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
|
|
|
public function setMibloader($mibloader) |
23
|
|
|
{ |
24
|
|
|
$this->MIB=$mibloader; |
25
|
|
|
$this->doTranslate=true; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function titleOrder($name) |
29
|
|
|
{ |
30
|
|
|
switch ($name) |
31
|
|
|
{ |
32
|
|
|
case 'host_name' : return $this->content[$name]; break; |
|
|
|
|
33
|
|
|
case 'source_ip' : return 'ip4'; break; |
34
|
|
|
default: return $this->content[$name]; |
35
|
|
|
} |
36
|
|
|
return NULL; |
|
|
|
|
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getCurrentURL() |
40
|
|
|
{ |
41
|
|
|
return Url::fromPath($this->urlPath . '/handler'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function renderLine($row) |
45
|
|
|
{ |
46
|
|
|
$html = ''; |
47
|
|
|
$firstCol = true; |
48
|
|
|
|
49
|
|
|
$titleNames = array_keys($this->titles); |
50
|
|
|
foreach ($titleNames as $rowkey ) |
51
|
|
|
{ |
52
|
|
|
// Check missing value |
53
|
|
|
if (property_exists($row, $rowkey)) |
54
|
|
|
{ |
55
|
|
|
switch ($rowkey) |
56
|
|
|
{ |
57
|
|
|
case 'action_match': // display text levels |
58
|
|
|
case 'action_nomatch': |
59
|
|
|
$val=$this->status_display[$row->$rowkey]; |
60
|
|
|
break; |
61
|
|
|
case 'trap_oid': // try to traslate oids. |
62
|
|
|
|
63
|
|
|
if ($this->doTranslate === true) |
64
|
|
|
{ |
65
|
|
|
$oidName = $this->MIB->translateOID($row->$rowkey); |
66
|
|
|
if (isset($oidName['name'])) |
67
|
|
|
{ |
68
|
|
|
$val=$oidName['name']; |
69
|
|
|
} |
70
|
|
|
else |
71
|
|
|
{ |
72
|
|
|
$val = $row->$rowkey; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
else |
76
|
|
|
{ |
77
|
|
|
$val = $row->$rowkey; |
78
|
|
|
} |
79
|
|
|
break; |
80
|
|
|
case 'host_name': // switch to hostgroup if name is null |
81
|
|
|
if ($row->$rowkey == null) |
82
|
|
|
{ |
83
|
|
|
$val = $row->host_group_name; |
84
|
|
|
} |
85
|
|
|
else |
86
|
|
|
{ |
87
|
|
|
$val = $row->$rowkey; |
88
|
|
|
} |
89
|
|
|
break; |
90
|
|
|
default: |
91
|
|
|
$val = $row->$rowkey; |
92
|
|
|
} |
93
|
|
|
if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
94
|
|
|
{ |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
} else { |
98
|
|
|
$val = '-'; |
99
|
|
|
} |
100
|
|
|
if ($firstCol === true) { // Put link in first column for trap detail. |
101
|
|
|
$html .= '<td>' |
102
|
|
|
. $this->view->qlink( |
103
|
|
|
$this->view->escape($val), |
104
|
|
|
Url::fromPath( |
105
|
|
|
$this->urlPath . '/handler/add', |
106
|
|
|
array('ruleid' => $row->id) |
107
|
|
|
) |
108
|
|
|
) |
109
|
|
|
. '</td>'; |
110
|
|
|
} else { |
111
|
|
|
$html .= '<td>' . $this->view->escape($val) . '</td>'; |
112
|
|
|
} |
113
|
|
|
$firstCol=false; |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
return $html; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
The
break
statement is not necessary if it is preceded for example by areturn
statement: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.