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