@@ -11,174 +11,174 @@ discard block |
||
11 | 11 | class Mib |
12 | 12 | { |
13 | 13 | |
14 | - protected $logging; //< logging class |
|
15 | - protected $trapsDB; //< Database class |
|
14 | + protected $logging; //< logging class |
|
15 | + protected $trapsDB; //< Database class |
|
16 | 16 | |
17 | - public $snmptranslate; |
|
18 | - public $snmptranslateDirs; |
|
17 | + public $snmptranslate; |
|
18 | + public $snmptranslateDirs; |
|
19 | 19 | |
20 | - private $dbOidAll; //< All oid in database; |
|
21 | - private $dbOidIndex; //< Index of oid in dbOidAll |
|
22 | - private $objectsAll; //< output lines of snmptranslate list |
|
23 | - private $trapObjectsIndex; //< array of traps objects (as OID) |
|
20 | + private $dbOidAll; //< All oid in database; |
|
21 | + private $dbOidIndex; //< Index of oid in dbOidAll |
|
22 | + private $objectsAll; //< output lines of snmptranslate list |
|
23 | + private $trapObjectsIndex; //< array of traps objects (as OID) |
|
24 | 24 | |
25 | - private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL |
|
25 | + private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL |
|
26 | 26 | |
27 | - // Timing vars for update |
|
28 | - private $timing=array(); |
|
27 | + // Timing vars for update |
|
28 | + private $timing=array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * Setup Mib Class |
|
32 | - * @param Logging $logClass : where to log |
|
33 | - * @param Database $dbClass : Database |
|
34 | - */ |
|
35 | - function __construct($logClass,$dbClass,$snmptrans,$snmptransdir) |
|
36 | - { |
|
37 | - $this->logging=$logClass; |
|
38 | - $this->trapsDB=$dbClass; |
|
39 | - $this->snmptranslate=$snmptrans; |
|
40 | - $this->snmptranslateDirs=$snmptransdir; |
|
30 | + /** |
|
31 | + * Setup Mib Class |
|
32 | + * @param Logging $logClass : where to log |
|
33 | + * @param Database $dbClass : Database |
|
34 | + */ |
|
35 | + function __construct($logClass,$dbClass,$snmptrans,$snmptransdir) |
|
36 | + { |
|
37 | + $this->logging=$logClass; |
|
38 | + $this->trapsDB=$dbClass; |
|
39 | + $this->snmptranslate=$snmptrans; |
|
40 | + $this->snmptranslateDirs=$snmptransdir; |
|
41 | 41 | |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Update or add an OID to database uses $this->dbOidIndex for mem cache |
|
47 | - * and $this->oidDesc doe data |
|
48 | - * @return number : 0=unchanged, 1 = changed, 2=created |
|
49 | - */ |
|
50 | - public function update_oid() |
|
51 | - { |
|
52 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
53 | - $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']); |
|
54 | - if (isset($this->dbOidIndex[$this->oidDesc['oid']])) |
|
55 | - { |
|
56 | - if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1) |
|
57 | - { // newly created. |
|
58 | - return 0; |
|
59 | - } |
|
60 | - $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
|
61 | - $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
|
62 | - if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
63 | - $this->oidDesc['mib'] != $dbOid['mib'] || |
|
64 | - $this->oidDesc['type'] !=$dbOid['type'] |
|
65 | - ) |
|
66 | - { // Do update |
|
67 | - $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '. |
|
68 | - 'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. |
|
69 | - ', syntax = :syntax, type_enum = :type_enum, description = :description '. |
|
70 | - ' WHERE id= :id'; |
|
71 | - $sqlQuery=$db_conn->prepare($sql); |
|
45 | + /** |
|
46 | + * Update or add an OID to database uses $this->dbOidIndex for mem cache |
|
47 | + * and $this->oidDesc doe data |
|
48 | + * @return number : 0=unchanged, 1 = changed, 2=created |
|
49 | + */ |
|
50 | + public function update_oid() |
|
51 | + { |
|
52 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
53 | + $this->oidDesc['description']=$db_conn->quote($this->oidDesc['description']); |
|
54 | + if (isset($this->dbOidIndex[$this->oidDesc['oid']])) |
|
55 | + { |
|
56 | + if ($this->dbOidIndex[$this->oidDesc['oid']]['key'] == -1) |
|
57 | + { // newly created. |
|
58 | + return 0; |
|
59 | + } |
|
60 | + $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
|
61 | + $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
|
62 | + if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
63 | + $this->oidDesc['mib'] != $dbOid['mib'] || |
|
64 | + $this->oidDesc['type'] !=$dbOid['type'] |
|
65 | + ) |
|
66 | + { // Do update |
|
67 | + $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '. |
|
68 | + 'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'. |
|
69 | + ', syntax = :syntax, type_enum = :type_enum, description = :description '. |
|
70 | + ' WHERE id= :id'; |
|
71 | + $sqlQuery=$db_conn->prepare($sql); |
|
72 | 72 | |
73 | - $sqlParam=array( |
|
74 | - ':name' => $this->oidDesc['name'], |
|
75 | - ':type' => $this->oidDesc['type'], |
|
76 | - ':mib' => $this->oidDesc['mib'], |
|
77 | - ':tc' => $this->oidDesc['textconv']??'null', |
|
78 | - ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
79 | - ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
80 | - ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
81 | - ':description' => $this->oidDesc['description']??'null', |
|
82 | - ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
|
83 | - ); |
|
73 | + $sqlParam=array( |
|
74 | + ':name' => $this->oidDesc['name'], |
|
75 | + ':type' => $this->oidDesc['type'], |
|
76 | + ':mib' => $this->oidDesc['mib'], |
|
77 | + ':tc' => $this->oidDesc['textconv']??'null', |
|
78 | + ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
79 | + ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
80 | + ':type_enum' => $this->oidDesc['type_enum']??'null', |
|
81 | + ':description' => $this->oidDesc['description']??'null', |
|
82 | + ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
|
83 | + ); |
|
84 | 84 | |
85 | - if ($sqlQuery->execute($sqlParam) === false) { |
|
86 | - $this->logging->log('Error in query : ' . $sql,ERROR,''); |
|
87 | - } |
|
88 | - $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
89 | - return 1; |
|
90 | - } |
|
91 | - else |
|
92 | - { |
|
93 | - $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
94 | - return 0; |
|
95 | - } |
|
96 | - } |
|
97 | - // create new OID. |
|
85 | + if ($sqlQuery->execute($sqlParam) === false) { |
|
86 | + $this->logging->log('Error in query : ' . $sql,ERROR,''); |
|
87 | + } |
|
88 | + $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
89 | + return 1; |
|
90 | + } |
|
91 | + else |
|
92 | + { |
|
93 | + $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
94 | + return 0; |
|
95 | + } |
|
96 | + } |
|
97 | + // create new OID. |
|
98 | 98 | |
99 | - // Insert data |
|
99 | + // Insert data |
|
100 | 100 | |
101 | - $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '. |
|
102 | - '(oid, name, type , mib, textual_convention, display_hint '. |
|
103 | - ', syntax, type_enum , description ) ' . |
|
104 | - 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
|
105 | - ', :syntax, :type_enum, :description )'; |
|
101 | + $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '. |
|
102 | + '(oid, name, type , mib, textual_convention, display_hint '. |
|
103 | + ', syntax, type_enum , description ) ' . |
|
104 | + 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
|
105 | + ', :syntax, :type_enum, :description )'; |
|
106 | 106 | |
107 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
107 | + if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
108 | 108 | |
109 | - $sqlQuery=$db_conn->prepare($sql); |
|
109 | + $sqlQuery=$db_conn->prepare($sql); |
|
110 | 110 | |
111 | - $sqlParam=array( |
|
112 | - ':oid' => $this->oidDesc['oid'], |
|
113 | - ':name' => $this->oidDesc['name'], |
|
114 | - ':type' => $this->oidDesc['type'], |
|
115 | - ':mib' => $this->oidDesc['mib'], |
|
116 | - ':tc' => ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] , |
|
117 | - ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] , |
|
118 | - ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'], |
|
119 | - ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'], |
|
120 | - ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description'] |
|
121 | - ); |
|
111 | + $sqlParam=array( |
|
112 | + ':oid' => $this->oidDesc['oid'], |
|
113 | + ':name' => $this->oidDesc['name'], |
|
114 | + ':type' => $this->oidDesc['type'], |
|
115 | + ':mib' => $this->oidDesc['mib'], |
|
116 | + ':tc' => ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] , |
|
117 | + ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] , |
|
118 | + ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'], |
|
119 | + ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'], |
|
120 | + ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description'] |
|
121 | + ); |
|
122 | 122 | |
123 | - if ($sqlQuery->execute($sqlParam) === false) { |
|
124 | - $this->logging->log('Error in query : ' . $sql,1,''); |
|
125 | - } |
|
123 | + if ($sqlQuery->execute($sqlParam) === false) { |
|
124 | + $this->logging->log('Error in query : ' . $sql,1,''); |
|
125 | + } |
|
126 | 126 | |
127 | - switch ($this->trapsDB->trapDBType) |
|
128 | - { |
|
129 | - case 'pgsql': |
|
130 | - // Get last id to insert oid/values in secondary table |
|
131 | - if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
|
132 | - $this->logging->log('Error getting id - pgsql - ',1,''); |
|
133 | - } |
|
134 | - if (! isset($inserted_id_ret['id'])) { |
|
135 | - $this->logging->log('Error getting id - pgsql - empty.',1,''); |
|
136 | - } |
|
137 | - $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
|
138 | - break; |
|
139 | - case 'mysql': |
|
140 | - // Get last id to insert oid/values in secondary table |
|
141 | - $sql='SELECT LAST_INSERT_ID();'; |
|
142 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
143 | - $this->logging->log('Erreur getting id - mysql - ',1,''); |
|
144 | - } |
|
127 | + switch ($this->trapsDB->trapDBType) |
|
128 | + { |
|
129 | + case 'pgsql': |
|
130 | + // Get last id to insert oid/values in secondary table |
|
131 | + if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
|
132 | + $this->logging->log('Error getting id - pgsql - ',1,''); |
|
133 | + } |
|
134 | + if (! isset($inserted_id_ret['id'])) { |
|
135 | + $this->logging->log('Error getting id - pgsql - empty.',1,''); |
|
136 | + } |
|
137 | + $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
|
138 | + break; |
|
139 | + case 'mysql': |
|
140 | + // Get last id to insert oid/values in secondary table |
|
141 | + $sql='SELECT LAST_INSERT_ID();'; |
|
142 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
143 | + $this->logging->log('Erreur getting id - mysql - ',1,''); |
|
144 | + } |
|
145 | 145 | |
146 | - $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
147 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
148 | - $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
|
149 | - break; |
|
150 | - default: |
|
151 | - $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,''); |
|
152 | - } |
|
146 | + $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
|
147 | + if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
148 | + $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
|
149 | + break; |
|
150 | + default: |
|
151 | + $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,''); |
|
152 | + } |
|
153 | 153 | |
154 | - // Set as newly created. |
|
155 | - $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1; |
|
156 | - return 2; |
|
157 | - } |
|
154 | + // Set as newly created. |
|
155 | + $this->dbOidIndex[$this->oidDesc['oid']]['key']=-1; |
|
156 | + return 2; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | /** |
160 | 160 | * get all objects for a trap. |
161 | 161 | * @param integer $trapId |
162 | 162 | * @return array : array of cached objects |
163 | 163 | */ |
164 | - private function cache_db_objects($trapId) |
|
165 | - { |
|
166 | - $dbObjects=array(); // cache of objects for trap in db |
|
167 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
168 | - // Get all objects |
|
169 | - $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
|
170 | - $this->logging->log('SQL query get all traps: '.$sql,DEBUG ); |
|
171 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
172 | - $this->logging->log('No result in query : ' . $sql,1,''); |
|
173 | - } |
|
174 | - $dbObjectsRaw=$ret_code->fetchAll(); |
|
164 | + private function cache_db_objects($trapId) |
|
165 | + { |
|
166 | + $dbObjects=array(); // cache of objects for trap in db |
|
167 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
168 | + // Get all objects |
|
169 | + $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
|
170 | + $this->logging->log('SQL query get all traps: '.$sql,DEBUG ); |
|
171 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
172 | + $this->logging->log('No result in query : ' . $sql,1,''); |
|
173 | + } |
|
174 | + $dbObjectsRaw=$ret_code->fetchAll(); |
|
175 | 175 | |
176 | - foreach ($dbObjectsRaw as $val) |
|
177 | - { |
|
178 | - $dbObjects[$val['object_id']]=1; |
|
179 | - } |
|
180 | - return $dbObjects; |
|
181 | - } |
|
176 | + foreach ($dbObjectsRaw as $val) |
|
177 | + { |
|
178 | + $dbObjects[$val['object_id']]=1; |
|
179 | + } |
|
180 | + return $dbObjects; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * Get object details & mib , returns snmptranslate output |
@@ -186,472 +186,472 @@ discard block |
||
186 | 186 | * @param string $trapmib : mib of trap |
187 | 187 | * @return NULL|array : null if not found, or output of snmptranslate |
188 | 188 | */ |
189 | - private function get_object_details($object,$trapmib) |
|
190 | - { |
|
191 | - $match=$snmptrans=array(); |
|
192 | - $retVal=0; |
|
193 | - $this->oidDesc['mib']=$trapmib; |
|
194 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
195 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
196 | - if ($retVal!=0) |
|
197 | - { |
|
198 | - // Maybe not trap mib, search with IR |
|
199 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
200 | - ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
201 | - if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match)) |
|
202 | - { // Not found -> continue with warning |
|
203 | - $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,''); |
|
204 | - return null; |
|
205 | - } |
|
206 | - $this->oidDesc['mib']=$match[1]; |
|
189 | + private function get_object_details($object,$trapmib) |
|
190 | + { |
|
191 | + $match=$snmptrans=array(); |
|
192 | + $retVal=0; |
|
193 | + $this->oidDesc['mib']=$trapmib; |
|
194 | + exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
195 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
196 | + if ($retVal!=0) |
|
197 | + { |
|
198 | + // Maybe not trap mib, search with IR |
|
199 | + exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
200 | + ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
201 | + if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match)) |
|
202 | + { // Not found -> continue with warning |
|
203 | + $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,''); |
|
204 | + return null; |
|
205 | + } |
|
206 | + $this->oidDesc['mib']=$match[1]; |
|
207 | 207 | |
208 | - // Do the snmptranslate again. |
|
209 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
210 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal); |
|
211 | - if ($retVal!=0) { |
|
212 | - $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,''); |
|
213 | - return null; |
|
214 | - } |
|
208 | + // Do the snmptranslate again. |
|
209 | + exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
210 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal); |
|
211 | + if ($retVal!=0) { |
|
212 | + $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,''); |
|
213 | + return null; |
|
214 | + } |
|
215 | 215 | |
216 | - } |
|
217 | - return $snmptrans; |
|
218 | - } |
|
216 | + } |
|
217 | + return $snmptrans; |
|
218 | + } |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Parse snmptranslate output and set $this->oidDesc with elements |
222 | 222 | * @param array $snmptrans : multi line output of snmptrans |
223 | 223 | */ |
224 | - private function parse_object($snmptrans) |
|
225 | - { |
|
226 | - $tmpdesc=''; // For multiline description |
|
227 | - $indesc=false; // true if currently inside multiline description |
|
228 | - $match=array(); |
|
224 | + private function parse_object($snmptrans) |
|
225 | + { |
|
226 | + $tmpdesc=''; // For multiline description |
|
227 | + $indesc=false; // true if currently inside multiline description |
|
228 | + $match=array(); |
|
229 | 229 | |
230 | - foreach ($snmptrans as $line) |
|
231 | - { |
|
232 | - if ($indesc===true) |
|
233 | - { |
|
234 | - $line=preg_replace('/[\t ]+/',' ',$line); |
|
235 | - if (preg_match('/(.*)"$/', $line,$match)) |
|
236 | - { |
|
237 | - $this->oidDesc['description'] = $tmpdesc . $match[1]; |
|
238 | - $indesc=false; |
|
239 | - } |
|
240 | - $tmpdesc.=$line; |
|
241 | - continue; |
|
242 | - } |
|
243 | - if (preg_match('/^\.[0-9\.]+$/', $line)) |
|
244 | - { |
|
245 | - $this->oidDesc['oid']=$line; |
|
246 | - continue; |
|
247 | - } |
|
248 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match)) |
|
249 | - { |
|
250 | - $this->oidDesc['syntax']=$match[1]; |
|
251 | - $this->oidDesc['type_enum']=$match[2]; |
|
252 | - continue; |
|
253 | - } |
|
254 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match)) |
|
255 | - { |
|
256 | - $this->oidDesc['syntax']=$match[1]; |
|
257 | - continue; |
|
258 | - } |
|
259 | - if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match)) |
|
260 | - { |
|
261 | - $this->oidDesc['dispHint']=$match[1]; |
|
262 | - continue; |
|
263 | - } |
|
264 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match)) |
|
265 | - { |
|
266 | - $this->oidDesc['description']=$match[1]; |
|
267 | - continue; |
|
268 | - } |
|
269 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match)) |
|
270 | - { |
|
271 | - $tmpdesc=$match[1]; |
|
272 | - $indesc=true; |
|
273 | - continue; |
|
274 | - } |
|
275 | - if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match)) |
|
276 | - { |
|
277 | - $this->oidDesc['textconv']=$match[1]; |
|
278 | - continue; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
230 | + foreach ($snmptrans as $line) |
|
231 | + { |
|
232 | + if ($indesc===true) |
|
233 | + { |
|
234 | + $line=preg_replace('/[\t ]+/',' ',$line); |
|
235 | + if (preg_match('/(.*)"$/', $line,$match)) |
|
236 | + { |
|
237 | + $this->oidDesc['description'] = $tmpdesc . $match[1]; |
|
238 | + $indesc=false; |
|
239 | + } |
|
240 | + $tmpdesc.=$line; |
|
241 | + continue; |
|
242 | + } |
|
243 | + if (preg_match('/^\.[0-9\.]+$/', $line)) |
|
244 | + { |
|
245 | + $this->oidDesc['oid']=$line; |
|
246 | + continue; |
|
247 | + } |
|
248 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match)) |
|
249 | + { |
|
250 | + $this->oidDesc['syntax']=$match[1]; |
|
251 | + $this->oidDesc['type_enum']=$match[2]; |
|
252 | + continue; |
|
253 | + } |
|
254 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match)) |
|
255 | + { |
|
256 | + $this->oidDesc['syntax']=$match[1]; |
|
257 | + continue; |
|
258 | + } |
|
259 | + if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match)) |
|
260 | + { |
|
261 | + $this->oidDesc['dispHint']=$match[1]; |
|
262 | + continue; |
|
263 | + } |
|
264 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match)) |
|
265 | + { |
|
266 | + $this->oidDesc['description']=$match[1]; |
|
267 | + continue; |
|
268 | + } |
|
269 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match)) |
|
270 | + { |
|
271 | + $tmpdesc=$match[1]; |
|
272 | + $indesc=true; |
|
273 | + continue; |
|
274 | + } |
|
275 | + if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match)) |
|
276 | + { |
|
277 | + $this->oidDesc['textconv']=$match[1]; |
|
278 | + continue; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * create or update (with check_existing = true) objects of trap |
|
285 | - * @param string $trapOID : trap oid |
|
286 | - * @param string $trapmib : mib of trap |
|
287 | - * @param array $objects : array of objects name (without MIB) |
|
288 | - * @param bool $check_existing : check instead of create |
|
289 | - */ |
|
290 | - public function trap_objects($trapOID,$trapmib,$objects,$check_existing) |
|
291 | - { |
|
292 | - $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap |
|
283 | + /** |
|
284 | + * create or update (with check_existing = true) objects of trap |
|
285 | + * @param string $trapOID : trap oid |
|
286 | + * @param string $trapmib : mib of trap |
|
287 | + * @param array $objects : array of objects name (without MIB) |
|
288 | + * @param bool $check_existing : check instead of create |
|
289 | + */ |
|
290 | + public function trap_objects($trapOID,$trapmib,$objects,$check_existing) |
|
291 | + { |
|
292 | + $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap |
|
293 | 293 | |
294 | - if ($check_existing === true) |
|
295 | - { |
|
296 | - $dbObjects=$this->cache_db_objects($trapId); |
|
297 | - } |
|
294 | + if ($check_existing === true) |
|
295 | + { |
|
296 | + $dbObjects=$this->cache_db_objects($trapId); |
|
297 | + } |
|
298 | 298 | |
299 | - foreach ($objects as $object) |
|
300 | - { |
|
299 | + foreach ($objects as $object) |
|
300 | + { |
|
301 | 301 | |
302 | - $this->reset_oidDesc(); |
|
302 | + $this->reset_oidDesc(); |
|
303 | 303 | |
304 | - $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details |
|
305 | - if ($snmptrans === null) continue; // object not found |
|
304 | + $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details |
|
305 | + if ($snmptrans === null) continue; // object not found |
|
306 | 306 | |
307 | - $this->parse_object($snmptrans); |
|
307 | + $this->parse_object($snmptrans); |
|
308 | 308 | |
309 | - $this->oidDesc['name'] = $object; |
|
309 | + $this->oidDesc['name'] = $object; |
|
310 | 310 | |
311 | - $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 ); |
|
311 | + $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 ); |
|
312 | 312 | |
313 | - // Update |
|
314 | - $this->update_oid(); |
|
313 | + // Update |
|
314 | + $this->update_oid(); |
|
315 | 315 | |
316 | - if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']])) |
|
317 | - { // if link exists, continue |
|
318 | - $dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2; |
|
319 | - continue; |
|
320 | - } |
|
321 | - if ($check_existing === true) |
|
322 | - { |
|
323 | - // TODO : check link trap - objects exists, mark them. |
|
324 | - } |
|
325 | - // Associate in object table |
|
326 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
327 | - $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '. |
|
328 | - 'values (:trap_id, :object_id)'; |
|
329 | - $sqlQuery=$db_conn->prepare($sql); |
|
330 | - $sqlParam=array( |
|
331 | - ':trap_id' => $trapId, |
|
332 | - ':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'], |
|
333 | - ); |
|
316 | + if (isset($dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']])) |
|
317 | + { // if link exists, continue |
|
318 | + $dbObjects[$this->dbOidIndex[$this->oidDesc['oid']]['id']]=2; |
|
319 | + continue; |
|
320 | + } |
|
321 | + if ($check_existing === true) |
|
322 | + { |
|
323 | + // TODO : check link trap - objects exists, mark them. |
|
324 | + } |
|
325 | + // Associate in object table |
|
326 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
327 | + $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '. |
|
328 | + 'values (:trap_id, :object_id)'; |
|
329 | + $sqlQuery=$db_conn->prepare($sql); |
|
330 | + $sqlParam=array( |
|
331 | + ':trap_id' => $trapId, |
|
332 | + ':object_id' => $this->dbOidIndex[$this->oidDesc['oid']]['id'], |
|
333 | + ); |
|
334 | 334 | |
335 | - if ($sqlQuery->execute($sqlParam) === false) { |
|
336 | - $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,''); |
|
337 | - } |
|
338 | - } |
|
339 | - if ($check_existing === true) |
|
340 | - { |
|
341 | - // TODO : remove link trap - objects that wasn't marked. |
|
342 | - } |
|
335 | + if ($sqlQuery->execute($sqlParam) === false) { |
|
336 | + $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,''); |
|
337 | + } |
|
338 | + } |
|
339 | + if ($check_existing === true) |
|
340 | + { |
|
341 | + // TODO : remove link trap - objects that wasn't marked. |
|
342 | + } |
|
343 | 343 | |
344 | - } |
|
344 | + } |
|
345 | 345 | |
346 | - private function reset_oidDesc() |
|
347 | - { |
|
348 | - $this->oidDesc['oid']=null; |
|
349 | - $this->oidDesc['name']=null; |
|
350 | - $this->oidDesc['type']=null; |
|
351 | - $this->oidDesc['mib']=null; |
|
352 | - $this->oidDesc['textconv']=null; |
|
353 | - $this->oidDesc['dispHint'] =null; |
|
354 | - $this->oidDesc['syntax']=null; |
|
355 | - $this->oidDesc['type_enum']=null; |
|
356 | - $this->oidDesc['description']=null; |
|
357 | - } |
|
346 | + private function reset_oidDesc() |
|
347 | + { |
|
348 | + $this->oidDesc['oid']=null; |
|
349 | + $this->oidDesc['name']=null; |
|
350 | + $this->oidDesc['type']=null; |
|
351 | + $this->oidDesc['mib']=null; |
|
352 | + $this->oidDesc['textconv']=null; |
|
353 | + $this->oidDesc['dispHint'] =null; |
|
354 | + $this->oidDesc['syntax']=null; |
|
355 | + $this->oidDesc['type_enum']=null; |
|
356 | + $this->oidDesc['description']=null; |
|
357 | + } |
|
358 | 358 | |
359 | - /** |
|
360 | - * Fills $this->objectsAll with all mibs from snmptranslate |
|
361 | - * @return integer : number of elements |
|
362 | - */ |
|
363 | - private function load_mibs_snmptranslate() |
|
364 | - { |
|
365 | - $retVal=0; |
|
366 | - // Get all mib objects from all mibs |
|
367 | - $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null'; |
|
368 | - $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG ); |
|
369 | - unset($this->objectsAll); |
|
370 | - exec($snmpCommand,$this->objectsAll,$retVal); |
|
371 | - if ($retVal!=0) |
|
372 | - { |
|
373 | - $this->logging->log('error executing snmptranslate',ERROR,''); |
|
374 | - } |
|
375 | - // Count elements to show progress |
|
376 | - $numElements=count($this->objectsAll); |
|
377 | - $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO ); |
|
378 | - return $numElements; |
|
379 | - } |
|
359 | + /** |
|
360 | + * Fills $this->objectsAll with all mibs from snmptranslate |
|
361 | + * @return integer : number of elements |
|
362 | + */ |
|
363 | + private function load_mibs_snmptranslate() |
|
364 | + { |
|
365 | + $retVal=0; |
|
366 | + // Get all mib objects from all mibs |
|
367 | + $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null'; |
|
368 | + $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG ); |
|
369 | + unset($this->objectsAll); |
|
370 | + exec($snmpCommand,$this->objectsAll,$retVal); |
|
371 | + if ($retVal!=0) |
|
372 | + { |
|
373 | + $this->logging->log('error executing snmptranslate',ERROR,''); |
|
374 | + } |
|
375 | + // Count elements to show progress |
|
376 | + $numElements=count($this->objectsAll); |
|
377 | + $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO ); |
|
378 | + return $numElements; |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * load all mib objects db in dbOidAll (raw) and index in dbOidIndex |
|
383 | - */ |
|
384 | - private function load_mibs_from_db() |
|
385 | - { |
|
386 | - // Get all mibs from databse to have a memory index |
|
381 | + /** |
|
382 | + * load all mib objects db in dbOidAll (raw) and index in dbOidIndex |
|
383 | + */ |
|
384 | + private function load_mibs_from_db() |
|
385 | + { |
|
386 | + // Get all mibs from databse to have a memory index |
|
387 | 387 | |
388 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
388 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
389 | 389 | |
390 | - $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;'; |
|
391 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
392 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
393 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
394 | - } |
|
395 | - $this->dbOidAll=$ret_code->fetchAll(); |
|
396 | - $this->dbOidIndex=array(); |
|
397 | - // Create the index for db; |
|
398 | - foreach($this->dbOidAll as $key=>$val) |
|
399 | - { |
|
400 | - $this->dbOidIndex[$val['oid']]['key']=$key; |
|
401 | - $this->dbOidIndex[$val['oid']]['id']=$val['id']; |
|
402 | - } |
|
403 | - } |
|
390 | + $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;'; |
|
391 | + $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
392 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
393 | + $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
394 | + } |
|
395 | + $this->dbOidAll=$ret_code->fetchAll(); |
|
396 | + $this->dbOidIndex=array(); |
|
397 | + // Create the index for db; |
|
398 | + foreach($this->dbOidAll as $key=>$val) |
|
399 | + { |
|
400 | + $this->dbOidIndex[$val['oid']]['key']=$key; |
|
401 | + $this->dbOidIndex[$val['oid']]['id']=$val['id']; |
|
402 | + } |
|
403 | + } |
|
404 | 404 | |
405 | - /** |
|
406 | - * Reset all update timers & count to zero |
|
407 | - */ |
|
408 | - private function reset_update_timers() |
|
409 | - { |
|
410 | - $this->timing['base_parse_time']=0; |
|
411 | - $this->timing['base_check_time']=0; |
|
412 | - $this->timing['type0_check_time']=0; |
|
413 | - $this->timing['nottrap_time']=0; |
|
414 | - $this->timing['update_time']=0; |
|
415 | - $this->timing['objects_time']=0; |
|
416 | - $this->timing['base_parse_num']=0; |
|
417 | - $this->timing['base_check_num']=0; |
|
418 | - $this->timing['type0_check_num']=0; |
|
419 | - $this->timing['nottrap_num']=0; |
|
420 | - $this->timing['update_num']=0; |
|
421 | - $this->timing['objects_num']=0; |
|
422 | - $this->timing['num_traps']=0; |
|
423 | - } |
|
405 | + /** |
|
406 | + * Reset all update timers & count to zero |
|
407 | + */ |
|
408 | + private function reset_update_timers() |
|
409 | + { |
|
410 | + $this->timing['base_parse_time']=0; |
|
411 | + $this->timing['base_check_time']=0; |
|
412 | + $this->timing['type0_check_time']=0; |
|
413 | + $this->timing['nottrap_time']=0; |
|
414 | + $this->timing['update_time']=0; |
|
415 | + $this->timing['objects_time']=0; |
|
416 | + $this->timing['base_parse_num']=0; |
|
417 | + $this->timing['base_check_num']=0; |
|
418 | + $this->timing['type0_check_num']=0; |
|
419 | + $this->timing['nottrap_num']=0; |
|
420 | + $this->timing['update_num']=0; |
|
421 | + $this->timing['objects_num']=0; |
|
422 | + $this->timing['num_traps']=0; |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Detect if $this->objectsAll[$curElement] is a trap |
|
427 | - * @param integer $curElement |
|
428 | - * @param bool $onlyTraps : set to false to get all and not only traps. |
|
429 | - * @return boolean : false if it's a trap , true if not |
|
430 | - */ |
|
431 | - private function detect_trap($curElement,$onlyTraps) |
|
432 | - { |
|
433 | - // Get oid or pass if not found |
|
434 | - if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement])) |
|
435 | - { |
|
436 | - $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time']; |
|
437 | - $this->timing['base_parse_num'] ++; |
|
438 | - return true; |
|
439 | - } |
|
440 | - $this->oidDesc['oid']=$this->objectsAll[$curElement]; |
|
425 | + /** |
|
426 | + * Detect if $this->objectsAll[$curElement] is a trap |
|
427 | + * @param integer $curElement |
|
428 | + * @param bool $onlyTraps : set to false to get all and not only traps. |
|
429 | + * @return boolean : false if it's a trap , true if not |
|
430 | + */ |
|
431 | + private function detect_trap($curElement,$onlyTraps) |
|
432 | + { |
|
433 | + // Get oid or pass if not found |
|
434 | + if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement])) |
|
435 | + { |
|
436 | + $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time']; |
|
437 | + $this->timing['base_parse_num'] ++; |
|
438 | + return true; |
|
439 | + } |
|
440 | + $this->oidDesc['oid']=$this->objectsAll[$curElement]; |
|
441 | 441 | |
442 | - // get next line |
|
443 | - $curElement++; |
|
444 | - $match=$snmptrans=array(); |
|
445 | - if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/', |
|
446 | - $this->objectsAll[$curElement],$match)) |
|
447 | - { |
|
448 | - $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time']; |
|
449 | - $this->timing['base_check_num']++; |
|
450 | - return true; |
|
451 | - } |
|
442 | + // get next line |
|
443 | + $curElement++; |
|
444 | + $match=$snmptrans=array(); |
|
445 | + if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/', |
|
446 | + $this->objectsAll[$curElement],$match)) |
|
447 | + { |
|
448 | + $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time']; |
|
449 | + $this->timing['base_check_num']++; |
|
450 | + return true; |
|
451 | + } |
|
452 | 452 | |
453 | - $this->oidDesc['name']=$match[1]; // Name |
|
454 | - $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
|
453 | + $this->oidDesc['name']=$match[1]; // Name |
|
454 | + $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
|
455 | 455 | |
456 | - if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
457 | - { |
|
458 | - // Check if next is suboid -> in that case is cannot be a trap |
|
459 | - if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
|
460 | - { |
|
461 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
462 | - $this->timing['type0_check_num']++; |
|
463 | - return true; |
|
464 | - } |
|
465 | - unset($snmptrans); |
|
466 | - $retVal=0; |
|
467 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
468 | - ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal); |
|
469 | - if ($retVal!=0) |
|
470 | - { |
|
471 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
472 | - $this->timing['type0_check_num']++; |
|
473 | - return true; |
|
474 | - } |
|
475 | - //echo "\n v1 trap found : $this->oidDesc['oid'] \n"; |
|
476 | - // Force as trap. |
|
477 | - $this->oidDesc['type']=21; |
|
478 | - } |
|
479 | - if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
480 | - { |
|
481 | - $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
|
482 | - $this->timing['nottrap_num']++; |
|
483 | - return true; |
|
484 | - } |
|
485 | - return false; |
|
486 | - } |
|
456 | + if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
457 | + { |
|
458 | + // Check if next is suboid -> in that case is cannot be a trap |
|
459 | + if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
|
460 | + { |
|
461 | + $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
462 | + $this->timing['type0_check_num']++; |
|
463 | + return true; |
|
464 | + } |
|
465 | + unset($snmptrans); |
|
466 | + $retVal=0; |
|
467 | + exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
468 | + ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal); |
|
469 | + if ($retVal!=0) |
|
470 | + { |
|
471 | + $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
472 | + $this->timing['type0_check_num']++; |
|
473 | + return true; |
|
474 | + } |
|
475 | + //echo "\n v1 trap found : $this->oidDesc['oid'] \n"; |
|
476 | + // Force as trap. |
|
477 | + $this->oidDesc['type']=21; |
|
478 | + } |
|
479 | + if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
480 | + { |
|
481 | + $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
|
482 | + $this->timing['nottrap_num']++; |
|
483 | + return true; |
|
484 | + } |
|
485 | + return false; |
|
486 | + } |
|
487 | 487 | |
488 | - private function get_trap_mib_description() |
|
489 | - { |
|
490 | - $retVal=0; |
|
491 | - $match=$snmptrans=array(); |
|
492 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
493 | - ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal); |
|
494 | - if ($retVal!=0) |
|
495 | - { |
|
496 | - $this->logging->log('error executing snmptranslate',ERROR); |
|
497 | - } |
|
488 | + private function get_trap_mib_description() |
|
489 | + { |
|
490 | + $retVal=0; |
|
491 | + $match=$snmptrans=array(); |
|
492 | + exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
493 | + ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal); |
|
494 | + if ($retVal!=0) |
|
495 | + { |
|
496 | + $this->logging->log('error executing snmptranslate',ERROR); |
|
497 | + } |
|
498 | 498 | |
499 | - if (!preg_match('/^(.*)::/',$snmptrans[0],$match)) |
|
500 | - { |
|
501 | - $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR); |
|
502 | - } |
|
503 | - $this->oidDesc['mib']=$match[1]; |
|
499 | + if (!preg_match('/^(.*)::/',$snmptrans[0],$match)) |
|
500 | + { |
|
501 | + $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR); |
|
502 | + } |
|
503 | + $this->oidDesc['mib']=$match[1]; |
|
504 | 504 | |
505 | - $numLine=1; |
|
506 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
507 | - if (isset($snmptrans[$numLine])) |
|
508 | - { |
|
509 | - $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
|
505 | + $numLine=1; |
|
506 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
507 | + if (isset($snmptrans[$numLine])) |
|
508 | + { |
|
509 | + $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
|
510 | 510 | |
511 | - while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine])) |
|
512 | - { |
|
513 | - $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]); |
|
514 | - $numLine++; |
|
515 | - } |
|
516 | - if (isset($snmptrans[$numLine])) { |
|
517 | - $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]); |
|
518 | - $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']); |
|
519 | - } |
|
511 | + while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine])) |
|
512 | + { |
|
513 | + $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]); |
|
514 | + $numLine++; |
|
515 | + } |
|
516 | + if (isset($snmptrans[$numLine])) { |
|
517 | + $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]); |
|
518 | + $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']); |
|
519 | + } |
|
520 | 520 | |
521 | - } |
|
522 | - return $snmptrans; |
|
523 | - } |
|
521 | + } |
|
522 | + return $snmptrans; |
|
523 | + } |
|
524 | 524 | |
525 | - /** |
|
526 | - * Get trap objects |
|
527 | - * @param string $snmptrans : output of snmptranslate for TrapModuleConfig |
|
528 | - * @return array|null : array of objects or null if not found |
|
529 | - **/ |
|
530 | - private function get_trap_objects($snmptrans) |
|
531 | - { |
|
532 | - $objectName=null; |
|
533 | - $match=array(); |
|
534 | - foreach ($snmptrans as $line) |
|
535 | - { |
|
536 | - if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match)) |
|
537 | - { |
|
538 | - $objectName=$match[1]; |
|
539 | - } |
|
540 | - } |
|
541 | - if ($objectName == null) |
|
542 | - { |
|
543 | - $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG); |
|
544 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
545 | - return null; |
|
546 | - } |
|
525 | + /** |
|
526 | + * Get trap objects |
|
527 | + * @param string $snmptrans : output of snmptranslate for TrapModuleConfig |
|
528 | + * @return array|null : array of objects or null if not found |
|
529 | + **/ |
|
530 | + private function get_trap_objects($snmptrans) |
|
531 | + { |
|
532 | + $objectName=null; |
|
533 | + $match=array(); |
|
534 | + foreach ($snmptrans as $line) |
|
535 | + { |
|
536 | + if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match)) |
|
537 | + { |
|
538 | + $objectName=$match[1]; |
|
539 | + } |
|
540 | + } |
|
541 | + if ($objectName == null) |
|
542 | + { |
|
543 | + $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG); |
|
544 | + $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
545 | + return null; |
|
546 | + } |
|
547 | 547 | |
548 | - $trapObjects=array(); |
|
549 | - while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match)) |
|
550 | - { |
|
551 | - array_push($trapObjects,$match[1]); |
|
552 | - $objectName=preg_replace('/'.$match[0].'/','',$objectName); |
|
553 | - } |
|
554 | - return $trapObjects; |
|
555 | - } |
|
548 | + $trapObjects=array(); |
|
549 | + while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match)) |
|
550 | + { |
|
551 | + array_push($trapObjects,$match[1]); |
|
552 | + $objectName=preg_replace('/'.$match[0].'/','',$objectName); |
|
553 | + } |
|
554 | + return $trapObjects; |
|
555 | + } |
|
556 | 556 | |
557 | - /** |
|
558 | - * Cache mib in database |
|
559 | - * @param boolean $display_progress : Display progress on standard output |
|
560 | - * @param boolean $check_change : Force check of trap params & objects |
|
561 | - * @param boolean $onlyTraps : only cache traps and objects (true) or all (false) |
|
562 | - * @param string $startOID : only cache under startOID (NOT IMPLEMENTED) |
|
563 | - */ |
|
564 | - public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1') |
|
565 | - { |
|
566 | - // Global Timing |
|
567 | - $timeTaken = microtime(true); |
|
557 | + /** |
|
558 | + * Cache mib in database |
|
559 | + * @param boolean $display_progress : Display progress on standard output |
|
560 | + * @param boolean $check_change : Force check of trap params & objects |
|
561 | + * @param boolean $onlyTraps : only cache traps and objects (true) or all (false) |
|
562 | + * @param string $startOID : only cache under startOID (NOT IMPLEMENTED) |
|
563 | + */ |
|
564 | + public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1') |
|
565 | + { |
|
566 | + // Global Timing |
|
567 | + $timeTaken = microtime(true); |
|
568 | 568 | |
569 | - $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll |
|
569 | + $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll |
|
570 | 570 | |
571 | - $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex |
|
571 | + $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex |
|
572 | 572 | |
573 | - $step=$basestep=$numElements/10; // output display of % done |
|
574 | - $num_step=0; |
|
575 | - $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds |
|
573 | + $step=$basestep=$numElements/10; // output display of % done |
|
574 | + $num_step=0; |
|
575 | + $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds |
|
576 | 576 | |
577 | - // Create index for trap objects |
|
578 | - $this->trapObjectsIndex=array(); |
|
577 | + // Create index for trap objects |
|
578 | + $this->trapObjectsIndex=array(); |
|
579 | 579 | |
580 | - // detailed timing (time_* vars) |
|
581 | - $this->reset_update_timers(); |
|
580 | + // detailed timing (time_* vars) |
|
581 | + $this->reset_update_timers(); |
|
582 | 582 | |
583 | - for ($curElement=0;$curElement < $numElements;$curElement++) |
|
584 | - { |
|
585 | - $this->timing['base_time']= microtime(true); |
|
586 | - if ($display_progress) |
|
587 | - { |
|
588 | - if ((microtime(true)-$timeFiveSec) > 2) |
|
589 | - { // echo a . every 2 sec |
|
590 | - echo '.'; |
|
591 | - $timeFiveSec = microtime(true); |
|
592 | - } |
|
593 | - if ($curElement>$step) |
|
594 | - { // display progress |
|
595 | - $num_step++; |
|
596 | - $step+=$basestep; |
|
597 | - echo "\n" . ($num_step*10). '% : '; |
|
598 | - } |
|
599 | - } |
|
583 | + for ($curElement=0;$curElement < $numElements;$curElement++) |
|
584 | + { |
|
585 | + $this->timing['base_time']= microtime(true); |
|
586 | + if ($display_progress) |
|
587 | + { |
|
588 | + if ((microtime(true)-$timeFiveSec) > 2) |
|
589 | + { // echo a . every 2 sec |
|
590 | + echo '.'; |
|
591 | + $timeFiveSec = microtime(true); |
|
592 | + } |
|
593 | + if ($curElement>$step) |
|
594 | + { // display progress |
|
595 | + $num_step++; |
|
596 | + $step+=$basestep; |
|
597 | + echo "\n" . ($num_step*10). '% : '; |
|
598 | + } |
|
599 | + } |
|
600 | 600 | |
601 | - $this->reset_oidDesc(); |
|
602 | - if ($this->detect_trap($curElement,$onlyTraps)===true) |
|
603 | - { |
|
604 | - continue; |
|
605 | - } |
|
601 | + $this->reset_oidDesc(); |
|
602 | + if ($this->detect_trap($curElement,$onlyTraps)===true) |
|
603 | + { |
|
604 | + continue; |
|
605 | + } |
|
606 | 606 | |
607 | - $this->timing['num_traps']++; |
|
607 | + $this->timing['num_traps']++; |
|
608 | 608 | |
609 | - $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
|
610 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
609 | + $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
|
610 | + if ($display_progress) echo '#'; // echo a # when trap found |
|
611 | 611 | |
612 | - // get trap objects & source MIB |
|
612 | + // get trap objects & source MIB |
|
613 | 613 | |
614 | - $snmptrans=$this->get_trap_mib_description(); // get MIB & description |
|
614 | + $snmptrans=$this->get_trap_mib_description(); // get MIB & description |
|
615 | 615 | |
616 | 616 | |
617 | - $update=$this->update_oid(); // Do update of trap. |
|
617 | + $update=$this->update_oid(); // Do update of trap. |
|
618 | 618 | |
619 | - $this->timing['update_time'] += microtime(true) - $this->timing['base_time']; |
|
620 | - $this->timing['update_num']++; |
|
619 | + $this->timing['update_time'] += microtime(true) - $this->timing['base_time']; |
|
620 | + $this->timing['update_num']++; |
|
621 | 621 | |
622 | - $this->timing['base_time']= microtime(true); // Reset to check object time |
|
622 | + $this->timing['base_time']= microtime(true); // Reset to check object time |
|
623 | 623 | |
624 | - if (($update==0) && ($check_change===false)) |
|
625 | - { // Trapd didn't change & force check disabled |
|
626 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
627 | - if ($display_progress) echo "C"; |
|
628 | - continue; |
|
629 | - } |
|
624 | + if (($update==0) && ($check_change===false)) |
|
625 | + { // Trapd didn't change & force check disabled |
|
626 | + $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
627 | + if ($display_progress) echo "C"; |
|
628 | + continue; |
|
629 | + } |
|
630 | 630 | |
631 | - $trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output |
|
632 | - if ($trapObjects == null) |
|
633 | - { |
|
634 | - continue; |
|
635 | - } |
|
631 | + $trapObjects=$this->get_trap_objects($snmptrans); // Get trap objects from snmptranslate output |
|
632 | + if ($trapObjects == null) |
|
633 | + { |
|
634 | + continue; |
|
635 | + } |
|
636 | 636 | |
637 | - $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false); |
|
637 | + $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false); |
|
638 | 638 | |
639 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
640 | - $this->timing['objects_num']++; |
|
641 | - } |
|
639 | + $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
640 | + $this->timing['objects_num']++; |
|
641 | + } |
|
642 | 642 | |
643 | - if ($display_progress) |
|
644 | - { |
|
645 | - echo "\nNumber of processed traps : ". $this->timing['num_traps'] ."\n"; |
|
646 | - 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"; |
|
647 | - 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"; |
|
648 | - echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , "; |
|
649 | - echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n"; |
|
643 | + if ($display_progress) |
|
644 | + { |
|
645 | + echo "\nNumber of processed traps : ". $this->timing['num_traps'] ."\n"; |
|
646 | + 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"; |
|
647 | + 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"; |
|
648 | + echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , "; |
|
649 | + echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n"; |
|
650 | 650 | |
651 | - $timeTaken=microtime(true) - $timeTaken; |
|
652 | - echo "Global time : ".round($timeTaken)." seconds\n"; |
|
653 | - } |
|
654 | - } |
|
651 | + $timeTaken=microtime(true) - $timeTaken; |
|
652 | + echo "Global time : ".round($timeTaken)." seconds\n"; |
|
653 | + } |
|
654 | + } |
|
655 | 655 | |
656 | 656 | |
657 | 657 | } |
658 | 658 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param Logging $logClass : where to log |
33 | 33 | * @param Database $dbClass : Database |
34 | 34 | */ |
35 | - function __construct($logClass,$dbClass,$snmptrans,$snmptransdir) |
|
35 | + function __construct($logClass, $dbClass, $snmptrans, $snmptransdir) |
|
36 | 36 | { |
37 | 37 | $this->logging=$logClass; |
38 | 38 | $this->trapsDB=$dbClass; |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | } |
60 | 60 | $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll |
61 | 61 | $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element |
62 | - if ( $this->oidDesc['name'] != $dbOid['name'] || |
|
62 | + if ($this->oidDesc['name'] != $dbOid['name'] || |
|
63 | 63 | $this->oidDesc['mib'] != $dbOid['mib'] || |
64 | - $this->oidDesc['type'] !=$dbOid['type'] |
|
64 | + $this->oidDesc['type'] != $dbOid['type'] |
|
65 | 65 | ) |
66 | 66 | { // Do update |
67 | 67 | $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '. |
@@ -75,22 +75,22 @@ discard block |
||
75 | 75 | ':type' => $this->oidDesc['type'], |
76 | 76 | ':mib' => $this->oidDesc['mib'], |
77 | 77 | ':tc' => $this->oidDesc['textconv']??'null', |
78 | - ':display_hint' => $this->oidDesc['dispHint']??'null' , |
|
79 | - ':syntax' => $this->oidDesc['syntax']==null??'null', |
|
78 | + ':display_hint' => $this->oidDesc['dispHint']??'null', |
|
79 | + ':syntax' => $this->oidDesc['syntax'] == null??'null', |
|
80 | 80 | ':type_enum' => $this->oidDesc['type_enum']??'null', |
81 | 81 | ':description' => $this->oidDesc['description']??'null', |
82 | 82 | ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']] |
83 | 83 | ); |
84 | 84 | |
85 | 85 | if ($sqlQuery->execute($sqlParam) === false) { |
86 | - $this->logging->log('Error in query : ' . $sql,ERROR,''); |
|
86 | + $this->logging->log('Error in query : '.$sql, ERROR, ''); |
|
87 | 87 | } |
88 | - $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
88 | + $this->logging->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG); |
|
89 | 89 | return 1; |
90 | 90 | } |
91 | 91 | else |
92 | 92 | { |
93 | - $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
|
93 | + $this->logging->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG); |
|
94 | 94 | return 0; |
95 | 95 | } |
96 | 96 | } |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | |
101 | 101 | $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '. |
102 | 102 | '(oid, name, type , mib, textual_convention, display_hint '. |
103 | - ', syntax, type_enum , description ) ' . |
|
103 | + ', syntax, type_enum , description ) '. |
|
104 | 104 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
105 | 105 | ', :syntax, :type_enum, :description )'; |
106 | 106 | |
107 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
107 | + if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id'; |
|
108 | 108 | |
109 | 109 | $sqlQuery=$db_conn->prepare($sql); |
110 | 110 | |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | ':name' => $this->oidDesc['name'], |
114 | 114 | ':type' => $this->oidDesc['type'], |
115 | 115 | ':mib' => $this->oidDesc['mib'], |
116 | - ':tc' => ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] , |
|
117 | - ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] , |
|
118 | - ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'], |
|
119 | - ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'], |
|
120 | - ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description'] |
|
116 | + ':tc' => ($this->oidDesc['textconv'] == null) ? 'null' : $this->oidDesc['textconv'], |
|
117 | + ':display_hint' => ($this->oidDesc['dispHint'] == null) ? 'null' : $this->oidDesc['dispHint'], |
|
118 | + ':syntax' => ($this->oidDesc['syntax'] == null) ? 'null' : $this->oidDesc['syntax'], |
|
119 | + ':type_enum' => ($this->oidDesc['type_enum'] == null) ? 'null' : $this->oidDesc['type_enum'], |
|
120 | + ':description' => ($this->oidDesc['description'] == null) ? 'null' : $this->oidDesc['description'] |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | if ($sqlQuery->execute($sqlParam) === false) { |
124 | - $this->logging->log('Error in query : ' . $sql,1,''); |
|
124 | + $this->logging->log('Error in query : '.$sql, 1, ''); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | switch ($this->trapsDB->trapDBType) |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | case 'pgsql': |
130 | 130 | // Get last id to insert oid/values in secondary table |
131 | 131 | if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) { |
132 | - $this->logging->log('Error getting id - pgsql - ',1,''); |
|
132 | + $this->logging->log('Error getting id - pgsql - ', 1, ''); |
|
133 | 133 | } |
134 | - if (! isset($inserted_id_ret['id'])) { |
|
135 | - $this->logging->log('Error getting id - pgsql - empty.',1,''); |
|
134 | + if (!isset($inserted_id_ret['id'])) { |
|
135 | + $this->logging->log('Error getting id - pgsql - empty.', 1, ''); |
|
136 | 136 | } |
137 | 137 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id']; |
138 | 138 | break; |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | // Get last id to insert oid/values in secondary table |
141 | 141 | $sql='SELECT LAST_INSERT_ID();'; |
142 | 142 | if (($ret_code=$db_conn->query($sql)) === false) { |
143 | - $this->logging->log('Erreur getting id - mysql - ',1,''); |
|
143 | + $this->logging->log('Erreur getting id - mysql - ', 1, ''); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
147 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
147 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
148 | 148 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
149 | 149 | break; |
150 | 150 | default: |
151 | - $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,''); |
|
151 | + $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, ''); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Set as newly created. |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | $db_conn=$this->trapsDB->db_connect_trap(); |
168 | 168 | // Get all objects |
169 | 169 | $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
170 | - $this->logging->log('SQL query get all traps: '.$sql,DEBUG ); |
|
170 | + $this->logging->log('SQL query get all traps: '.$sql, DEBUG); |
|
171 | 171 | if (($ret_code=$db_conn->query($sql)) === false) { |
172 | - $this->logging->log('No result in query : ' . $sql,1,''); |
|
172 | + $this->logging->log('No result in query : '.$sql, 1, ''); |
|
173 | 173 | } |
174 | 174 | $dbObjectsRaw=$ret_code->fetchAll(); |
175 | 175 | |
@@ -186,30 +186,30 @@ discard block |
||
186 | 186 | * @param string $trapmib : mib of trap |
187 | 187 | * @return NULL|array : null if not found, or output of snmptranslate |
188 | 188 | */ |
189 | - private function get_object_details($object,$trapmib) |
|
189 | + private function get_object_details($object, $trapmib) |
|
190 | 190 | { |
191 | 191 | $match=$snmptrans=array(); |
192 | 192 | $retVal=0; |
193 | 193 | $this->oidDesc['mib']=$trapmib; |
194 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
195 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
196 | - if ($retVal!=0) |
|
194 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs. |
|
195 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
196 | + if ($retVal != 0) |
|
197 | 197 | { |
198 | 198 | // Maybe not trap mib, search with IR |
199 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
200 | - ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
201 | - if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match)) |
|
199 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs. |
|
200 | + ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
201 | + if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match)) |
|
202 | 202 | { // Not found -> continue with warning |
203 | - $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,''); |
|
203 | + $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, ''); |
|
204 | 204 | return null; |
205 | 205 | } |
206 | 206 | $this->oidDesc['mib']=$match[1]; |
207 | 207 | |
208 | 208 | // Do the snmptranslate again. |
209 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
210 | - ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal); |
|
211 | - if ($retVal!=0) { |
|
212 | - $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,''); |
|
209 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs. |
|
210 | + ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal); |
|
211 | + if ($retVal != 0) { |
|
212 | + $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, ''); |
|
213 | 213 | return null; |
214 | 214 | } |
215 | 215 | |
@@ -229,12 +229,12 @@ discard block |
||
229 | 229 | |
230 | 230 | foreach ($snmptrans as $line) |
231 | 231 | { |
232 | - if ($indesc===true) |
|
232 | + if ($indesc === true) |
|
233 | 233 | { |
234 | - $line=preg_replace('/[\t ]+/',' ',$line); |
|
235 | - if (preg_match('/(.*)"$/', $line,$match)) |
|
234 | + $line=preg_replace('/[\t ]+/', ' ', $line); |
|
235 | + if (preg_match('/(.*)"$/', $line, $match)) |
|
236 | 236 | { |
237 | - $this->oidDesc['description'] = $tmpdesc . $match[1]; |
|
237 | + $this->oidDesc['description']=$tmpdesc.$match[1]; |
|
238 | 238 | $indesc=false; |
239 | 239 | } |
240 | 240 | $tmpdesc.=$line; |
@@ -245,34 +245,34 @@ discard block |
||
245 | 245 | $this->oidDesc['oid']=$line; |
246 | 246 | continue; |
247 | 247 | } |
248 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match)) |
|
248 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match)) |
|
249 | 249 | { |
250 | 250 | $this->oidDesc['syntax']=$match[1]; |
251 | 251 | $this->oidDesc['type_enum']=$match[2]; |
252 | 252 | continue; |
253 | 253 | } |
254 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match)) |
|
254 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match)) |
|
255 | 255 | { |
256 | 256 | $this->oidDesc['syntax']=$match[1]; |
257 | 257 | continue; |
258 | 258 | } |
259 | - if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match)) |
|
259 | + if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match)) |
|
260 | 260 | { |
261 | 261 | $this->oidDesc['dispHint']=$match[1]; |
262 | 262 | continue; |
263 | 263 | } |
264 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match)) |
|
264 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match)) |
|
265 | 265 | { |
266 | 266 | $this->oidDesc['description']=$match[1]; |
267 | 267 | continue; |
268 | 268 | } |
269 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match)) |
|
269 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match)) |
|
270 | 270 | { |
271 | 271 | $tmpdesc=$match[1]; |
272 | 272 | $indesc=true; |
273 | 273 | continue; |
274 | 274 | } |
275 | - if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match)) |
|
275 | + if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match)) |
|
276 | 276 | { |
277 | 277 | $this->oidDesc['textconv']=$match[1]; |
278 | 278 | continue; |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @param array $objects : array of objects name (without MIB) |
288 | 288 | * @param bool $check_existing : check instead of create |
289 | 289 | */ |
290 | - public function trap_objects($trapOID,$trapmib,$objects,$check_existing) |
|
290 | + public function trap_objects($trapOID, $trapmib, $objects, $check_existing) |
|
291 | 291 | { |
292 | - $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap |
|
292 | + $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap |
|
293 | 293 | |
294 | 294 | if ($check_existing === true) |
295 | 295 | { |
@@ -306,9 +306,9 @@ discard block |
||
306 | 306 | |
307 | 307 | $this->parse_object($snmptrans); |
308 | 308 | |
309 | - $this->oidDesc['name'] = $object; |
|
309 | + $this->oidDesc['name']=$object; |
|
310 | 310 | |
311 | - $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 ); |
|
311 | + $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); |
|
312 | 312 | |
313 | 313 | // Update |
314 | 314 | $this->update_oid(); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | ); |
334 | 334 | |
335 | 335 | if ($sqlQuery->execute($sqlParam) === false) { |
336 | - $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,''); |
|
336 | + $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, ''); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | if ($check_existing === true) |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | $this->oidDesc['type']=null; |
351 | 351 | $this->oidDesc['mib']=null; |
352 | 352 | $this->oidDesc['textconv']=null; |
353 | - $this->oidDesc['dispHint'] =null; |
|
353 | + $this->oidDesc['dispHint']=null; |
|
354 | 354 | $this->oidDesc['syntax']=null; |
355 | 355 | $this->oidDesc['type_enum']=null; |
356 | 356 | $this->oidDesc['description']=null; |
@@ -364,17 +364,17 @@ discard block |
||
364 | 364 | { |
365 | 365 | $retVal=0; |
366 | 366 | // Get all mib objects from all mibs |
367 | - $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null'; |
|
368 | - $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG ); |
|
367 | + $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null'; |
|
368 | + $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG); |
|
369 | 369 | unset($this->objectsAll); |
370 | - exec($snmpCommand,$this->objectsAll,$retVal); |
|
371 | - if ($retVal!=0) |
|
370 | + exec($snmpCommand, $this->objectsAll, $retVal); |
|
371 | + if ($retVal != 0) |
|
372 | 372 | { |
373 | - $this->logging->log('error executing snmptranslate',ERROR,''); |
|
373 | + $this->logging->log('error executing snmptranslate', ERROR, ''); |
|
374 | 374 | } |
375 | 375 | // Count elements to show progress |
376 | 376 | $numElements=count($this->objectsAll); |
377 | - $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO ); |
|
377 | + $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO); |
|
378 | 378 | return $numElements; |
379 | 379 | } |
380 | 380 | |
@@ -388,14 +388,14 @@ discard block |
||
388 | 388 | $db_conn=$this->trapsDB->db_connect_trap(); |
389 | 389 | |
390 | 390 | $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;'; |
391 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
391 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
392 | 392 | if (($ret_code=$db_conn->query($sql)) === false) { |
393 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
393 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
394 | 394 | } |
395 | 395 | $this->dbOidAll=$ret_code->fetchAll(); |
396 | 396 | $this->dbOidIndex=array(); |
397 | 397 | // Create the index for db; |
398 | - foreach($this->dbOidAll as $key=>$val) |
|
398 | + foreach ($this->dbOidAll as $key=>$val) |
|
399 | 399 | { |
400 | 400 | $this->dbOidIndex[$val['oid']]['key']=$key; |
401 | 401 | $this->dbOidIndex[$val['oid']]['id']=$val['id']; |
@@ -428,13 +428,13 @@ discard block |
||
428 | 428 | * @param bool $onlyTraps : set to false to get all and not only traps. |
429 | 429 | * @return boolean : false if it's a trap , true if not |
430 | 430 | */ |
431 | - private function detect_trap($curElement,$onlyTraps) |
|
431 | + private function detect_trap($curElement, $onlyTraps) |
|
432 | 432 | { |
433 | 433 | // Get oid or pass if not found |
434 | - if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement])) |
|
434 | + if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement])) |
|
435 | 435 | { |
436 | - $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time']; |
|
437 | - $this->timing['base_parse_num'] ++; |
|
436 | + $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time']; |
|
437 | + $this->timing['base_parse_num']++; |
|
438 | 438 | return true; |
439 | 439 | } |
440 | 440 | $this->oidDesc['oid']=$this->objectsAll[$curElement]; |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | $curElement++; |
444 | 444 | $match=$snmptrans=array(); |
445 | 445 | if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/', |
446 | - $this->objectsAll[$curElement],$match)) |
|
446 | + $this->objectsAll[$curElement], $match)) |
|
447 | 447 | { |
448 | - $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time']; |
|
448 | + $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time']; |
|
449 | 449 | $this->timing['base_check_num']++; |
450 | 450 | return true; |
451 | 451 | } |
@@ -453,22 +453,22 @@ discard block |
||
453 | 453 | $this->oidDesc['name']=$match[1]; // Name |
454 | 454 | $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
455 | 455 | |
456 | - if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
456 | + if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap |
|
457 | 457 | { |
458 | 458 | // Check if next is suboid -> in that case is cannot be a trap |
459 | - if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
|
459 | + if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1])) |
|
460 | 460 | { |
461 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
461 | + $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time']; |
|
462 | 462 | $this->timing['type0_check_num']++; |
463 | 463 | return true; |
464 | 464 | } |
465 | 465 | unset($snmptrans); |
466 | 466 | $retVal=0; |
467 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
468 | - ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal); |
|
469 | - if ($retVal!=0) |
|
467 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs. |
|
468 | + ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal); |
|
469 | + if ($retVal != 0) |
|
470 | 470 | { |
471 | - $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
|
471 | + $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time']; |
|
472 | 472 | $this->timing['type0_check_num']++; |
473 | 473 | return true; |
474 | 474 | } |
@@ -476,9 +476,9 @@ discard block |
||
476 | 476 | // Force as trap. |
477 | 477 | $this->oidDesc['type']=21; |
478 | 478 | } |
479 | - if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
479 | + if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue |
|
480 | 480 | { |
481 | - $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
|
481 | + $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time']; |
|
482 | 482 | $this->timing['nottrap_num']++; |
483 | 483 | return true; |
484 | 484 | } |
@@ -489,33 +489,33 @@ discard block |
||
489 | 489 | { |
490 | 490 | $retVal=0; |
491 | 491 | $match=$snmptrans=array(); |
492 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs. |
|
493 | - ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal); |
|
494 | - if ($retVal!=0) |
|
492 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs. |
|
493 | + ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal); |
|
494 | + if ($retVal != 0) |
|
495 | 495 | { |
496 | - $this->logging->log('error executing snmptranslate',ERROR); |
|
496 | + $this->logging->log('error executing snmptranslate', ERROR); |
|
497 | 497 | } |
498 | 498 | |
499 | - if (!preg_match('/^(.*)::/',$snmptrans[0],$match)) |
|
499 | + if (!preg_match('/^(.*)::/', $snmptrans[0], $match)) |
|
500 | 500 | { |
501 | - $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR); |
|
501 | + $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR); |
|
502 | 502 | } |
503 | 503 | $this->oidDesc['mib']=$match[1]; |
504 | 504 | |
505 | 505 | $numLine=1; |
506 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
506 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++; |
|
507 | 507 | if (isset($snmptrans[$numLine])) |
508 | 508 | { |
509 | - $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
|
509 | + $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]); |
|
510 | 510 | |
511 | - while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine])) |
|
511 | + while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine])) |
|
512 | 512 | { |
513 | - $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]); |
|
513 | + $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]); |
|
514 | 514 | $numLine++; |
515 | 515 | } |
516 | 516 | if (isset($snmptrans[$numLine])) { |
517 | - $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]); |
|
518 | - $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']); |
|
517 | + $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]); |
|
518 | + $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | } |
@@ -533,23 +533,23 @@ discard block |
||
533 | 533 | $match=array(); |
534 | 534 | foreach ($snmptrans as $line) |
535 | 535 | { |
536 | - if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match)) |
|
536 | + if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match)) |
|
537 | 537 | { |
538 | 538 | $objectName=$match[1]; |
539 | 539 | } |
540 | 540 | } |
541 | 541 | if ($objectName == null) |
542 | 542 | { |
543 | - $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG); |
|
544 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
543 | + $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG); |
|
544 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
545 | 545 | return null; |
546 | 546 | } |
547 | 547 | |
548 | 548 | $trapObjects=array(); |
549 | - while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match)) |
|
549 | + while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match)) |
|
550 | 550 | { |
551 | - array_push($trapObjects,$match[1]); |
|
552 | - $objectName=preg_replace('/'.$match[0].'/','',$objectName); |
|
551 | + array_push($trapObjects, $match[1]); |
|
552 | + $objectName=preg_replace('/'.$match[0].'/', '', $objectName); |
|
553 | 553 | } |
554 | 554 | return $trapObjects; |
555 | 555 | } |
@@ -561,18 +561,18 @@ discard block |
||
561 | 561 | * @param boolean $onlyTraps : only cache traps and objects (true) or all (false) |
562 | 562 | * @param string $startOID : only cache under startOID (NOT IMPLEMENTED) |
563 | 563 | */ |
564 | - public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1') |
|
564 | + public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1') |
|
565 | 565 | { |
566 | 566 | // Global Timing |
567 | - $timeTaken = microtime(true); |
|
567 | + $timeTaken=microtime(true); |
|
568 | 568 | |
569 | 569 | $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll |
570 | 570 | |
571 | 571 | $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex |
572 | 572 | |
573 | - $step=$basestep=$numElements/10; // output display of % done |
|
573 | + $step=$basestep=$numElements / 10; // output display of % done |
|
574 | 574 | $num_step=0; |
575 | - $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds |
|
575 | + $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds |
|
576 | 576 | |
577 | 577 | // Create index for trap objects |
578 | 578 | $this->trapObjectsIndex=array(); |
@@ -580,33 +580,33 @@ discard block |
||
580 | 580 | // detailed timing (time_* vars) |
581 | 581 | $this->reset_update_timers(); |
582 | 582 | |
583 | - for ($curElement=0;$curElement < $numElements;$curElement++) |
|
583 | + for ($curElement=0; $curElement < $numElements; $curElement++) |
|
584 | 584 | { |
585 | - $this->timing['base_time']= microtime(true); |
|
585 | + $this->timing['base_time']=microtime(true); |
|
586 | 586 | if ($display_progress) |
587 | 587 | { |
588 | - if ((microtime(true)-$timeFiveSec) > 2) |
|
588 | + if ((microtime(true) - $timeFiveSec) > 2) |
|
589 | 589 | { // echo a . every 2 sec |
590 | 590 | echo '.'; |
591 | - $timeFiveSec = microtime(true); |
|
591 | + $timeFiveSec=microtime(true); |
|
592 | 592 | } |
593 | - if ($curElement>$step) |
|
593 | + if ($curElement > $step) |
|
594 | 594 | { // display progress |
595 | 595 | $num_step++; |
596 | 596 | $step+=$basestep; |
597 | - echo "\n" . ($num_step*10). '% : '; |
|
597 | + echo "\n".($num_step * 10).'% : '; |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
601 | 601 | $this->reset_oidDesc(); |
602 | - if ($this->detect_trap($curElement,$onlyTraps)===true) |
|
602 | + if ($this->detect_trap($curElement, $onlyTraps) === true) |
|
603 | 603 | { |
604 | 604 | continue; |
605 | 605 | } |
606 | 606 | |
607 | 607 | $this->timing['num_traps']++; |
608 | 608 | |
609 | - $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
|
609 | + $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO); |
|
610 | 610 | if ($display_progress) echo '#'; // echo a # when trap found |
611 | 611 | |
612 | 612 | // get trap objects & source MIB |
@@ -616,14 +616,14 @@ discard block |
||
616 | 616 | |
617 | 617 | $update=$this->update_oid(); // Do update of trap. |
618 | 618 | |
619 | - $this->timing['update_time'] += microtime(true) - $this->timing['base_time']; |
|
619 | + $this->timing['update_time']+=microtime(true) - $this->timing['base_time']; |
|
620 | 620 | $this->timing['update_num']++; |
621 | 621 | |
622 | - $this->timing['base_time']= microtime(true); // Reset to check object time |
|
622 | + $this->timing['base_time']=microtime(true); // Reset to check object time |
|
623 | 623 | |
624 | - if (($update==0) && ($check_change===false)) |
|
624 | + if (($update == 0) && ($check_change === false)) |
|
625 | 625 | { // Trapd didn't change & force check disabled |
626 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
626 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
627 | 627 | if ($display_progress) echo "C"; |
628 | 628 | continue; |
629 | 629 | } |
@@ -636,17 +636,17 @@ discard block |
||
636 | 636 | |
637 | 637 | $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false); |
638 | 638 | |
639 | - $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
|
639 | + $this->timing['objects_time']+=microtime(true) - $this->timing['base_time']; |
|
640 | 640 | $this->timing['objects_num']++; |
641 | 641 | } |
642 | 642 | |
643 | 643 | if ($display_progress) |
644 | 644 | { |
645 | - echo "\nNumber of processed traps : ". $this->timing['num_traps'] ."\n"; |
|
646 | - 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"; |
|
647 | - 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"; |
|
648 | - echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , "; |
|
649 | - echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n"; |
|
645 | + echo "\nNumber of processed traps : ".$this->timing['num_traps']."\n"; |
|
646 | + 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"; |
|
647 | + 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"; |
|
648 | + echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , "; |
|
649 | + echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n"; |
|
650 | 650 | |
651 | 651 | $timeTaken=microtime(true) - $timeTaken; |
652 | 652 | echo "Global time : ".round($timeTaken)." seconds\n"; |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
89 | 89 | return 1; |
90 | - } |
|
91 | - else |
|
90 | + } else |
|
92 | 91 | { |
93 | 92 | $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG ); |
94 | 93 | return 0; |
@@ -104,7 +103,9 @@ discard block |
||
104 | 103 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
105 | 104 | ', :syntax, :type_enum, :description )'; |
106 | 105 | |
107 | - if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
106 | + if ($this->trapsDB->trapDBType == 'pgsql') { |
|
107 | + $sql .= 'RETURNING id'; |
|
108 | + } |
|
108 | 109 | |
109 | 110 | $sqlQuery=$db_conn->prepare($sql); |
110 | 111 | |
@@ -144,7 +145,9 @@ discard block |
||
144 | 145 | } |
145 | 146 | |
146 | 147 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
147 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
148 | + if ($inserted_id==false) { |
|
149 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
150 | + } |
|
148 | 151 | $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id; |
149 | 152 | break; |
150 | 153 | default: |
@@ -302,7 +305,10 @@ discard block |
||
302 | 305 | $this->reset_oidDesc(); |
303 | 306 | |
304 | 307 | $snmptrans=$this->get_object_details($object, $trapmib); // Get object mib & details |
305 | - if ($snmptrans === null) continue; // object not found |
|
308 | + if ($snmptrans === null) { |
|
309 | + continue; |
|
310 | + } |
|
311 | + // object not found |
|
306 | 312 | |
307 | 313 | $this->parse_object($snmptrans); |
308 | 314 | |
@@ -453,12 +459,14 @@ discard block |
||
453 | 459 | $this->oidDesc['name']=$match[1]; // Name |
454 | 460 | $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
455 | 461 | |
456 | - if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap |
|
462 | + if ($this->oidDesc['type']==0) { |
|
463 | + // object type=0 : check if v1 trap |
|
457 | 464 | { |
458 | 465 | // Check if next is suboid -> in that case is cannot be a trap |
459 | 466 | if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1])) |
460 | 467 | { |
461 | 468 | $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time']; |
469 | + } |
|
462 | 470 | $this->timing['type0_check_num']++; |
463 | 471 | return true; |
464 | 472 | } |
@@ -476,9 +484,11 @@ discard block |
||
476 | 484 | // Force as trap. |
477 | 485 | $this->oidDesc['type']=21; |
478 | 486 | } |
479 | - if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue |
|
487 | + if ($onlyTraps===true && $this->oidDesc['type']!=21) { |
|
488 | + // if only traps and not a trap, continue |
|
480 | 489 | { |
481 | 490 | $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time']; |
491 | + } |
|
482 | 492 | $this->timing['nottrap_num']++; |
483 | 493 | return true; |
484 | 494 | } |
@@ -503,7 +513,9 @@ discard block |
||
503 | 513 | $this->oidDesc['mib']=$match[1]; |
504 | 514 | |
505 | 515 | $numLine=1; |
506 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
516 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) { |
|
517 | + $numLine++; |
|
518 | + } |
|
507 | 519 | if (isset($snmptrans[$numLine])) |
508 | 520 | { |
509 | 521 | $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
@@ -607,7 +619,10 @@ discard block |
||
607 | 619 | $this->timing['num_traps']++; |
608 | 620 | |
609 | 621 | $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO ); |
610 | - if ($display_progress) echo '#'; // echo a # when trap found |
|
622 | + if ($display_progress) { |
|
623 | + echo '#'; |
|
624 | + } |
|
625 | + // echo a # when trap found |
|
611 | 626 | |
612 | 627 | // get trap objects & source MIB |
613 | 628 | |
@@ -624,7 +639,9 @@ discard block |
||
624 | 639 | if (($update==0) && ($check_change===false)) |
625 | 640 | { // Trapd didn't change & force check disabled |
626 | 641 | $this->timing['objects_time'] += microtime(true) - $this->timing['base_time']; |
627 | - if ($display_progress) echo "C"; |
|
642 | + if ($display_progress) { |
|
643 | + echo "C"; |
|
644 | + } |
|
628 | 645 | continue; |
629 | 646 | } |
630 | 647 |
@@ -22,77 +22,77 @@ discard block |
||
22 | 22 | class MibCommand extends Command |
23 | 23 | { |
24 | 24 | /** |
25 | - * Update mib database |
|
26 | - * |
|
27 | - * USAGE |
|
28 | - * |
|
29 | - * icingli trapdirector mib update |
|
30 | - * |
|
31 | - * OPTIONS |
|
32 | - * |
|
33 | - * --pid <file> : run in background with pid in <file> |
|
34 | - * |
|
35 | - * --verb : Set output log to verbose |
|
36 | - * |
|
37 | - * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
38 | - */ |
|
25 | + * Update mib database |
|
26 | + * |
|
27 | + * USAGE |
|
28 | + * |
|
29 | + * icingli trapdirector mib update |
|
30 | + * |
|
31 | + * OPTIONS |
|
32 | + * |
|
33 | + * --pid <file> : run in background with pid in <file> |
|
34 | + * |
|
35 | + * --verb : Set output log to verbose |
|
36 | + * |
|
37 | + * --force-check : force check of all traps & objects for change. (NOT IMPLEMENTED) |
|
38 | + */ |
|
39 | 39 | public function updateAction() |
40 | 40 | { |
41 | - $background = $this->params->get('pid', null); |
|
42 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
45 | - $pid=1; |
|
46 | - if ($background != null) |
|
47 | - { |
|
48 | - $file=@fopen($background,'w'); |
|
49 | - if ($file == false) |
|
50 | - { |
|
51 | - echo 'Error : cannot open pid file '.$background; |
|
52 | - return 1; |
|
53 | - } |
|
54 | - $pid = pcntl_fork(); |
|
55 | - if ($pid == -1) { |
|
56 | - echo 'Error : Cannot fork process'; |
|
57 | - return 1; |
|
58 | - } |
|
59 | - } |
|
60 | - $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
41 | + $background = $this->params->get('pid', null); |
|
42 | + $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | + if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | + $forceCheck=$this->params->has('force-check')?True:False; |
|
45 | + $pid=1; |
|
46 | + if ($background != null) |
|
47 | + { |
|
48 | + $file=@fopen($background,'w'); |
|
49 | + if ($file == false) |
|
50 | + { |
|
51 | + echo 'Error : cannot open pid file '.$background; |
|
52 | + return 1; |
|
53 | + } |
|
54 | + $pid = pcntl_fork(); |
|
55 | + if ($pid == -1) { |
|
56 | + echo 'Error : Cannot fork process'; |
|
57 | + return 1; |
|
58 | + } |
|
59 | + } |
|
60 | + $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
|
61 | 61 | require_once($module->getBaseDir() .'/bin/trap_class.php'); |
62 | 62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
63 | 63 | $trap = new Trap($icingaweb2_etc); |
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | - $trap->setLogging($logLevel,'display'); |
|
66 | + $trap->setLogging($logLevel,'display'); |
|
67 | 67 | } |
68 | 68 | else |
69 | 69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | - if ($pid != 0) |
|
71 | - { |
|
72 | - // father process |
|
73 | - fwrite($file,$pid); |
|
74 | - fclose($file); |
|
75 | - echo "OK : process $pid in bckground"; |
|
76 | - return 0; |
|
77 | - } |
|
78 | - else |
|
79 | - { // son process : close all file descriptors and go to a new session |
|
80 | - fclose($file); |
|
70 | + if ($pid != 0) |
|
71 | + { |
|
72 | + // father process |
|
73 | + fwrite($file,$pid); |
|
74 | + fclose($file); |
|
75 | + echo "OK : process $pid in bckground"; |
|
76 | + return 0; |
|
77 | + } |
|
78 | + else |
|
79 | + { // son process : close all file descriptors and go to a new session |
|
80 | + fclose($file); |
|
81 | 81 | // $sid = posix_setsid(); |
82 | - fclose(STDIN); |
|
83 | - fclose(STDOUT); |
|
84 | - fclose(STDERR); |
|
85 | - try |
|
86 | - { |
|
87 | - $trap->mibClass->update_mib_database(false,$forceCheck); |
|
88 | - } |
|
89 | - catch (Exception $e) |
|
90 | - { |
|
91 | - $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
92 | - } |
|
93 | - unlink($background); |
|
94 | - return 0; |
|
95 | - } |
|
82 | + fclose(STDIN); |
|
83 | + fclose(STDOUT); |
|
84 | + fclose(STDERR); |
|
85 | + try |
|
86 | + { |
|
87 | + $trap->mibClass->update_mib_database(false,$forceCheck); |
|
88 | + } |
|
89 | + catch (Exception $e) |
|
90 | + { |
|
91 | + $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
92 | + } |
|
93 | + unlink($background); |
|
94 | + return 0; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
@@ -110,28 +110,28 @@ discard block |
||
110 | 110 | } |
111 | 111 | if ($pid != 1) |
112 | 112 | { |
113 | - unlink($background); |
|
113 | + unlink($background); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | /** |
117 | - * purge all mib database NOT IMPLEMENTED |
|
118 | - * |
|
119 | - * USAGE |
|
120 | - * |
|
121 | - * icingli trapdirector mib purge --confirm |
|
122 | - * |
|
123 | - * OPTIONS |
|
124 | - * |
|
125 | - * --confirm : needed to execute purge |
|
126 | - */ |
|
117 | + * purge all mib database NOT IMPLEMENTED |
|
118 | + * |
|
119 | + * USAGE |
|
120 | + * |
|
121 | + * icingli trapdirector mib purge --confirm |
|
122 | + * |
|
123 | + * OPTIONS |
|
124 | + * |
|
125 | + * --confirm : needed to execute purge |
|
126 | + */ |
|
127 | 127 | public function purgeAction() |
128 | 128 | { |
129 | 129 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |
130 | 130 | |
131 | 131 | if (!$this->params->has('confirm')) |
132 | 132 | { |
133 | - echo "This needs confirmation with '--confirm'\n"; |
|
134 | - return; |
|
133 | + echo "This needs confirmation with '--confirm'\n"; |
|
134 | + return; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | $Config = new TrapModuleConfig($db_prefix); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
145 | 145 | |
146 | 146 | $query = $db->delete( |
147 | - $Config->getMIBCacheTableName(), |
|
148 | - 'id>0'); |
|
149 | - echo 'Deleted '. $query . " traps and objects\n"; |
|
147 | + $Config->getMIBCacheTableName(), |
|
148 | + 'id>0'); |
|
149 | + echo 'Deleted '. $query . " traps and objects\n"; |
|
150 | 150 | } |
151 | 151 | catch (Exception $e) |
152 | 152 | { |
@@ -38,39 +38,39 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function updateAction() |
40 | 40 | { |
41 | - $background = $this->params->get('pid', null); |
|
42 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
43 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
44 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
41 | + $background=$this->params->get('pid', null); |
|
42 | + $logLevel=$this->params->has('verb') ? 4 : 2; |
|
43 | + if ($this->params->has('force-check')) { echo "Not implemented"; return; } |
|
44 | + $forceCheck=$this->params->has('force-check') ?True:False; |
|
45 | 45 | $pid=1; |
46 | 46 | if ($background != null) |
47 | 47 | { |
48 | - $file=@fopen($background,'w'); |
|
48 | + $file=@fopen($background, 'w'); |
|
49 | 49 | if ($file == false) |
50 | 50 | { |
51 | 51 | echo 'Error : cannot open pid file '.$background; |
52 | 52 | return 1; |
53 | 53 | } |
54 | - $pid = pcntl_fork(); |
|
54 | + $pid=pcntl_fork(); |
|
55 | 55 | if ($pid == -1) { |
56 | 56 | echo 'Error : Cannot fork process'; |
57 | 57 | return 1; |
58 | 58 | } |
59 | 59 | } |
60 | 60 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
61 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
61 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
62 | 62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
63 | - $trap = new Trap($icingaweb2_etc); |
|
63 | + $trap=new Trap($icingaweb2_etc); |
|
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | - $trap->setLogging($logLevel,'display'); |
|
66 | + $trap->setLogging($logLevel, 'display'); |
|
67 | 67 | } |
68 | 68 | else |
69 | 69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | 70 | if ($pid != 0) |
71 | 71 | { |
72 | 72 | // father process |
73 | - fwrite($file,$pid); |
|
73 | + fwrite($file, $pid); |
|
74 | 74 | fclose($file); |
75 | 75 | echo "OK : process $pid in bckground"; |
76 | 76 | return 0; |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | fclose(STDERR); |
85 | 85 | try |
86 | 86 | { |
87 | - $trap->mibClass->update_mib_database(false,$forceCheck); |
|
87 | + $trap->mibClass->update_mib_database(false, $forceCheck); |
|
88 | 88 | } |
89 | 89 | catch (Exception $e) |
90 | 90 | { |
91 | - $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
91 | + $trap->trapLog('Error in updating : '.$e->getMessage(), 2); |
|
92 | 92 | } |
93 | 93 | unlink($background); |
94 | 94 | return 0; |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | { |
101 | 101 | echo "Update main mib database : \n"; |
102 | 102 | echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n"; |
103 | - $trap->mibClass->update_mib_database(true,$forceCheck); |
|
103 | + $trap->mibClass->update_mib_database(true, $forceCheck); |
|
104 | 104 | echo "Done\n"; |
105 | 105 | |
106 | 106 | } |
107 | 107 | catch (Exception $e) |
108 | 108 | { |
109 | - echo 'Error in updating : ' . $e->getMessage(); |
|
109 | + echo 'Error in updating : '.$e->getMessage(); |
|
110 | 110 | } |
111 | 111 | if ($pid != 1) |
112 | 112 | { |
@@ -134,23 +134,23 @@ discard block |
||
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - $Config = new TrapModuleConfig($db_prefix); |
|
137 | + $Config=new TrapModuleConfig($db_prefix); |
|
138 | 138 | |
139 | 139 | try |
140 | 140 | { |
141 | 141 | |
142 | 142 | $dbresource=$this->Config()->get('config', 'database'); |
143 | 143 | echo "DB name : $dbresource\n"; |
144 | - $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
144 | + $db=IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
145 | 145 | |
146 | - $query = $db->delete( |
|
146 | + $query=$db->delete( |
|
147 | 147 | $Config->getMIBCacheTableName(), |
148 | 148 | 'id>0'); |
149 | - echo 'Deleted '. $query . " traps and objects\n"; |
|
149 | + echo 'Deleted '.$query." traps and objects\n"; |
|
150 | 150 | } |
151 | 151 | catch (Exception $e) |
152 | 152 | { |
153 | - echo 'Error in DB : ' . $e->getMessage(); |
|
153 | + echo 'Error in DB : '.$e->getMessage(); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | if ($pid == 1) |
65 | 65 | { |
66 | 66 | $trap->setLogging($logLevel,'display'); |
67 | - } |
|
68 | - else |
|
67 | + } else |
|
69 | 68 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
70 | 69 | if ($pid != 0) |
71 | 70 | { |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | fclose($file); |
75 | 74 | echo "OK : process $pid in bckground"; |
76 | 75 | return 0; |
77 | - } |
|
78 | - else |
|
76 | + } else |
|
79 | 77 | { // son process : close all file descriptors and go to a new session |
80 | 78 | fclose($file); |
81 | 79 | // $sid = posix_setsid(); |
@@ -85,8 +83,7 @@ discard block |
||
85 | 83 | try |
86 | 84 | { |
87 | 85 | $trap->mibClass->update_mib_database(false,$forceCheck); |
88 | - } |
|
89 | - catch (Exception $e) |
|
86 | + } catch (Exception $e) |
|
90 | 87 | { |
91 | 88 | $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
92 | 89 | } |
@@ -103,8 +100,7 @@ discard block |
||
103 | 100 | $trap->mibClass->update_mib_database(true,$forceCheck); |
104 | 101 | echo "Done\n"; |
105 | 102 | |
106 | - } |
|
107 | - catch (Exception $e) |
|
103 | + } catch (Exception $e) |
|
108 | 104 | { |
109 | 105 | echo 'Error in updating : ' . $e->getMessage(); |
110 | 106 | } |
@@ -147,8 +143,7 @@ discard block |
||
147 | 143 | $Config->getMIBCacheTableName(), |
148 | 144 | 'id>0'); |
149 | 145 | echo 'Deleted '. $query . " traps and objects\n"; |
150 | - } |
|
151 | - catch (Exception $e) |
|
146 | + } catch (Exception $e) |
|
152 | 147 | { |
153 | 148 | echo 'Error in DB : ' . $e->getMessage(); |
154 | 149 | } |