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