@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param Logging $logClass : where to log |
32 | 32 | * @param Database $dbClass : Database |
33 | 33 | */ |
34 | - function __construct($logClass,$dbClass,$snmptrans,$snmptransdir) |
|
34 | + function __construct($logClass, $dbClass, $snmptrans, $snmptransdir) |
|
35 | 35 | { |
36 | 36 | $this->logging=$logClass; |
37 | 37 | $this->trapsDB=$dbClass; |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | } |
59 | 59 | $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
60 | 60 | $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
61 | - if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
61 | + if ($this->oidDesc['name'] != $dbOid['name'] || |
|
62 | 62 | $this->oidDesc['mib'] != $dbOid['mib'] || |
63 | - $this->oidDesc['type'] !=$dbOid['type'] |
|
63 | + $this->oidDesc['type'] != $dbOid['type'] |
|
64 | 64 | ) |
65 | 65 | { // Do update |
66 | 66 | $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '. |
@@ -74,22 +74,22 @@ discard block |
||
74 | 74 | ':type' => $this->oidDesc['type'], |
75 | 75 | ':mib' => $this->oidDesc['mib'], |
76 | 76 | ':tc' => $this->oidDesc['textconv']??'null', |
77 | - ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
78 | - ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
77 | + ':display_hint' => $this->oidDesc['dispHint']??'null', |
|
78 | + ':syntax' => $this->oidDesc['syntax'] == null??'null', |
|
79 | 79 | ':type_enum' => $this->oidDesc['type_enum']??'null', |
80 | 80 | ':description' => $this->oidDesc['description']??'null', |
81 | 81 | ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
82 | 82 | ); |
83 | 83 | |
84 | 84 | if ($sqlQuery->execute($sqlParam) === false) { |
85 | - $this->logging->log('Error in query : ' . $sql,ERROR,''); |
|
85 | + $this->logging->log('Error in query : '.$sql, ERROR, ''); |
|
86 | 86 | } |
87 | - $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
87 | + $this->logging->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG); |
|
88 | 88 | return 1; |
89 | 89 | } |
90 | 90 | else |
91 | 91 | { |
92 | - $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
92 | + $this->logging->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG); |
|
93 | 93 | return 0; |
94 | 94 | } |
95 | 95 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | |
100 | 100 | $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '. |
101 | 101 | '(oid, name, type , mib, textual_convention, display_hint '. |
102 | - ', syntax, type_enum , description ) ' . |
|
102 | + ', syntax, type_enum , description ) '. |
|
103 | 103 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
104 | 104 | ', :syntax, :type_enum, :description )'; |
105 | 105 | |
106 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
106 | + if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id'; |
|
107 | 107 | |
108 | 108 | $sqlQuery=$db_conn->prepare($sql); |
109 | 109 | |
@@ -112,15 +112,15 @@ discard block |
||
112 | 112 | ':name' => $this->oidDesc['name'], |
113 | 113 | ':type' => $this->oidDesc['type'], |
114 | 114 | ':mib' => $this->oidDesc['mib'], |
115 | - ':tc' => ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] , |
|
116 | - ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] , |
|
117 | - ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'], |
|
118 | - ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'], |
|
119 | - ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description'] |
|
115 | + ':tc' => ($this->oidDesc['textconv'] == null) ? 'null' : $this->oidDesc['textconv'], |
|
116 | + ':display_hint' => ($this->oidDesc['dispHint'] == null) ? 'null' : $this->oidDesc['dispHint'], |
|
117 | + ':syntax' => ($this->oidDesc['syntax'] == null) ? 'null' : $this->oidDesc['syntax'], |
|
118 | + ':type_enum' => ($this->oidDesc['type_enum'] == null) ? 'null' : $this->oidDesc['type_enum'], |
|
119 | + ':description' => ($this->oidDesc['description'] == null) ? 'null' : $this->oidDesc['description'] |
|
120 | 120 | ); |
121 | 121 | |
122 | 122 | if ($sqlQuery->execute($sqlParam) === false) { |
123 | - $this->logging->log('Error in query : ' . $sql,1,''); |
|
123 | + $this->logging->log('Error in query : '.$sql, 1, ''); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | switch ($this->trapsDB->trapDBType) |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | case 'pgsql': |
129 | 129 | // Get last id to insert oid/values in secondary table |
130 | 130 | if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
131 | - $this->logging->log('Error getting id - pgsql - ',1,''); |
|
131 | + $this->logging->log('Error getting id - pgsql - ', 1, ''); |
|
132 | 132 | } |
133 | - if (! isset($inserted_id_ret['id'])) { |
|
134 | - $this->logging->log('Error getting id - pgsql - empty.',1,''); |
|
133 | + if (!isset($inserted_id_ret['id'])) { |
|
134 | + $this->logging->log('Error getting id - pgsql - empty.', 1, ''); |
|
135 | 135 | } |
136 | 136 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
137 | 137 | break; |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | // Get last id to insert oid/values in secondary table |
140 | 140 | $sql='SELECT LAST_INSERT_ID();'; |
141 | 141 | if (($ret_code=$db_conn->query($sql)) === false) { |
142 | - $this->logging->log('Erreur getting id - mysql - ',1,''); |
|
142 | + $this->logging->log('Erreur getting id - mysql - ', 1, ''); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
146 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
146 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
147 | 147 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
148 | 148 | break; |
149 | 149 | default: |
150 | - $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,''); |
|
150 | + $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, ''); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Set as newly created. |
@@ -162,21 +162,21 @@ discard block |
||
162 | 162 | * @param array $objects : array of objects name (without MIB) |
163 | 163 | * @param bool $check_existing : check instead of create |
164 | 164 | */ |
165 | - public function trap_objects($trapOID,$trapmib,$objects,$check_existing) |
|
165 | + public function trap_objects($trapOID, $trapmib, $objects, $check_existing) |
|
166 | 166 | { |
167 | 167 | $dbObjects=null; // cache of objects for trap in db |
168 | 168 | $db_conn=$this->trapsDB->db_connect_trap(); |
169 | 169 | |
170 | 170 | // Get id of trapmib. |
171 | 171 | |
172 | - $trapId = $this->dbOidIndex[$trapOID]['id']; |
|
172 | + $trapId=$this->dbOidIndex[$trapOID]['id']; |
|
173 | 173 | if ($check_existing === true) |
174 | 174 | { |
175 | 175 | // Get all objects |
176 | 176 | $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
177 | - $this->logging->log('SQL query get all traps: '.$sql,DEBUG ); |
|
177 | + $this->logging->log('SQL query get all traps: '.$sql, DEBUG); |
|
178 | 178 | if (($ret_code=$db_conn->query($sql)) === false) { |
179 | - $this->logging->log('No result in query : ' . $sql,1,''); |
|
179 | + $this->logging->log('No result in query : '.$sql, 1, ''); |
|
180 | 180 | } |
181 | 181 | $dbObjectsRaw=$ret_code->fetchAll(); |
182 | 182 | |
@@ -197,36 +197,36 @@ discard block |
||
197 | 197 | $indesc=false; // true if currently inside multiline description |
198 | 198 | |
199 | 199 | $this->oidDesc['mib']=$trapmib; |
200 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
201 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
202 | - if ($retVal!=0) |
|
200 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
201 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
202 | + if ($retVal != 0) |
|
203 | 203 | { |
204 | 204 | // Maybe not trap mib, search with IR |
205 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
206 | - ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
207 | - if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match)) |
|
205 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
206 | + ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
207 | + if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match)) |
|
208 | 208 | { // Not found -> continue with warning |
209 | - $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,''); |
|
209 | + $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, ''); |
|
210 | 210 | continue; |
211 | 211 | } |
212 | 212 | $this->oidDesc['mib']=$match[1]; |
213 | 213 | |
214 | 214 | // Do the snmptranslate again. |
215 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
216 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal); |
|
217 | - if ($retVal!=0) { |
|
218 | - $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,''); |
|
215 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
216 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal); |
|
217 | + if ($retVal != 0) { |
|
218 | + $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, ''); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | } |
222 | 222 | foreach ($snmptrans as $line) |
223 | 223 | { |
224 | - if ($indesc===true) |
|
224 | + if ($indesc === true) |
|
225 | 225 | { |
226 | - $line=preg_replace('/[\t ]+/',' ',$line); |
|
227 | - if (preg_match('/(.*)"$/', $line,$match)) |
|
226 | + $line=preg_replace('/[\t ]+/', ' ', $line); |
|
227 | + if (preg_match('/(.*)"$/', $line, $match)) |
|
228 | 228 | { |
229 | - $this->oidDesc['description'] = $tmpdesc . $match[1]; |
|
229 | + $this->oidDesc['description']=$tmpdesc.$match[1]; |
|
230 | 230 | $indesc=false; |
231 | 231 | } |
232 | 232 | $tmpdesc.=$line; |
@@ -237,41 +237,41 @@ discard block |
||
237 | 237 | $this->oidDesc['oid']=$line; |
238 | 238 | continue; |
239 | 239 | } |
240 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match)) |
|
240 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match)) |
|
241 | 241 | { |
242 | 242 | $this->oidDesc['syntax']=$match[1]; |
243 | 243 | $this->oidDesc['type_enum']=$match[2]; |
244 | 244 | continue; |
245 | 245 | } |
246 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match)) |
|
246 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match)) |
|
247 | 247 | { |
248 | 248 | $this->oidDesc['syntax']=$match[1]; |
249 | 249 | continue; |
250 | 250 | } |
251 | - if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match)) |
|
251 | + if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match)) |
|
252 | 252 | { |
253 | 253 | $this->oidDesc['dispHint']=$match[1]; |
254 | 254 | continue; |
255 | 255 | } |
256 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match)) |
|
256 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match)) |
|
257 | 257 | { |
258 | 258 | $this->oidDesc['description']=$match[1]; |
259 | 259 | continue; |
260 | 260 | } |
261 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match)) |
|
261 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match)) |
|
262 | 262 | { |
263 | 263 | $tmpdesc=$match[1]; |
264 | 264 | $indesc=true; |
265 | 265 | continue; |
266 | 266 | } |
267 | - if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match)) |
|
267 | + if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match)) |
|
268 | 268 | { |
269 | 269 | $this->oidDesc['textconv']=$match[1]; |
270 | 270 | continue; |
271 | 271 | } |
272 | 272 | } |
273 | - $this->oidDesc['name'] = $object; |
|
274 | - $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG ); |
|
273 | + $this->oidDesc['name']=$object; |
|
274 | + $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'], DEBUG); |
|
275 | 275 | //echo "$this->oidDesc['name'] : $this->oidDesc['oid'] / $this->oidDesc['syntax'] / $this->oidDesc['type_enum'] / $this->oidDesc['dispHint'] / $this->oidDesc['textconv'] / $this->oidDesc['description']\n"; |
276 | 276 | // Update |
277 | 277 | $this->update_oid(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ); |
296 | 296 | |
297 | 297 | if ($sqlQuery->execute($sqlParam) === false) { |
298 | - $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,''); |
|
298 | + $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, ''); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | if ($check_existing === true) |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $this->oidDesc['type']=null; |
313 | 313 | $this->oidDesc['mib']=null; |
314 | 314 | $this->oidDesc['textconv']=null; |
315 | - $this->oidDesc['dispHint'] =null; |
|
315 | + $this->oidDesc['dispHint']=null; |
|
316 | 316 | $this->oidDesc['syntax']=null; |
317 | 317 | $this->oidDesc['type_enum']=null; |
318 | 318 | $this->oidDesc['description']=null; |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | { |
327 | 327 | $retVal=0; |
328 | 328 | // Get all mib objects from all mibs |
329 | - $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null'; |
|
330 | - $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG ); |
|
329 | + $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null'; |
|
330 | + $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG); |
|
331 | 331 | unset($this->objectsAll); |
332 | - exec($snmpCommand,$this->objectsAll,$retVal); |
|
333 | - if ($retVal!=0) |
|
332 | + exec($snmpCommand, $this->objectsAll, $retVal); |
|
333 | + if ($retVal != 0) |
|
334 | 334 | { |
335 | - $this->logging->log('error executing snmptranslate',ERROR,''); |
|
335 | + $this->logging->log('error executing snmptranslate', ERROR, ''); |
|
336 | 336 | } |
337 | 337 | // Count elements to show progress |
338 | 338 | $numElements=count($this->objectsAll); |
339 | - $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO ); |
|
339 | + $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO); |
|
340 | 340 | return $numElements; |
341 | 341 | } |
342 | 342 | |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | $db_conn=$this->trapsDB->db_connect_trap(); |
351 | 351 | |
352 | 352 | $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;'; |
353 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
353 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
354 | 354 | if (($ret_code=$db_conn->query($sql)) === false) { |
355 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
355 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
356 | 356 | } |
357 | 357 | $this->dbOidAll=$ret_code->fetchAll(); |
358 | 358 | $this->dbOidIndex=array(); |
359 | 359 | // Create the index for db; |
360 | - foreach($this->dbOidAll as $key=>$val) |
|
360 | + foreach ($this->dbOidAll as $key=>$val) |
|
361 | 361 | { |
362 | 362 | $this->dbOidIndex[$val['oid']]['key']=$key; |
363 | 363 | $this->dbOidIndex[$val['oid']]['id']=$val['id']; |
@@ -384,13 +384,13 @@ discard block |
||
384 | 384 | $this->timing['num_traps']=0; |
385 | 385 | } |
386 | 386 | |
387 | - private function detect_trap($curElement,$onlyTraps) |
|
387 | + private function detect_trap($curElement, $onlyTraps) |
|
388 | 388 | { |
389 | 389 | // Get oid or pass if not found |
390 | - if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement])) |
|
390 | + if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement])) |
|
391 | 391 | { |
392 | - $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time']; |
|
393 | - $this->timing['base_parse_num'] ++; |
|
392 | + $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time']; |
|
393 | + $this->timing['base_parse_num']++; |
|
394 | 394 | return true; |
395 | 395 | } |
396 | 396 | $this->oidDesc['oid']=$this->objectsAll[$curElement]; |
@@ -399,9 +399,9 @@ discard block |
||
399 | 399 | $curElement++; |
400 | 400 | $match=$snmptrans=array(); |
401 | 401 | if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/', |
402 | - $this->objectsAll[$curElement],$match)) |
|
402 | + $this->objectsAll[$curElement], $match)) |
|
403 | 403 | { |
404 | - $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time']; |
|
404 | + $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time']; |
|
405 | 405 | $this->timing['base_check_num']++; |
406 | 406 | return true; |
407 | 407 | } |
@@ -409,22 +409,22 @@ discard block |
||
409 | 409 | $this->oidDesc['name']=$match[1]; // Name |
410 | 410 | $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
411 | 411 | |
412 | - if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
412 | + if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap |
|
413 | 413 | { |
414 | 414 | // Check if next is suboid -> in that case is cannot be a trap |
415 | - if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
|
415 | + if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1])) |
|
416 | 416 | { |
417 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
417 | + $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time']; |
|
418 | 418 | $this->timing['type0_check_num']++; |
419 | 419 | return true; |
420 | 420 | } |
421 | 421 | unset($snmptrans); |
422 | 422 | $retVal=0; |
423 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
424 | - ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal); |
|
425 | - if ($retVal!=0) |
|
423 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
424 | + ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal); |
|
425 | + if ($retVal != 0) |
|
426 | 426 | { |
427 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
427 | + $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time']; |
|
428 | 428 | $this->timing['type0_check_num']++; |
429 | 429 | return true; |
430 | 430 | } |
@@ -432,9 +432,9 @@ discard block |
||
432 | 432 | // Force as trap. |
433 | 433 | $this->oidDesc['type']=21; |
434 | 434 | } |
435 | - if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
435 | + if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue |
|
436 | 436 | { |
437 | - $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
|
437 | + $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time']; |
|
438 | 438 | $this->timing['nottrap_num']++; |
439 | 439 | return true; |
440 | 440 | } |
@@ -448,18 +448,18 @@ discard block |
||
448 | 448 | * @param boolean $onlyTraps : only cache traps and objects (true) or all (false) |
449 | 449 | * @param string $startOID : only cache under startOID (NOT IMPLEMENTED) |
450 | 450 | */ |
451 | - public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1') |
|
451 | + public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1') |
|
452 | 452 | { |
453 | 453 | // Global Timing |
454 | - $timeTaken = microtime(true); |
|
454 | + $timeTaken=microtime(true); |
|
455 | 455 | |
456 | 456 | $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll |
457 | 457 | |
458 | 458 | $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex |
459 | 459 | |
460 | - $step=$basestep=$numElements/10; // output display of % done |
|
460 | + $step=$basestep=$numElements / 10; // output display of % done |
|
461 | 461 | $num_step=0; |
462 | - $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds |
|
462 | + $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds |
|
463 | 463 | |
464 | 464 | // Create index for trap objects |
465 | 465 | $this->trapObjectsIndex=array(); |
@@ -467,80 +467,80 @@ discard block |
||
467 | 467 | // detailed timing (time_* vars) |
468 | 468 | $this->reset_update_timers(); |
469 | 469 | |
470 | - for ($curElement=0;$curElement < $numElements;$curElement++) |
|
470 | + for ($curElement=0; $curElement < $numElements; $curElement++) |
|
471 | 471 | { |
472 | - $this->timing['base_time']= microtime(true); |
|
472 | + $this->timing['base_time']=microtime(true); |
|
473 | 473 | if ($display_progress) |
474 | 474 | { |
475 | - if ((microtime(true)-$timeFiveSec) > 2) |
|
475 | + if ((microtime(true) - $timeFiveSec) > 2) |
|
476 | 476 | { // echo a . every 2 sec |
477 | 477 | echo '.'; |
478 | - $timeFiveSec = microtime(true); |
|
478 | + $timeFiveSec=microtime(true); |
|
479 | 479 | } |
480 | - if ($curElement>$step) |
|
480 | + if ($curElement > $step) |
|
481 | 481 | { // display progress |
482 | 482 | $num_step++; |
483 | 483 | $step+=$basestep; |
484 | - echo "\n" . ($num_step*10). '% : '; |
|
484 | + echo "\n".($num_step * 10).'% : '; |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
488 | 488 | $this->reset_oidDesc(); |
489 | - if ($this->detect_trap($curElement,$onlyTraps)===true) |
|
489 | + if ($this->detect_trap($curElement, $onlyTraps) === true) |
|
490 | 490 | { |
491 | 491 | continue; |
492 | 492 | } |
493 | 493 | |
494 | 494 | $this->timing['num_traps']++; |
495 | 495 | |
496 | - $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
|
496 | + $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO); |
|
497 | 497 | if ($display_progress) echo '#'; // echo a # when trap found |
498 | 498 | |
499 | 499 | //################################ |
500 | 500 | // get trap objects & source MIB |
501 | 501 | $retVal=0; |
502 | 502 | $match=$snmptrans=array(); |
503 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
504 | - ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal); |
|
505 | - if ($retVal!=0) |
|
503 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
504 | + ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal); |
|
505 | + if ($retVal != 0) |
|
506 | 506 | { |
507 | - $this->logging->log('error executing snmptranslate',ERROR); |
|
507 | + $this->logging->log('error executing snmptranslate', ERROR); |
|
508 | 508 | } |
509 | 509 | |
510 | - if (!preg_match('/^(.*)::/',$snmptrans[0],$match)) |
|
510 | + if (!preg_match('/^(.*)::/', $snmptrans[0], $match)) |
|
511 | 511 | { |
512 | - $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR); |
|
512 | + $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR); |
|
513 | 513 | } |
514 | 514 | $this->oidDesc['mib']=$match[1]; |
515 | 515 | |
516 | 516 | $numLine=1; |
517 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
517 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++; |
|
518 | 518 | if (isset($snmptrans[$numLine])) |
519 | 519 | { |
520 | - $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
|
520 | + $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]); |
|
521 | 521 | |
522 | - while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine])) |
|
522 | + while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine])) |
|
523 | 523 | { |
524 | - $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]); |
|
524 | + $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]); |
|
525 | 525 | $numLine++; |
526 | 526 | } |
527 | 527 | if (isset($snmptrans[$numLine])) { |
528 | - $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]); |
|
529 | - $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']); |
|
528 | + $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]); |
|
529 | + $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | } |
533 | 533 | |
534 | 534 | $update=$this->update_oid(); // Do update of trap. |
535 | 535 | |
536 | - $this->timing['update_time'] += microtime(true) - $this->timing['base_time']; |
|
536 | + $this->timing['update_time']+=microtime(true) - $this->timing['base_time']; |
|
537 | 537 | $this->timing['update_num']++; |
538 | 538 | |
539 | - $this->timing['base_time']= microtime(true); // Reset to check object time |
|
539 | + $this->timing['base_time']=microtime(true); // Reset to check object time |
|
540 | 540 | |
541 | - if (($update==0) && ($check_change===false)) |
|
541 | + if (($update == 0) && ($check_change === false)) |
|
542 | 542 | { // Trapd didn't change & force check disabled |
543 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
543 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
544 | 544 | if ($display_progress) echo "C"; |
545 | 545 | continue; |
546 | 546 | } |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $synt=null; |
549 | 549 | foreach ($snmptrans as $line) |
550 | 550 | { |
551 | - if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match)) |
|
551 | + if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match)) |
|
552 | 552 | { |
553 | 553 | $synt=$match[1]; |
554 | 554 | } |
@@ -556,30 +556,30 @@ discard block |
||
556 | 556 | if ($synt == null) |
557 | 557 | { |
558 | 558 | //echo "No objects for $trapOID\n"; |
559 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
559 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
560 | 560 | continue; |
561 | 561 | } |
562 | 562 | //echo "$synt \n"; |
563 | 563 | $trapObjects=array(); |
564 | - while (preg_match('/ *([^ ,]+) *,* */',$synt,$match)) |
|
564 | + while (preg_match('/ *([^ ,]+) *,* */', $synt, $match)) |
|
565 | 565 | { |
566 | - array_push($trapObjects,$match[1]); |
|
567 | - $synt=preg_replace('/'.$match[0].'/','',$synt); |
|
566 | + array_push($trapObjects, $match[1]); |
|
567 | + $synt=preg_replace('/'.$match[0].'/', '', $synt); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false); |
571 | 571 | |
572 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
572 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
573 | 573 | $this->timing['objects_num']++; |
574 | 574 | } |
575 | 575 | |
576 | 576 | if ($display_progress) |
577 | 577 | { |
578 | - echo "\nNumber of processed traps : ". $this->timing['num_traps'] ."\n"; |
|
579 | - echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num']) . " occurences\n"; |
|
580 | - echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n"; |
|
581 | - echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , "; |
|
582 | - echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n"; |
|
578 | + echo "\nNumber of processed traps : ".$this->timing['num_traps']."\n"; |
|
579 | + echo "\nParsing : ".number_format($this->timing['base_parse_time'] + $this->timing['base_check_time'], 1)." sec / ".($this->timing['base_parse_num'] + $this->timing['base_check_num'])." occurences\n"; |
|
580 | + echo "Detecting traps : ".number_format($this->timing['type0_check_time'] + $this->timing['nottrap_time'], 1)." sec / ".($this->timing['type0_check_num'] + $this->timing['nottrap_num'])." occurences\n"; |
|
581 | + echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , "; |
|
582 | + echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n"; |
|
583 | 583 | |
584 | 584 | $timeTaken=microtime(true) - $timeTaken; |
585 | 585 | echo "Global time : ".round($timeTaken)." seconds\n"; |