Issues (48)

library/Trapdirector/Tables/HandlerTable.php (1 issue)

Severity
1
<?php
2
3
namespace Icinga\Module\Trapdirector\Tables;
4
5
use Icinga\Web\Url;
6
7
class HandlerTable extends TrapDirectorTable
8
{
9
10
    protected $status_display=array(
11
        -2	=>'ignore',
12
        -1 => '-',
13
        0	=> 'OK',
14
        1	=> 'warning',
15
        2	=> 'critical',
16
        3	=> 'unknown',);
17
    
18
    // translate
19
    protected $doTranslate=false;
20
    protected $MIB;
21
    
22
    // categories
23
    protected $categories = NULL;
24
    
25
    public function setCategoriesArray(array $categories)
26
    {
27
        $this->categories = $categories;
28
    }
29
    
30
    public function groupingPrintData( string $value)
31
    {
32
        if ($this->groupingColumn == 'rule_type')
33
        {
34
            if ($this->categories == NULL || (! isset($this->categories[$value])))
35
                return 'Unknown category ('.$value.')';
36
            return 'Category : '. $this->categories[$value];
37
        }
38
        $html = "$value";
39
        return $html;
40
    }
41
    
42
    public function setMibloader($mibloader)
43
    {
44
        $this->MIB=$mibloader;
45
        $this->doTranslate=true;
46
    }
47
48
    public function titleOrder($name)
49
    {
50
        switch ($name)
51
        {
52
            case 'host_name' : return $this->content[$name]; break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
53
            case 'source_ip' : return 'ip4'; break;
54
            default: return $this->content[$name];	
55
        }
56
    }
57
    
58
    public function getCurrentURL()
59
    {
60
        return Url::fromPath($this->urlPath . '/handler');
61
    }
62
    
63
    public function renderLine($row)
64
      {
65
          $html = '';
66
          $firstCol = true;
67
               
68
          $titleNames = array_keys($this->titles);
69
          foreach ($titleNames as $rowkey )
70
          {        
71
              // Check missing value
72
              if (property_exists($row, $rowkey))
73
              {
74
                  switch ($rowkey)
75
                  {
76
                      case 'action_match': // display text levels
77
                      case 'action_nomatch':
78
                          $val=$this->status_display[$row->$rowkey];
79
                          break;
80
                      case 'trap_oid': // try to traslate oids.
81
                          
82
                          if ($this->doTranslate === true)
83
                          {
84
                              $oidName = $this->MIB->translateOID($row->$rowkey);
85
                              if (isset($oidName['name']))
86
                              {
87
                                  $val=$oidName['name'];
88
                              }
89
                              else
90
                              {
91
                                  $val = $row->$rowkey;
92
                              }
93
                          }
94
                          else
95
                          {
96
                              $val = $row->$rowkey;
97
                          }
98
                          break;
99
                      case 'host_name': // switch to hostgroup if name is null
100
                          if ($row->$rowkey == null)
101
                          {
102
                              $val = $row->host_group_name;
103
                          }
104
                          else
105
                          {
106
                              $val = $row->$rowkey;
107
                          }
108
                          break;
109
                      default:
110
                          $val = $row->$rowkey;
111
                  }
112
                  if ($rowkey == 'trap_oid' && $this->doTranslate===true)
113
                  {
114
                      
115
                  }
116
              } else {
117
                  $val = '-';
118
              }
119
              if ($firstCol === true) { // Put link in first column for trap detail.
120
                  $html .= '<td class="traphover">'
121
                      . $this->view->qlink(
122
                          $this->view->escape($val),
123
                          Url::fromPath(
124
                              $this->urlPath . '/handler/add',
125
                              array('ruleid' => $row->id)
126
                              )
127
                          );
128
                  if ($row->comment != '')
129
                  {
130
                      $html.= '<span class="tohover">'. $row->comment .'</span></td>';
131
                  }
132
                  $html.= '</td>';
133
              } else {
134
                  $html .= '<td>' . $this->view->escape($val) . '</td>';
135
              }
136
              $firstCol=false;
137
              
138
          }
139
          return $html;
140
      }
141
142
}