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