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