1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Icinga\Module\TrapDirector\Config; |
4
|
|
|
|
5
|
|
|
class TrapModuleConfig |
6
|
|
|
{ |
7
|
|
|
/********** Database configuration ***********************/ |
8
|
|
|
// Database prefix for tables |
9
|
|
|
protected $table_prefix; //< Database prefix for tables |
10
|
|
|
protected $DBConfigDefaults=array( |
11
|
|
|
'db_remove_days' => 60, // number of days before removing traps |
12
|
|
|
'log_destination' => 'syslog', // Log destination for trap handler |
13
|
|
|
'log_file' => '/tmp/trapdirector.log', // Log file |
14
|
|
|
'log_level' => 2, // log level |
15
|
|
|
'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default |
16
|
|
|
'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
17
|
|
|
); |
18
|
|
|
// get default values for dbconfig |
19
|
|
|
public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
20
|
|
|
/** Minimum DB version |
21
|
|
|
* @return number |
22
|
|
|
*/ |
23
|
|
|
static public function getDbMinVersion() { return 2;} |
24
|
|
|
/** Current DB version |
25
|
|
|
* @return number |
26
|
|
|
*/ |
27
|
|
|
static public function getDbCurVersion() { return 2;} |
28
|
|
|
|
29
|
|
|
/************ Module configuration **********************/ |
30
|
|
|
// Module base path |
31
|
|
|
static public function urlPath() { return 'trapdirector'; } |
32
|
|
|
static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/*********** Log configuration *************************/ |
36
|
|
|
protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL'); |
37
|
|
|
public function getlogLevels() { return $this->logLevels;} |
38
|
|
|
protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display'); |
39
|
|
|
public function getLogDestinations() { return $this->logDestinations;} |
40
|
|
|
|
41
|
|
|
function __construct($prefix) |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$this->table_prefix=$prefix; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/************ Database table names ********************/ |
47
|
|
|
// DB table name of trap received list : prefix 't' |
48
|
|
|
public function getTrapTableName() |
49
|
|
|
{ |
50
|
|
|
return array('t' => $this->table_prefix . 'received'); |
51
|
|
|
} |
52
|
|
|
// DB table name of trap data list : prefix 'd' |
53
|
|
|
public function getTrapDataTableName() |
54
|
|
|
{ |
55
|
|
|
return array('d' => $this->table_prefix . 'received_data'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// DB table name of rules : prefix 'r' |
59
|
|
|
public function getTrapRuleName() |
60
|
|
|
{ |
61
|
|
|
return array('r' => $this->table_prefix . 'rules'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// DB table name of db config : prefix 'c' |
65
|
|
|
public function getDbConfigTableName() |
66
|
|
|
{ |
67
|
|
|
return array('c' => $this->table_prefix . 'db_config'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// Mib cache tables |
71
|
|
|
public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; } |
72
|
|
|
public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; } |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
/****************** Database queries *******************/ |
76
|
|
|
// DB columns to display in view table (prefix is set for table in getTrapTableName) |
77
|
|
|
// Note : must have 'id' and 'timestamp' |
78
|
|
|
public function getTrapListDisplayColumns() |
79
|
|
|
{ |
80
|
|
|
return array( |
81
|
|
|
'timestamp' => 'UNIX_TIMESTAMP(t.date_received)', |
82
|
|
|
'source_ip' => 'CASE WHEN t.source_name IS NULL THEN t.source_ip ELSE t.source_name END as source_ip', |
83
|
|
|
'trap_oid' => "CASE WHEN t.trap_name IS NULL OR t.trap_name = '' THEN t.trap_oid ELSE t.trap_name END", |
84
|
|
|
'status' => 't.status', |
85
|
|
|
'status_detail' => 't.status_detail', |
86
|
|
|
'process_time' => 't.process_time', |
87
|
|
|
'id' => 't.id', |
88
|
|
|
//'destination_port' => 't.destination_port', |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
public function getTrapListSearchColumns() |
92
|
|
|
{ |
93
|
|
|
return array( |
94
|
|
|
't.date_received', |
95
|
|
|
't.source_ip', |
96
|
|
|
't.source_name', |
97
|
|
|
't.trap_name', |
98
|
|
|
't.trap_oid', |
99
|
|
|
't.status', |
100
|
|
|
't.id', |
101
|
|
|
//'destination_port' => 't.destination_port', |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
// Titles display in Trap List table |
105
|
|
|
public function getTrapListTitles() |
106
|
|
|
{ |
107
|
|
|
return array( |
108
|
|
|
'timestamp' => 'Time', |
109
|
|
|
'source_ip' => 'Source IP/name', |
110
|
|
|
'trap_oid' => 'Trap OID', |
111
|
|
|
'status' => 'Status', |
112
|
|
|
'status_detail' => 'Status detail', |
113
|
|
|
'process_time' => 'Processing time', |
114
|
|
|
//'destination_port' => 'Destination Port', |
115
|
|
|
//'id' => 'Id', |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
// DB columns to display in host view table (prefix is set for table in getTrapTableName) |
120
|
|
|
// Note : must have 'source_ip' and 'last_sent' |
121
|
|
|
public function getTrapHostListDisplayColumns() |
122
|
|
|
{ |
123
|
|
|
return array( |
124
|
|
|
'source_name' => 't.source_name', |
125
|
|
|
'source_ip' => 't.source_ip', |
126
|
|
|
'trap_oid' => 't.trap_oid', |
127
|
|
|
'count' => 'count(*)', |
128
|
|
|
'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getTrapHostListSearchColumns() |
133
|
|
|
{ |
134
|
|
|
return array(); // No search needed on this table |
135
|
|
|
} |
136
|
|
|
// Titles display in Trap List table |
137
|
|
|
public function getTrapHostListTitles() |
138
|
|
|
{ |
139
|
|
|
return array( |
140
|
|
|
'trap_oid' => 'Trap OID', |
141
|
|
|
'count' => 'Number of traps received', |
142
|
|
|
'last_sent' => 'Last trap received' |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
|
148
|
|
|
// DB columns to display in view table (prefix is set for table in getTrapTableName) |
149
|
|
|
// Note : must have 'id' and 'timestamp' |
150
|
|
|
public function getHandlerListDisplayColumns() |
151
|
|
|
{ |
152
|
|
|
return array( |
153
|
|
|
'host_name' => 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)', |
154
|
|
|
'host_group_name'=> 'r.host_group_name', |
155
|
|
|
'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
156
|
|
|
'trap_oid' => 'r.trap_oid', |
157
|
|
|
'rule' => 'r.rule', |
158
|
|
|
'action_match' => 'r.action_match', |
159
|
|
|
'action_nomatch'=> 'r.action_nomatch', |
160
|
|
|
'service_name' => 'r.service_name', |
161
|
|
|
'num_match' => 'r.num_match', |
162
|
|
|
'id' => 'r.id' |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
// Titles display in Trap List table |
166
|
|
|
public function getHandlerListTitles() |
167
|
|
|
{ |
168
|
|
|
return array( |
169
|
|
|
'host_name' => 'Host/Group Name', |
170
|
|
|
'source_ip' => 'Source IP', |
171
|
|
|
'trap_oid' => 'Trap OID', |
172
|
|
|
'rule' => 'Rule', |
173
|
|
|
'action_match' => 'On rule match', |
174
|
|
|
'action_nomatch'=> 'On rule dont match', |
175
|
|
|
'service_name' => 'Service Name', |
176
|
|
|
'num_match' => 'Has matched' |
177
|
|
|
//'id' => 'Id', |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
public function getHandlerColumns() |
181
|
|
|
{ |
182
|
|
|
return array( |
183
|
|
|
'r.host_name', 'r.host_group_name', |
184
|
|
|
'r.ip4', 'r.ip6', |
185
|
|
|
'r.trap_oid', |
186
|
|
|
'r.rule', |
187
|
|
|
'r.action_match', |
188
|
|
|
'r.action_nomatch', |
189
|
|
|
'r.service_name', |
190
|
|
|
'r.num_match', |
191
|
|
|
'r.id' |
192
|
|
|
); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// handler update (<key> => <sql select>) |
196
|
|
|
public function ruleDetailQuery() |
197
|
|
|
{ |
198
|
|
|
return array( |
199
|
|
|
'id' => 'r.id', |
200
|
|
|
'ip4' => "r.ip4", |
201
|
|
|
'ip6' => "r.ip6", |
202
|
|
|
'trap_oid' => 'r.trap_oid', |
203
|
|
|
'host_name' => 'r.host_name', |
204
|
|
|
'host_group_name' => 'r.host_group_name', |
205
|
|
|
'rule' => 'r.rule', |
206
|
|
|
'action_match' => 'r.action_match', |
207
|
|
|
'action_nomatch'=> 'r.action_nomatch', |
208
|
|
|
'service_name' => 'r.service_name', |
209
|
|
|
'revert_ok' => 'r.revert_ok', |
210
|
|
|
'display' => 'r.display', |
211
|
|
|
'modified' => 'UNIX_TIMESTAMP(r.modified)', |
212
|
|
|
'modifier' => 'r.modifier' |
213
|
|
|
); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
// Trap detail (<key> => <title> <sql select>) |
217
|
|
|
public function trapDetailQuery() |
218
|
|
|
{ |
219
|
|
|
return array( |
220
|
|
|
'timestamp' => array('Date','UNIX_TIMESTAMP(t.date_received)'), |
221
|
|
|
'source_ip' => array('Source IP','t.source_ip'), |
222
|
|
|
'source_name' => array('Source name','t.source_name'), |
223
|
|
|
'source_port' => array('Source port','t.source_port'), |
224
|
|
|
'destination_ip' => array('Destination IP','t.destination_ip'), |
225
|
|
|
'destination_port' => array('Destination port','t.destination_port'), |
226
|
|
|
'trap_oid' => array('Numeric OID','t.trap_oid'), |
227
|
|
|
'trap_name' => array('Trap name','t.trap_name'), |
228
|
|
|
'trap_name_mib' => array('Trap MIB','t.trap_name_mib'), |
229
|
|
|
'status' => array('Processing status','t.status'), |
230
|
|
|
'status_detail' => array('Status details','t.status_detail'), |
231
|
|
|
'process_time' => array('Trap processing time','t.process_time'), |
232
|
|
|
); |
233
|
|
|
} |
234
|
|
|
// Trap detail : additional data (<key> => <title> <sql select>) |
235
|
|
|
public function trapDataDetailQuery() |
236
|
|
|
{ |
237
|
|
|
return array( |
238
|
|
|
'oid' => array('Numeric OID','d.oid'), |
239
|
|
|
'oid_name' => array('Text OID','d.oid_name'), |
240
|
|
|
'oid_name_mib' => array('MIB','d.oid_name_mib'), |
241
|
|
|
'value' => array('Value','d.value'), |
242
|
|
|
); |
243
|
|
|
} |
244
|
|
|
// foreign key of trap data table |
245
|
|
|
public function trapDataFK() { return 'trap_id';} |
246
|
|
|
|
247
|
|
|
// Max items in a list |
248
|
|
|
public function itemListDisplay() { return 25; } |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.