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