Passed
Push — master ( 037a61...ff53ce )
by Patrick
02:47 queued 10s
created
library/Trapdirector/TrapsProcess/Mib.php 3 patches
Indentation   +503 added lines, -503 removed lines patch added patch discarded remove patch
@@ -10,569 +10,569 @@
 block discarded – undo
10 10
 class Mib
11 11
 {
12 12
     
13
-    protected $logging; //< logging class
14
-    protected $trapsDB; //< Database class
13
+	protected $logging; //< logging class
14
+	protected $trapsDB; //< Database class
15 15
     
16
-    public $snmptranslate;
17
-    public $snmptranslate_dirs;
16
+	public $snmptranslate;
17
+	public $snmptranslate_dirs;
18 18
     
19
-    private $dbOidAll; //< All oid in database;
20
-    private $dbOidIndex; //< Index of oid in dbOidAll
21
-    private $objectsAll; //< output lines of snmptranslate list
22
-    private $trapObjectsIndex; //< array of traps objects (as OID)
19
+	private $dbOidAll; //< All oid in database;
20
+	private $dbOidIndex; //< Index of oid in dbOidAll
21
+	private $objectsAll; //< output lines of snmptranslate list
22
+	private $trapObjectsIndex; //< array of traps objects (as OID)
23 23
     
24
-    private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
24
+	private $oidDesc=array(); //< $oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL
25 25
     
26
-    // Timing vars for update
27
-    private $timing=array();
26
+	// Timing vars for update
27
+	private $timing=array();
28 28
     
29
-    /**
30
-     * Setup Mib Class
31
-     * @param Logging $logClass : where to log
32
-     * @param Database $dbClass : Database
33
-     */
34
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
35
-    {
36
-        $this->logging=$logClass;
37
-        $this->trapsDB=$dbClass;
38
-        $this->snmptranslate=$snmptrans;
39
-        $this->snmptranslate_dirs=$snmptransdir;
29
+	/**
30
+	 * Setup Mib Class
31
+	 * @param Logging $logClass : where to log
32
+	 * @param Database $dbClass : Database
33
+	 */
34
+	function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
35
+	{
36
+		$this->logging=$logClass;
37
+		$this->trapsDB=$dbClass;
38
+		$this->snmptranslate=$snmptrans;
39
+		$this->snmptranslate_dirs=$snmptransdir;
40 40
 
41
-    }
41
+	}
42 42
     
43 43
     
44
-    /**
45
-     * Update or add an OID to database uses $this->dbOidIndex for mem cache
46
-     * @param string $oid
47
-     * @param string $mib
48
-     * @param string $name
49
-     * @param string $type
50
-     * @param string $textConv
51
-     * @param string $dispHint
52
-     * @param string $syntax
53
-     * @param string $type_enum
54
-     * @param string $description
55
-     * @return number : 0=unchanged, 1 = changed, 2=created
56
-     */
57
-    public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
58
-    {
59
-        $db_conn=$this->trapsDB->db_connect_trap();
60
-        $description=$db_conn->quote($description);
61
-        if (isset($this->dbOidIndex[$oid]))
62
-        {
63
-            if ($this->dbOidIndex[$oid]['key'] == -1)
64
-            { // newly created.
65
-                return 0;
66
-            }
67
-            if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
68
-                $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
69
-                $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
70
-                //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
71
-                //$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
72
-                //$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
73
-                //$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
74
-                //$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
75
-                )
76
-            { // Do update
77
-                $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
78
-                    'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
79
-                    ', syntax = :syntax, type_enum = :type_enum, description = :description '.
80
-                    ' WHERE id= :id';
81
-                $sqlQuery=$db_conn->prepare($sql);
44
+	/**
45
+	 * Update or add an OID to database uses $this->dbOidIndex for mem cache
46
+	 * @param string $oid
47
+	 * @param string $mib
48
+	 * @param string $name
49
+	 * @param string $type
50
+	 * @param string $textConv
51
+	 * @param string $dispHint
52
+	 * @param string $syntax
53
+	 * @param string $type_enum
54
+	 * @param string $description
55
+	 * @return number : 0=unchanged, 1 = changed, 2=created
56
+	 */
57
+	public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
58
+	{
59
+		$db_conn=$this->trapsDB->db_connect_trap();
60
+		$description=$db_conn->quote($description);
61
+		if (isset($this->dbOidIndex[$oid]))
62
+		{
63
+			if ($this->dbOidIndex[$oid]['key'] == -1)
64
+			{ // newly created.
65
+				return 0;
66
+			}
67
+			if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
68
+				$mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
69
+				$type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
70
+				//$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
71
+				//$dispHint != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['display_hint'] ||
72
+				//$syntax != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['syntax'] ||
73
+				//$type_enum != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type_enum'] ||
74
+				//$description != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['description']
75
+				)
76
+			{ // Do update
77
+				$sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
78
+					'name = :name , type = :type , mib = :mib , textual_convention = :tc , display_hint = :display_hint'.
79
+					', syntax = :syntax, type_enum = :type_enum, description = :description '.
80
+					' WHERE id= :id';
81
+				$sqlQuery=$db_conn->prepare($sql);
82 82
                 
83
-                $sqlParam=array(
84
-                    ':name' => $name,
85
-                    ':type' => $type,
86
-                    ':mib' => $mib,
87
-                    ':tc' =>  ($textConv==null)?'null':$textConv ,
88
-                    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
89
-                    ':syntax' => ($syntax==null)?'null':$syntax,
90
-                    ':type_enum' => ($type_enum==null)?'null':$type_enum,
91
-                    ':description' => ($description==null)?'null':$description,
92
-                    ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
93
-                );
83
+				$sqlParam=array(
84
+					':name' => $name,
85
+					':type' => $type,
86
+					':mib' => $mib,
87
+					':tc' =>  ($textConv==null)?'null':$textConv ,
88
+					':display_hint' => ($dispHint==null)?'null':$dispHint ,
89
+					':syntax' => ($syntax==null)?'null':$syntax,
90
+					':type_enum' => ($type_enum==null)?'null':$type_enum,
91
+					':description' => ($description==null)?'null':$description,
92
+					':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
93
+				);
94 94
                 
95
-                if ($sqlQuery->execute($sqlParam) === false) {
96
-                    $this->logging->log('Error in query : ' . $sql,ERROR,'');
97
-                }
98
-                $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
99
-                return 1;
100
-            }
101
-            else
102
-            {
103
-                $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
104
-                return 0;
105
-            }
106
-        }
107
-        // create new OID.
95
+				if ($sqlQuery->execute($sqlParam) === false) {
96
+					$this->logging->log('Error in query : ' . $sql,ERROR,'');
97
+				}
98
+				$this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
99
+				return 1;
100
+			}
101
+			else
102
+			{
103
+				$this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
104
+				return 0;
105
+			}
106
+		}
107
+		// create new OID.
108 108
         
109
-        // Insert data
109
+		// Insert data
110 110
         
111
-        $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
112
-            '(oid, name, type , mib, textual_convention, display_hint '.
113
-            ', syntax, type_enum , description ) ' .
114
-            'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
115
-            ', :syntax, :type_enum, :description )';
111
+		$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
112
+			'(oid, name, type , mib, textual_convention, display_hint '.
113
+			', syntax, type_enum , description ) ' .
114
+			'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
115
+			', :syntax, :type_enum, :description )';
116 116
         
117
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
117
+		if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
118 118
         
119
-        $sqlQuery=$db_conn->prepare($sql);
119
+		$sqlQuery=$db_conn->prepare($sql);
120 120
         
121
-        $sqlParam=array(
122
-            ':oid' => $oid,
123
-            ':name' => $name,
124
-            ':type' => $type,
125
-            ':mib' => $mib,
126
-            ':tc' =>  ($textConv==null)?'null':$textConv ,
127
-            ':display_hint' => ($dispHint==null)?'null':$dispHint ,
128
-            ':syntax' => ($syntax==null)?'null':$syntax,
129
-            ':type_enum' => ($type_enum==null)?'null':$type_enum,
130
-            ':description' => ($description==null)?'null':$description
131
-        );
121
+		$sqlParam=array(
122
+			':oid' => $oid,
123
+			':name' => $name,
124
+			':type' => $type,
125
+			':mib' => $mib,
126
+			':tc' =>  ($textConv==null)?'null':$textConv ,
127
+			':display_hint' => ($dispHint==null)?'null':$dispHint ,
128
+			':syntax' => ($syntax==null)?'null':$syntax,
129
+			':type_enum' => ($type_enum==null)?'null':$type_enum,
130
+			':description' => ($description==null)?'null':$description
131
+		);
132 132
         
133
-        if ($sqlQuery->execute($sqlParam) === false) {
134
-            $this->logging->log('Error in query : ' . $sql,1,'');
135
-        }
133
+		if ($sqlQuery->execute($sqlParam) === false) {
134
+			$this->logging->log('Error in query : ' . $sql,1,'');
135
+		}
136 136
         
137
-        switch ($this->trapsDB->trapDBType)
138
-        {
139
-            case 'pgsql':
140
-                // Get last id to insert oid/values in secondary table
141
-                if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
142
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
143
-                }
144
-                if (! isset($inserted_id_ret['id'])) {
145
-                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
146
-                }
147
-                $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
148
-                break;
149
-            case 'mysql':
150
-                // Get last id to insert oid/values in secondary table
151
-                $sql='SELECT LAST_INSERT_ID();';
152
-                if (($ret_code=$db_conn->query($sql)) === false) {
153
-                    $this->logging->log('Erreur getting id - mysql - ',1,'');
154
-                }
137
+		switch ($this->trapsDB->trapDBType)
138
+		{
139
+			case 'pgsql':
140
+				// Get last id to insert oid/values in secondary table
141
+				if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
142
+					$this->logging->log('Error getting id - pgsql - ',1,'');
143
+				}
144
+				if (! isset($inserted_id_ret['id'])) {
145
+					$this->logging->log('Error getting id - pgsql - empty.',1,'');
146
+				}
147
+				$this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
148
+				break;
149
+			case 'mysql':
150
+				// Get last id to insert oid/values in secondary table
151
+				$sql='SELECT LAST_INSERT_ID();';
152
+				if (($ret_code=$db_conn->query($sql)) === false) {
153
+					$this->logging->log('Erreur getting id - mysql - ',1,'');
154
+				}
155 155
                 
156
-                $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
157
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
158
-                $this->dbOidIndex[$oid]['id']=$inserted_id;
159
-                break;
160
-            default:
161
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
162
-        }
156
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
157
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
158
+				$this->dbOidIndex[$oid]['id']=$inserted_id;
159
+				break;
160
+			default:
161
+				$this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
162
+		}
163 163
         
164
-        // Set as newly created.
165
-        $this->dbOidIndex[$oid]['key']=-1;
166
-        return 2;
167
-    }
164
+		// Set as newly created.
165
+		$this->dbOidIndex[$oid]['key']=-1;
166
+		return 2;
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
-        $dbObjects=null; // cache of objects for trap in db
179
-        $db_conn=$this->trapsDB->db_connect_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
+		$dbObjects=null; // cache of objects for trap in db
179
+		$db_conn=$this->trapsDB->db_connect_trap();
180 180
         
181
-        // Get id of trapmib.
181
+		// Get id of trapmib.
182 182
         
183
-        $trapId = $this->dbOidIndex[$trapOID]['id'];
184
-        if ($check_existing === true)
185
-        {
186
-            // Get all objects
187
-            $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
188
-            $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
189
-            if (($ret_code=$db_conn->query($sql)) === false) {
190
-                $this->logging->log('No result in query : ' . $sql,1,'');
191
-            }
192
-            $dbObjectsRaw=$ret_code->fetchAll();
183
+		$trapId = $this->dbOidIndex[$trapOID]['id'];
184
+		if ($check_existing === true)
185
+		{
186
+			// Get all objects
187
+			$sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
188
+			$this->logging->log('SQL query get all traps: '.$sql,DEBUG );
189
+			if (($ret_code=$db_conn->query($sql)) === false) {
190
+				$this->logging->log('No result in query : ' . $sql,1,'');
191
+			}
192
+			$dbObjectsRaw=$ret_code->fetchAll();
193 193
             
194
-            foreach ($dbObjectsRaw as $val)
195
-            {
196
-                $dbObjects[$val['object_id']]=1;
197
-            }
198
-        }
199
-        foreach ($objects as $object)
200
-        {
201
-            $match=$snmptrans=array();
202
-            $retVal=0;
203
-            $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
204
-            $tmpdesc='';$indesc=false;
194
+			foreach ($dbObjectsRaw as $val)
195
+			{
196
+				$dbObjects[$val['object_id']]=1;
197
+			}
198
+		}
199
+		foreach ($objects as $object)
200
+		{
201
+			$match=$snmptrans=array();
202
+			$retVal=0;
203
+			$objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
204
+			$tmpdesc='';$indesc=false;
205 205
             
206
-            $objMib=$trapmib;
207
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
208
-                ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
209
-            if ($retVal!=0)
210
-            {
211
-                // Maybe not trap mib, search with IR
212
-                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
213
-                    ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
214
-                if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
215
-                { // Not found -> continue with warning
216
-                    $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
217
-                    continue;
218
-                }
219
-                $objMib=$match[1];
206
+			$objMib=$trapmib;
207
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
208
+				' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
209
+			if ($retVal!=0)
210
+			{
211
+				// Maybe not trap mib, search with IR
212
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
213
+					' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
214
+				if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
215
+				{ // Not found -> continue with warning
216
+					$this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
217
+					continue;
218
+				}
219
+				$objMib=$match[1];
220 220
                 
221
-                // Do the snmptranslate again.
222
-                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
223
-                    ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
224
-                if ($retVal!=0) {
225
-                    $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
226
-                }
221
+				// Do the snmptranslate again.
222
+				exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
223
+					' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
224
+				if ($retVal!=0) {
225
+					$this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
226
+				}
227 227
                 
228
-            }
229
-            foreach ($snmptrans as $line)
230
-            {
231
-                if ($indesc===true)
232
-                {
233
-                    $line=preg_replace('/[\t ]+/',' ',$line);
234
-                    if (preg_match('/(.*)"$/', $line,$match))
235
-                    {
236
-                        $objDesc = $tmpdesc . $match[1];
237
-                        $indesc=false;
238
-                    }
239
-                    $tmpdesc.=$line;
240
-                    continue;
241
-                }
242
-                if (preg_match('/^\.[0-9\.]+$/', $line))
243
-                {
244
-                    $objOid=$line;
245
-                    continue;
246
-                }
247
-                if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
248
-                {
249
-                    $objSyntax=$match[1];
250
-                    $objEnum=$match[2];
251
-                    continue;
252
-                }
253
-                if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
254
-                {
255
-                    $objSyntax=$match[1];
256
-                    continue;
257
-                }
258
-                if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
259
-                {
260
-                    $objDispHint=$match[1];
261
-                    continue;
262
-                }
263
-                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
264
-                {
265
-                    $objDesc=$match[1];
266
-                    continue;
267
-                }
268
-                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
269
-                {
270
-                    $tmpdesc=$match[1];
271
-                    $indesc=true;
272
-                    continue;
273
-                }
274
-                if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
275
-                {
276
-                    $objTc=$match[1];
277
-                    continue;
278
-                }
279
-            }
280
-            $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
281
-            //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
282
-            // Update
283
-            $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
228
+			}
229
+			foreach ($snmptrans as $line)
230
+			{
231
+				if ($indesc===true)
232
+				{
233
+					$line=preg_replace('/[\t ]+/',' ',$line);
234
+					if (preg_match('/(.*)"$/', $line,$match))
235
+					{
236
+						$objDesc = $tmpdesc . $match[1];
237
+						$indesc=false;
238
+					}
239
+					$tmpdesc.=$line;
240
+					continue;
241
+				}
242
+				if (preg_match('/^\.[0-9\.]+$/', $line))
243
+				{
244
+					$objOid=$line;
245
+					continue;
246
+				}
247
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
248
+				{
249
+					$objSyntax=$match[1];
250
+					$objEnum=$match[2];
251
+					continue;
252
+				}
253
+				if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
254
+				{
255
+					$objSyntax=$match[1];
256
+					continue;
257
+				}
258
+				if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
259
+				{
260
+					$objDispHint=$match[1];
261
+					continue;
262
+				}
263
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
264
+				{
265
+					$objDesc=$match[1];
266
+					continue;
267
+				}
268
+				if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
269
+				{
270
+					$tmpdesc=$match[1];
271
+					$indesc=true;
272
+					continue;
273
+				}
274
+				if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
275
+				{
276
+					$objTc=$match[1];
277
+					continue;
278
+				}
279
+			}
280
+			$this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
281
+			//echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
282
+			// Update
283
+			$this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
284 284
             
285
-            if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
286
-            {   // if link exists, continue
287
-                $dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
288
-                continue;
289
-            }
290
-            if ($check_existing === true)
291
-            {
292
-                // TODO : check link trap - objects exists, mark them.
293
-            }
294
-            // Associate in object table
295
-            $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
296
-                'values (:trap_id, :object_id)';
297
-            $sqlQuery=$db_conn->prepare($sql);
298
-            $sqlParam=array(
299
-                ':trap_id' => $trapId,
300
-                ':object_id' => $this->dbOidIndex[$objOid]['id'],
301
-            );
285
+			if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
286
+			{   // if link exists, continue
287
+				$dbObjects[$this->dbOidIndex[$objOid]['id']]=2;
288
+				continue;
289
+			}
290
+			if ($check_existing === true)
291
+			{
292
+				// TODO : check link trap - objects exists, mark them.
293
+			}
294
+			// Associate in object table
295
+			$sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache_trap_object (trap_id,object_id) '.
296
+				'values (:trap_id, :object_id)';
297
+			$sqlQuery=$db_conn->prepare($sql);
298
+			$sqlParam=array(
299
+				':trap_id' => $trapId,
300
+				':object_id' => $this->dbOidIndex[$objOid]['id'],
301
+			);
302 302
             
303
-            if ($sqlQuery->execute($sqlParam) === false) {
304
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
305
-            }
306
-        }
307
-        if ($check_existing === true)
308
-        {
309
-            // TODO : remove link trap - objects that wasn't marked.
310
-        }
303
+			if ($sqlQuery->execute($sqlParam) === false) {
304
+				$this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
305
+			}
306
+		}
307
+		if ($check_existing === true)
308
+		{
309
+			// TODO : remove link trap - objects that wasn't marked.
310
+		}
311 311
         
312
-    }
312
+	}
313 313
     
314
-    /**
315
-     * Fills $this->objectsAll with all mibs from snmptranslate
316
-     * @return integer : number of elements 
317
-     */
318
-    private function load_mibs_snmptranslate()
319
-    {
320
-        $retVal=0;
321
-        // Get all mib objects from all mibs
322
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
323
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
324
-        unset($this->objectsAll);
325
-        exec($snmpCommand,$this->objectsAll,$retVal);
326
-        if ($retVal!=0)
327
-        {
328
-            $this->logging->log('error executing snmptranslate',ERROR,'');
329
-        }
330
-        // Count elements to show progress
331
-        $numElements=count($this->objectsAll);
332
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
333
-        return $numElements;
334
-    }
314
+	/**
315
+	 * Fills $this->objectsAll with all mibs from snmptranslate
316
+	 * @return integer : number of elements 
317
+	 */
318
+	private function load_mibs_snmptranslate()
319
+	{
320
+		$retVal=0;
321
+		// Get all mib objects from all mibs
322
+		$snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
323
+		$this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
324
+		unset($this->objectsAll);
325
+		exec($snmpCommand,$this->objectsAll,$retVal);
326
+		if ($retVal!=0)
327
+		{
328
+			$this->logging->log('error executing snmptranslate',ERROR,'');
329
+		}
330
+		// Count elements to show progress
331
+		$numElements=count($this->objectsAll);
332
+		$this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
333
+		return $numElements;
334
+	}
335 335
 
336
-    /**
337
-     * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
338
-     */
339
-    private function load_mibs_from_db()
340
-    {
341
-        // Get all mibs from databse to have a memory index
336
+	/**
337
+	 * load all mib objects db in dbOidAll (raw) and index in dbOidIndex
338
+	 */
339
+	private function load_mibs_from_db()
340
+	{
341
+		// Get all mibs from databse to have a memory index
342 342
         
343
-        $db_conn=$this->trapsDB->db_connect_trap();
343
+		$db_conn=$this->trapsDB->db_connect_trap();
344 344
         
345
-        $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
346
-        $this->logging->log('SQL query : '.$sql,DEBUG );
347
-        if (($ret_code=$db_conn->query($sql)) === false) {
348
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
349
-        }
350
-        $this->dbOidAll=$ret_code->fetchAll();
351
-        $this->dbOidIndex=array();
352
-        // Create the index for db;
353
-        foreach($this->dbOidAll as $key=>$val)
354
-        {
355
-            $this->dbOidIndex[$val['oid']]['key']=$key;
356
-            $this->dbOidIndex[$val['oid']]['id']=$val['id'];
357
-        }
358
-    }
345
+		$sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
346
+		$this->logging->log('SQL query : '.$sql,DEBUG );
347
+		if (($ret_code=$db_conn->query($sql)) === false) {
348
+			$this->logging->log('No result in query : ' . $sql,ERROR,'');
349
+		}
350
+		$this->dbOidAll=$ret_code->fetchAll();
351
+		$this->dbOidIndex=array();
352
+		// Create the index for db;
353
+		foreach($this->dbOidAll as $key=>$val)
354
+		{
355
+			$this->dbOidIndex[$val['oid']]['key']=$key;
356
+			$this->dbOidIndex[$val['oid']]['id']=$val['id'];
357
+		}
358
+	}
359 359
 
360
-    /**
361
-     * Reset all update timers & count to zero
362
-     */
363
-    private function reset_update_timers()
364
-    {
365
-        $this->timing['base_parse_time']=$this->timing['base_check_time']=0;
366
-        $this->timing['type0_check_time']=$this->timing['nottrap_time']=0;
367
-        $this->timing['update_time']=$this->timing['objects_time']=0;
368
-        $this->timing['base_parse_num']=$this->timing['base_check_num']=0;
369
-        $this->timing['type0_check_num']=$this->timing['nottrap_num']=0;
370
-        $this->timing['update_num']=$this->timing['objects_num']=0;
371
-        $this->timing['num_traps']=0;
372
-    }
360
+	/**
361
+	 * Reset all update timers & count to zero
362
+	 */
363
+	private function reset_update_timers()
364
+	{
365
+		$this->timing['base_parse_time']=$this->timing['base_check_time']=0;
366
+		$this->timing['type0_check_time']=$this->timing['nottrap_time']=0;
367
+		$this->timing['update_time']=$this->timing['objects_time']=0;
368
+		$this->timing['base_parse_num']=$this->timing['base_check_num']=0;
369
+		$this->timing['type0_check_num']=$this->timing['nottrap_num']=0;
370
+		$this->timing['update_num']=$this->timing['objects_num']=0;
371
+		$this->timing['num_traps']=0;
372
+	}
373 373
 
374
-    private function detect_trap($curElement,$onlyTraps,&$name,&$type,&$oid)
375
-    {
376
-        // Get oid or pass if not found
377
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
378
-        {
379
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
380
-            $this->timing['base_parse_num'] ++;
381
-            return true;
382
-        }
383
-        $oid=$this->objectsAll[$curElement];
374
+	private function detect_trap($curElement,$onlyTraps,&$name,&$type,&$oid)
375
+	{
376
+		// Get oid or pass if not found
377
+		if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
378
+		{
379
+			$this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
380
+			$this->timing['base_parse_num'] ++;
381
+			return true;
382
+		}
383
+		$oid=$this->objectsAll[$curElement];
384 384
         
385
-        // get next line
386
-        $curElement++;
387
-        $match=$snmptrans=array();
388
-        if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
389
-            $this->objectsAll[$curElement],$match))
390
-        {
391
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
392
-            $this->timing['base_check_num']++;
393
-            return true;
394
-        }
385
+		// get next line
386
+		$curElement++;
387
+		$match=$snmptrans=array();
388
+		if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
389
+			$this->objectsAll[$curElement],$match))
390
+		{
391
+			$this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
392
+			$this->timing['base_check_num']++;
393
+			return true;
394
+		}
395 395
         
396
-        $name=$match[1]; // Name
397
-        $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
396
+		$name=$match[1]; // Name
397
+		$type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
398 398
         
399
-        if ($type==0) // object type=0 : check if v1 trap
400
-        {
401
-            // Check if next is suboid -> in that case is cannot be a trap
402
-            if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
403
-            {
404
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
405
-                $this->timing['type0_check_num']++;
406
-                return true;
407
-            }
408
-            unset($snmptrans);
409
-            $retVal=0;
410
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
-                ' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
412
-            if ($retVal!=0)
413
-            {
414
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
415
-                $this->timing['type0_check_num']++;
416
-                return true;
417
-            }
418
-            //echo "\n v1 trap found : $oid \n";
419
-            // Force as trap.
420
-            $type=21;
421
-        }
422
-        if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
423
-        {
424
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
425
-            $this->timing['nottrap_num']++;
426
-            return true;
427
-        }
428
-        return false;
429
-    }
399
+		if ($type==0) // object type=0 : check if v1 trap
400
+		{
401
+			// Check if next is suboid -> in that case is cannot be a trap
402
+			if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
403
+			{
404
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
405
+				$this->timing['type0_check_num']++;
406
+				return true;
407
+			}
408
+			unset($snmptrans);
409
+			$retVal=0;
410
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
+				' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
412
+			if ($retVal!=0)
413
+			{
414
+				$this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
415
+				$this->timing['type0_check_num']++;
416
+				return true;
417
+			}
418
+			//echo "\n v1 trap found : $oid \n";
419
+			// Force as trap.
420
+			$type=21;
421
+		}
422
+		if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
423
+		{
424
+			$this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
425
+			$this->timing['nottrap_num']++;
426
+			return true;
427
+		}
428
+		return false;
429
+	}
430 430
     
431
-    /**
432
-     * Cache mib in database
433
-     * @param boolean $display_progress : Display progress on standard output
434
-     * @param boolean $check_change : Force check of trap params & objects
435
-     * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
436
-     * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
437
-     */
438
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
439
-    {
440
-        // Global Timing
441
-        $timeTaken = microtime(true);
431
+	/**
432
+	 * Cache mib in database
433
+	 * @param boolean $display_progress : Display progress on standard output
434
+	 * @param boolean $check_change : Force check of trap params & objects
435
+	 * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
436
+	 * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
437
+	 */
438
+	public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
439
+	{
440
+		// Global Timing
441
+		$timeTaken = microtime(true);
442 442
         
443
-        $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
443
+		$numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
444 444
         
445
-        $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
445
+		$this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
446 446
         
447
-        $step=$basestep=$numElements/10; // output display of % done
448
-        $num_step=0;
449
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
447
+		$step=$basestep=$numElements/10; // output display of % done
448
+		$num_step=0;
449
+		$timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
450 450
         
451
-        // Create index for trap objects
452
-        $this->trapObjectsIndex=array();
451
+		// Create index for trap objects
452
+		$this->trapObjectsIndex=array();
453 453
         
454
-        // detailed timing (time_* vars)
455
-        $this->reset_update_timers();
454
+		// detailed timing (time_* vars)
455
+		$this->reset_update_timers();
456 456
         
457
-        for ($curElement=0;$curElement < $numElements;$curElement++)
458
-        {
459
-            $this->timing['base_time']= microtime(true);
460
-            if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
461
-            { // echo a . every 2 sec
462
-                echo '.';
463
-                $timeFiveSec = microtime(true);
464
-            }
465
-            if ($curElement>$step)
466
-            { // display progress
467
-                $num_step++;
468
-                $step+=$basestep;
469
-                if ($display_progress)
470
-                {
471
-                    echo "\n" . ($num_step*10). '% : ';
472
-                }
473
-            }
474
-            $name=$type=$oid='';
475
-            if ($this->detect_trap($curElement,$onlyTraps,$name,$type,$oid)===true)
476
-            {
477
-                continue;
478
-            }
457
+		for ($curElement=0;$curElement < $numElements;$curElement++)
458
+		{
459
+			$this->timing['base_time']= microtime(true);
460
+			if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
461
+			{ // echo a . every 2 sec
462
+				echo '.';
463
+				$timeFiveSec = microtime(true);
464
+			}
465
+			if ($curElement>$step)
466
+			{ // display progress
467
+				$num_step++;
468
+				$step+=$basestep;
469
+				if ($display_progress)
470
+				{
471
+					echo "\n" . ($num_step*10). '% : ';
472
+				}
473
+			}
474
+			$name=$type=$oid='';
475
+			if ($this->detect_trap($curElement,$onlyTraps,$name,$type,$oid)===true)
476
+			{
477
+				continue;
478
+			}
479 479
             
480
-            $this->timing['num_traps']++;
480
+			$this->timing['num_traps']++;
481 481
             
482
-            $this->logging->log('Found trap : '.$name . ' / OID : '.$oid,INFO );
483
-            if ($display_progress) echo '#'; // echo a # when trap found
482
+			$this->logging->log('Found trap : '.$name . ' / OID : '.$oid,INFO );
483
+			if ($display_progress) echo '#'; // echo a # when trap found
484 484
             
485
-            // get trap objects & source MIB
486
-            $retVal=0;
487
-            $match=$snmptrans=array();
488
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
489
-                ' -Td '.$oid,$snmptrans,$retVal);
490
-            if ($retVal!=0)
491
-            {
492
-                $this->logging->log('error executing snmptranslate',ERROR,'');
493
-            }
485
+			// get trap objects & source MIB
486
+			$retVal=0;
487
+			$match=$snmptrans=array();
488
+			exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
489
+				' -Td '.$oid,$snmptrans,$retVal);
490
+			if ($retVal!=0)
491
+			{
492
+				$this->logging->log('error executing snmptranslate',ERROR,'');
493
+			}
494 494
             
495
-            if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
496
-            {
497
-                $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
498
-            }
499
-            $trapMib=$match[1];
495
+			if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
496
+			{
497
+				$this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
498
+			}
499
+			$trapMib=$match[1];
500 500
             
501
-            $numLine=1;$trapDesc='';
502
-            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
503
-            if (isset($snmptrans[$numLine]))
504
-            {
505
-                $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
501
+			$numLine=1;$trapDesc='';
502
+			while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
503
+			if (isset($snmptrans[$numLine]))
504
+			{
505
+				$snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
506 506
                 
507
-                while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
508
-                {
509
-                    $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
510
-                    $numLine++;
511
-                }
512
-                if (isset($snmptrans[$numLine])) {
513
-                    $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
514
-                    $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
515
-                }
507
+				while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
508
+				{
509
+					$trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
510
+					$numLine++;
511
+				}
512
+				if (isset($snmptrans[$numLine])) {
513
+					$trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
514
+					$trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
515
+				}
516 516
                 
517
-            }
518
-            $update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
519
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
520
-            $this->timing['update_num']++;
517
+			}
518
+			$update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
519
+			$this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
520
+			$this->timing['update_num']++;
521 521
             
522
-            $this->timing['base_time']= microtime(true); // Reset to check object time
522
+			$this->timing['base_time']= microtime(true); // Reset to check object time
523 523
             
524
-            if (($update==0) && ($check_change===false))
525
-            { // Trapd didn't change & force check disabled
526
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
527
-                if ($display_progress) echo "C";
528
-                continue;
529
-            }
524
+			if (($update==0) && ($check_change===false))
525
+			{ // Trapd didn't change & force check disabled
526
+				$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
527
+				if ($display_progress) echo "C";
528
+				continue;
529
+			}
530 530
             
531
-            $synt=null;
532
-            foreach ($snmptrans as $line)
533
-            {
534
-                if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
535
-                {
536
-                    $synt=$match[1];
537
-                }
538
-            }
539
-            if ($synt == null)
540
-            {
541
-                //echo "No objects for $trapOID\n";
542
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
543
-                continue;
544
-            }
545
-            //echo "$synt \n";
546
-            $trapObjects=array();
547
-            while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
548
-            {
549
-                array_push($trapObjects,$match[1]);
550
-                $synt=preg_replace('/'.$match[0].'/','',$synt);
551
-            }
531
+			$synt=null;
532
+			foreach ($snmptrans as $line)
533
+			{
534
+				if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
535
+				{
536
+					$synt=$match[1];
537
+				}
538
+			}
539
+			if ($synt == null)
540
+			{
541
+				//echo "No objects for $trapOID\n";
542
+				$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
543
+				continue;
544
+			}
545
+			//echo "$synt \n";
546
+			$trapObjects=array();
547
+			while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
548
+			{
549
+				array_push($trapObjects,$match[1]);
550
+				$synt=preg_replace('/'.$match[0].'/','',$synt);
551
+			}
552 552
             
553
-            $this->trap_objects($oid, $trapMib, $trapObjects, false);
553
+			$this->trap_objects($oid, $trapMib, $trapObjects, false);
554 554
             
555
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
556
-            $this->timing['objects_num']++;
557
-        }
555
+			$this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
556
+			$this->timing['objects_num']++;
557
+		}
558 558
         
559
-        if ($display_progress)
560
-        {
561
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
562
-            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";
563
-            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";
564
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
565
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
566
-        }
559
+		if ($display_progress)
560
+		{
561
+			echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
562
+			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";
563
+			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";
564
+			echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
565
+			echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
566
+		}
567 567
         
568
-        // Timing ends
569
-        $timeTaken=microtime(true) - $timeTaken;
570
-        if ($display_progress)
571
-        {
572
-            echo "Global time : ".round($timeTaken)." seconds\n";
573
-        }
568
+		// Timing ends
569
+		$timeTaken=microtime(true) - $timeTaken;
570
+		if ($display_progress)
571
+		{
572
+			echo "Global time : ".round($timeTaken)." seconds\n";
573
+		}
574 574
         
575
-    }
575
+	}
576 576
     
577 577
     
578 578
 }
579 579
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param Logging $logClass : where to log
32 32
      * @param Database $dbClass : Database
33 33
      */
34
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
34
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
35 35
     {
36 36
         $this->logging=$logClass;
37 37
         $this->trapsDB=$dbClass;
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @param string $description
55 55
      * @return number : 0=unchanged, 1 = changed, 2=created
56 56
      */
57
-    public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL)
57
+    public function update_oid($oid, $mib, $name, $type, $textConv, $dispHint, $syntax, $type_enum, $description=NULL)
58 58
     {
59 59
         $db_conn=$this->trapsDB->db_connect_trap();
60 60
         $description=$db_conn->quote($description);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             { // newly created.
65 65
                 return 0;
66 66
             }
67
-            if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
67
+            if ($name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] ||
68 68
                 $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] ||
69 69
                 $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //||
70 70
                 //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //||
@@ -84,23 +84,23 @@  discard block
 block discarded – undo
84 84
                     ':name' => $name,
85 85
                     ':type' => $type,
86 86
                     ':mib' => $mib,
87
-                    ':tc' =>  ($textConv==null)?'null':$textConv ,
88
-                    ':display_hint' => ($dispHint==null)?'null':$dispHint ,
89
-                    ':syntax' => ($syntax==null)?'null':$syntax,
90
-                    ':type_enum' => ($type_enum==null)?'null':$type_enum,
91
-                    ':description' => ($description==null)?'null':$description,
87
+                    ':tc' =>  ($textConv == null) ? 'null' : $textConv,
88
+                    ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
89
+                    ':syntax' => ($syntax == null) ? 'null' : $syntax,
90
+                    ':type_enum' => ($type_enum == null) ? 'null' : $type_enum,
91
+                    ':description' => ($description == null) ? 'null' : $description,
92 92
                     ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']]
93 93
                 );
94 94
                 
95 95
                 if ($sqlQuery->execute($sqlParam) === false) {
96
-                    $this->logging->log('Error in query : ' . $sql,ERROR,'');
96
+                    $this->logging->log('Error in query : '.$sql, ERROR, '');
97 97
                 }
98
-                $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
98
+                $this->logging->log('Trap updated : '.$name.' / OID : '.$oid, DEBUG);
99 99
                 return 1;
100 100
             }
101 101
             else
102 102
             {
103
-                $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
103
+                $this->logging->log('Trap unchanged : '.$name.' / OID : '.$oid, DEBUG);
104 104
                 return 0;
105 105
             }
106 106
         }
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
         
111 111
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
112 112
             '(oid, name, type , mib, textual_convention, display_hint '.
113
-            ', syntax, type_enum , description ) ' .
113
+            ', syntax, type_enum , description ) '.
114 114
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
115 115
             ', :syntax, :type_enum, :description )';
116 116
         
117
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
117
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
118 118
         
119 119
         $sqlQuery=$db_conn->prepare($sql);
120 120
         
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
             ':name' => $name,
124 124
             ':type' => $type,
125 125
             ':mib' => $mib,
126
-            ':tc' =>  ($textConv==null)?'null':$textConv ,
127
-            ':display_hint' => ($dispHint==null)?'null':$dispHint ,
128
-            ':syntax' => ($syntax==null)?'null':$syntax,
129
-            ':type_enum' => ($type_enum==null)?'null':$type_enum,
130
-            ':description' => ($description==null)?'null':$description
126
+            ':tc' =>  ($textConv == null) ? 'null' : $textConv,
127
+            ':display_hint' => ($dispHint == null) ? 'null' : $dispHint,
128
+            ':syntax' => ($syntax == null) ? 'null' : $syntax,
129
+            ':type_enum' => ($type_enum == null) ? 'null' : $type_enum,
130
+            ':description' => ($description == null) ? 'null' : $description
131 131
         );
132 132
         
133 133
         if ($sqlQuery->execute($sqlParam) === false) {
134
-            $this->logging->log('Error in query : ' . $sql,1,'');
134
+            $this->logging->log('Error in query : '.$sql, 1, '');
135 135
         }
136 136
         
137 137
         switch ($this->trapsDB->trapDBType)
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
             case 'pgsql':
140 140
                 // Get last id to insert oid/values in secondary table
141 141
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
142
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
142
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
143 143
                 }
144
-                if (! isset($inserted_id_ret['id'])) {
145
-                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
144
+                if (!isset($inserted_id_ret['id'])) {
145
+                    $this->logging->log('Error getting id - pgsql - empty.', 1, '');
146 146
                 }
147 147
                 $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id'];
148 148
                 break;
@@ -150,15 +150,15 @@  discard block
 block discarded – undo
150 150
                 // Get last id to insert oid/values in secondary table
151 151
                 $sql='SELECT LAST_INSERT_ID();';
152 152
                 if (($ret_code=$db_conn->query($sql)) === false) {
153
-                    $this->logging->log('Erreur getting id - mysql - ',1,'');
153
+                    $this->logging->log('Erreur getting id - mysql - ', 1, '');
154 154
                 }
155 155
                 
156 156
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
157
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
157
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
158 158
                 $this->dbOidIndex[$oid]['id']=$inserted_id;
159 159
                 break;
160 160
             default:
161
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
161
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, '');
162 162
         }
163 163
         
164 164
         // Set as newly created.
@@ -173,21 +173,21 @@  discard block
 block discarded – undo
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 178
         $dbObjects=null; // cache of objects for trap in db
179 179
         $db_conn=$this->trapsDB->db_connect_trap();
180 180
         
181 181
         // Get id of trapmib.
182 182
         
183
-        $trapId = $this->dbOidIndex[$trapOID]['id'];
183
+        $trapId=$this->dbOidIndex[$trapOID]['id'];
184 184
         if ($check_existing === true)
185 185
         {
186 186
             // Get all objects
187 187
             $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
188
-            $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
188
+            $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
189 189
             if (($ret_code=$db_conn->query($sql)) === false) {
190
-                $this->logging->log('No result in query : ' . $sql,1,'');
190
+                $this->logging->log('No result in query : '.$sql, 1, '');
191 191
             }
192 192
             $dbObjectsRaw=$ret_code->fetchAll();
193 193
             
@@ -201,39 +201,39 @@  discard block
 block discarded – undo
201 201
             $match=$snmptrans=array();
202 202
             $retVal=0;
203 203
             $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL;
204
-            $tmpdesc='';$indesc=false;
204
+            $tmpdesc=''; $indesc=false;
205 205
             
206 206
             $objMib=$trapmib;
207
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
208
-                ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
209
-            if ($retVal!=0)
207
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
208
+                ' -On -Td '.$objMib.'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
209
+            if ($retVal != 0)
210 210
             {
211 211
                 // Maybe not trap mib, search with IR
212
-                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
213
-                    ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
214
-                if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
212
+                exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
213
+                    ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
214
+                if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
215 215
                 { // Not found -> continue with warning
216
-                    $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
216
+                    $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
217 217
                     continue;
218 218
                 }
219 219
                 $objMib=$match[1];
220 220
                 
221 221
                 // Do the snmptranslate again.
222
-                exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
223
-                    ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal);
224
-                if ($retVal!=0) {
225
-                    $this->logging->log('Error finding trap object : '.$objMib.'::'.$object,2,'');
222
+                exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
223
+                    ' -On -Td '.$objMib.'::'.$object, $snmptrans, $retVal);
224
+                if ($retVal != 0) {
225
+                    $this->logging->log('Error finding trap object : '.$objMib.'::'.$object, 2, '');
226 226
                 }
227 227
                 
228 228
             }
229 229
             foreach ($snmptrans as $line)
230 230
             {
231
-                if ($indesc===true)
231
+                if ($indesc === true)
232 232
                 {
233
-                    $line=preg_replace('/[\t ]+/',' ',$line);
234
-                    if (preg_match('/(.*)"$/', $line,$match))
233
+                    $line=preg_replace('/[\t ]+/', ' ', $line);
234
+                    if (preg_match('/(.*)"$/', $line, $match))
235 235
                     {
236
-                        $objDesc = $tmpdesc . $match[1];
236
+                        $objDesc=$tmpdesc.$match[1];
237 237
                         $indesc=false;
238 238
                     }
239 239
                     $tmpdesc.=$line;
@@ -244,43 +244,43 @@  discard block
 block discarded – undo
244 244
                     $objOid=$line;
245 245
                     continue;
246 246
                 }
247
-                if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
247
+                if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
248 248
                 {
249 249
                     $objSyntax=$match[1];
250 250
                     $objEnum=$match[2];
251 251
                     continue;
252 252
                 }
253
-                if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
253
+                if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
254 254
                 {
255 255
                     $objSyntax=$match[1];
256 256
                     continue;
257 257
                 }
258
-                if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
258
+                if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
259 259
                 {
260 260
                     $objDispHint=$match[1];
261 261
                     continue;
262 262
                 }
263
-                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
263
+                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
264 264
                 {
265 265
                     $objDesc=$match[1];
266 266
                     continue;
267 267
                 }
268
-                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
268
+                if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
269 269
                 {
270 270
                     $tmpdesc=$match[1];
271 271
                     $indesc=true;
272 272
                     continue;
273 273
                 }
274
-                if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
274
+                if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
275 275
                 {
276 276
                     $objTc=$match[1];
277 277
                     continue;
278 278
                 }
279 279
             }
280
-            $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",DEBUG );
280
+            $this->logging->log("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc", DEBUG);
281 281
             //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n";
282 282
             // Update
283
-            $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc);
283
+            $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum, $objDesc);
284 284
             
285 285
             if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']]))
286 286
             {   // if link exists, continue
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
             );
302 302
             
303 303
             if ($sqlQuery->execute($sqlParam) === false) {
304
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,'');
304
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$objOid]['id'], 1, '');
305 305
             }
306 306
         }
307 307
         if ($check_existing === true)
@@ -319,17 +319,17 @@  discard block
 block discarded – undo
319 319
     {
320 320
         $retVal=0;
321 321
         // Get all mib objects from all mibs
322
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
323
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
322
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null';
323
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
324 324
         unset($this->objectsAll);
325
-        exec($snmpCommand,$this->objectsAll,$retVal);
326
-        if ($retVal!=0)
325
+        exec($snmpCommand, $this->objectsAll, $retVal);
326
+        if ($retVal != 0)
327 327
         {
328
-            $this->logging->log('error executing snmptranslate',ERROR,'');
328
+            $this->logging->log('error executing snmptranslate', ERROR, '');
329 329
         }
330 330
         // Count elements to show progress
331 331
         $numElements=count($this->objectsAll);
332
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
332
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
333 333
         return $numElements;
334 334
     }
335 335
 
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
         $db_conn=$this->trapsDB->db_connect_trap();
344 344
         
345 345
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
346
-        $this->logging->log('SQL query : '.$sql,DEBUG );
346
+        $this->logging->log('SQL query : '.$sql, DEBUG);
347 347
         if (($ret_code=$db_conn->query($sql)) === false) {
348
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
348
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
349 349
         }
350 350
         $this->dbOidAll=$ret_code->fetchAll();
351 351
         $this->dbOidIndex=array();
352 352
         // Create the index for db;
353
-        foreach($this->dbOidAll as $key=>$val)
353
+        foreach ($this->dbOidAll as $key=>$val)
354 354
         {
355 355
             $this->dbOidIndex[$val['oid']]['key']=$key;
356 356
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -371,13 +371,13 @@  discard block
 block discarded – undo
371 371
         $this->timing['num_traps']=0;
372 372
     }
373 373
 
374
-    private function detect_trap($curElement,$onlyTraps,&$name,&$type,&$oid)
374
+    private function detect_trap($curElement, $onlyTraps, &$name, &$type, &$oid)
375 375
     {
376 376
         // Get oid or pass if not found
377
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
377
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
378 378
         {
379
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
380
-            $this->timing['base_parse_num'] ++;
379
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
380
+            $this->timing['base_parse_num']++;
381 381
             return true;
382 382
         }
383 383
         $oid=$this->objectsAll[$curElement];
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
         $curElement++;
387 387
         $match=$snmptrans=array();
388 388
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
389
-            $this->objectsAll[$curElement],$match))
389
+            $this->objectsAll[$curElement], $match))
390 390
         {
391
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
391
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
392 392
             $this->timing['base_check_num']++;
393 393
             return true;
394 394
         }
@@ -396,22 +396,22 @@  discard block
 block discarded – undo
396 396
         $name=$match[1]; // Name
397 397
         $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
398 398
         
399
-        if ($type==0) // object type=0 : check if v1 trap
399
+        if ($type == 0) // object type=0 : check if v1 trap
400 400
         {
401 401
             // Check if next is suboid -> in that case is cannot be a trap
402
-            if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
402
+            if (preg_match("/^$oid/", $this->objectsAll[$curElement + 1]))
403 403
             {
404
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
404
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
405 405
                 $this->timing['type0_check_num']++;
406 406
                 return true;
407 407
             }
408 408
             unset($snmptrans);
409 409
             $retVal=0;
410
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
-                ' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal);
412
-            if ($retVal!=0)
410
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
411
+                ' -Td '.$oid.' | grep OBJECTS ', $snmptrans, $retVal);
412
+            if ($retVal != 0)
413 413
             {
414
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
414
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
415 415
                 $this->timing['type0_check_num']++;
416 416
                 return true;
417 417
             }
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
             // Force as trap.
420 420
             $type=21;
421 421
         }
422
-        if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
422
+        if ($onlyTraps === true && $type != 21) // if only traps and not a trap, continue
423 423
         {
424
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
424
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
425 425
             $this->timing['nottrap_num']++;
426 426
             return true;
427 427
         }
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
436 436
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
437 437
      */
438
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
438
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
439 439
     {
440 440
         // Global Timing
441
-        $timeTaken = microtime(true);
441
+        $timeTaken=microtime(true);
442 442
         
443 443
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
444 444
         
445 445
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
446 446
         
447
-        $step=$basestep=$numElements/10; // output display of % done
447
+        $step=$basestep=$numElements / 10; // output display of % done
448 448
         $num_step=0;
449
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
449
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
450 450
         
451 451
         // Create index for trap objects
452 452
         $this->trapObjectsIndex=array();
@@ -454,76 +454,76 @@  discard block
 block discarded – undo
454 454
         // detailed timing (time_* vars)
455 455
         $this->reset_update_timers();
456 456
         
457
-        for ($curElement=0;$curElement < $numElements;$curElement++)
457
+        for ($curElement=0; $curElement < $numElements; $curElement++)
458 458
         {
459
-            $this->timing['base_time']= microtime(true);
460
-            if ((microtime(true)-$timeFiveSec) > 2 && $display_progress)
459
+            $this->timing['base_time']=microtime(true);
460
+            if ((microtime(true) - $timeFiveSec) > 2 && $display_progress)
461 461
             { // echo a . every 2 sec
462 462
                 echo '.';
463
-                $timeFiveSec = microtime(true);
463
+                $timeFiveSec=microtime(true);
464 464
             }
465
-            if ($curElement>$step)
465
+            if ($curElement > $step)
466 466
             { // display progress
467 467
                 $num_step++;
468 468
                 $step+=$basestep;
469 469
                 if ($display_progress)
470 470
                 {
471
-                    echo "\n" . ($num_step*10). '% : ';
471
+                    echo "\n".($num_step * 10).'% : ';
472 472
                 }
473 473
             }
474 474
             $name=$type=$oid='';
475
-            if ($this->detect_trap($curElement,$onlyTraps,$name,$type,$oid)===true)
475
+            if ($this->detect_trap($curElement, $onlyTraps, $name, $type, $oid) === true)
476 476
             {
477 477
                 continue;
478 478
             }
479 479
             
480 480
             $this->timing['num_traps']++;
481 481
             
482
-            $this->logging->log('Found trap : '.$name . ' / OID : '.$oid,INFO );
482
+            $this->logging->log('Found trap : '.$name.' / OID : '.$oid, INFO);
483 483
             if ($display_progress) echo '#'; // echo a # when trap found
484 484
             
485 485
             // get trap objects & source MIB
486 486
             $retVal=0;
487 487
             $match=$snmptrans=array();
488
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
489
-                ' -Td '.$oid,$snmptrans,$retVal);
490
-            if ($retVal!=0)
488
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
489
+                ' -Td '.$oid, $snmptrans, $retVal);
490
+            if ($retVal != 0)
491 491
             {
492
-                $this->logging->log('error executing snmptranslate',ERROR,'');
492
+                $this->logging->log('error executing snmptranslate', ERROR, '');
493 493
             }
494 494
             
495
-            if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
495
+            if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
496 496
             {
497
-                $this->logging->log('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,'');
497
+                $this->logging->log('Error getting mib from trap '.$oid.' : '.$snmptrans[0], 1, '');
498 498
             }
499 499
             $trapMib=$match[1];
500 500
             
501
-            $numLine=1;$trapDesc='';
502
-            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
501
+            $numLine=1; $trapDesc='';
502
+            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
503 503
             if (isset($snmptrans[$numLine]))
504 504
             {
505
-                $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
505
+                $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
506 506
                 
507
-                while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
507
+                while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
508 508
                 {
509
-                    $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
509
+                    $trapDesc.=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
510 510
                     $numLine++;
511 511
                 }
512 512
                 if (isset($snmptrans[$numLine])) {
513
-                    $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]);
514
-                    $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc);
513
+                    $trapDesc.=preg_replace('/".*/', '', $snmptrans[$numLine]);
514
+                    $trapDesc=preg_replace('/[\t ]+/', ' ', $trapDesc);
515 515
                 }
516 516
                 
517 517
             }
518
-            $update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc);
519
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
518
+            $update=$this->update_oid($oid, $trapMib, $name, $type, NULL, NULL, NULL, NULL, $trapDesc);
519
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
520 520
             $this->timing['update_num']++;
521 521
             
522
-            $this->timing['base_time']= microtime(true); // Reset to check object time
522
+            $this->timing['base_time']=microtime(true); // Reset to check object time
523 523
             
524
-            if (($update==0) && ($check_change===false))
524
+            if (($update == 0) && ($check_change === false))
525 525
             { // Trapd didn't change & force check disabled
526
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
526
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
527 527
                 if ($display_progress) echo "C";
528 528
                 continue;
529 529
             }
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             $synt=null;
532 532
             foreach ($snmptrans as $line)
533 533
             {
534
-                if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
534
+                if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
535 535
                 {
536 536
                     $synt=$match[1];
537 537
                 }
@@ -539,30 +539,30 @@  discard block
 block discarded – undo
539 539
             if ($synt == null)
540 540
             {
541 541
                 //echo "No objects for $trapOID\n";
542
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
542
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
543 543
                 continue;
544 544
             }
545 545
             //echo "$synt \n";
546 546
             $trapObjects=array();
547
-            while (preg_match('/ *([^ ,]+) *,* */',$synt,$match))
547
+            while (preg_match('/ *([^ ,]+) *,* */', $synt, $match))
548 548
             {
549
-                array_push($trapObjects,$match[1]);
550
-                $synt=preg_replace('/'.$match[0].'/','',$synt);
549
+                array_push($trapObjects, $match[1]);
550
+                $synt=preg_replace('/'.$match[0].'/', '', $synt);
551 551
             }
552 552
             
553 553
             $this->trap_objects($oid, $trapMib, $trapObjects, false);
554 554
             
555
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
555
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
556 556
             $this->timing['objects_num']++;
557 557
         }
558 558
         
559 559
         if ($display_progress)
560 560
         {
561
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
562
-            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";
563
-            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";
564
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
565
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
561
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
562
+            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";
563
+            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";
564
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
565
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
566 566
         }
567 567
         
568 568
         // Timing ends
Please login to merge, or discard this patch.
Braces   +23 added lines, -9 removed lines patch added patch discarded remove patch
@@ -97,8 +97,7 @@  discard block
 block discarded – undo
97 97
                 }
98 98
                 $this->logging->log('Trap updated : '.$name . ' / OID : '.$oid,DEBUG );
99 99
                 return 1;
100
-            }
101
-            else
100
+            } else
102 101
             {
103 102
                 $this->logging->log('Trap unchanged : '.$name . ' / OID : '.$oid,DEBUG );
104 103
                 return 0;
@@ -114,7 +113,9 @@  discard block
 block discarded – undo
114 113
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
115 114
             ', :syntax, :type_enum, :description )';
116 115
         
117
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
116
+        if ($this->trapsDB->trapDBType == 'pgsql') {
117
+        	$sql .= 'RETURNING id';
118
+        }
118 119
         
119 120
         $sqlQuery=$db_conn->prepare($sql);
120 121
         
@@ -154,7 +155,9 @@  discard block
 block discarded – undo
154 155
                 }
155 156
                 
156 157
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
157
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
158
+                if ($inserted_id==false) {
159
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
160
+                }
158 161
                 $this->dbOidIndex[$oid]['id']=$inserted_id;
159 162
                 break;
160 163
             default:
@@ -396,12 +399,14 @@  discard block
 block discarded – undo
396 399
         $name=$match[1]; // Name
397 400
         $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap
398 401
         
399
-        if ($type==0) // object type=0 : check if v1 trap
402
+        if ($type==0) {
403
+        	// object type=0 : check if v1 trap
400 404
         {
401 405
             // Check if next is suboid -> in that case is cannot be a trap
402 406
             if (preg_match("/^$oid/",$this->objectsAll[$curElement+1]))
403 407
             {
404 408
                 $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
409
+        }
405 410
                 $this->timing['type0_check_num']++;
406 411
                 return true;
407 412
             }
@@ -419,9 +424,11 @@  discard block
 block discarded – undo
419 424
             // Force as trap.
420 425
             $type=21;
421 426
         }
422
-        if ($onlyTraps===true && $type!=21) // if only traps and not a trap, continue
427
+        if ($onlyTraps===true && $type!=21) {
428
+        	// if only traps and not a trap, continue
423 429
         {
424 430
             $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
431
+        }
425 432
             $this->timing['nottrap_num']++;
426 433
             return true;
427 434
         }
@@ -480,7 +487,10 @@  discard block
 block discarded – undo
480 487
             $this->timing['num_traps']++;
481 488
             
482 489
             $this->logging->log('Found trap : '.$name . ' / OID : '.$oid,INFO );
483
-            if ($display_progress) echo '#'; // echo a # when trap found
490
+            if ($display_progress) {
491
+            	echo '#';
492
+            }
493
+            // echo a # when trap found
484 494
             
485 495
             // get trap objects & source MIB
486 496
             $retVal=0;
@@ -499,7 +509,9 @@  discard block
 block discarded – undo
499 509
             $trapMib=$match[1];
500 510
             
501 511
             $numLine=1;$trapDesc='';
502
-            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
512
+            while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) {
513
+            	$numLine++;
514
+            }
503 515
             if (isset($snmptrans[$numLine]))
504 516
             {
505 517
                 $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
@@ -524,7 +536,9 @@  discard block
 block discarded – undo
524 536
             if (($update==0) && ($check_change===false))
525 537
             { // Trapd didn't change & force check disabled
526 538
                 $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
527
-                if ($display_progress) echo "C";
539
+                if ($display_progress) {
540
+                	echo "C";
541
+                }
528 542
                 continue;
529 543
             }
530 544
             
Please login to merge, or discard this patch.
bin/trap_class.php 1 patch
Spacing   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
 	protected $api_password='';
35 35
 
36 36
 	// Logs 
37
-	protected $logging;    //< Logging class.
38
-	protected $logSetup;   //< bool true if log was setup in constructor
37
+	protected $logging; //< Logging class.
38
+	protected $logSetup; //< bool true if log was setup in constructor
39 39
 	
40 40
 	// Databases
41 41
 	public $trapsDB; //< Database class
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	// Mib update data
52 52
 	public $mibClass; //< Mib class
53 53
 	
54
-	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
54
+	function __construct($etc_dir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
55 55
 	{
56 56
 	    // Paths of ini files
57 57
 		$this->icingaweb2_etc=$etc_dir;
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
60 60
 
61 61
 		// Setup logging
62
-		$this->logging = new Logging();
62
+		$this->logging=new Logging();
63 63
 		if ($baseLogLevel != null)
64 64
 		{
65
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
65
+		    $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
66 66
 		    $this->logSetup=true;
67 67
 		}
68 68
 		else
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 		$this->logging->log('Loggin started', INFO);
71 71
 
72 72
 		// Get options from ini files
73
-		$trapConfig=parse_ini_file($this->trap_module_config,true);
73
+		$trapConfig=parse_ini_file($this->trap_module_config, true);
74 74
 		if ($trapConfig == false)
75 75
 		{
76
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
76
+		    $this->logging->log("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog');
77 77
 		}
78 78
 		$this->getMainOptions($trapConfig); // Get main options from ini file
79 79
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		$this->getDatabaseOptions(); // Get options in database
82 82
 		if ($this->api_use === true) $this->getAPI(); // Setup API
83 83
 		
84
-		$this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
84
+		$this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
85 85
 		
86 86
 		$this->trap_data=array(
87 87
 			'source_ip'	=> 'unknown',
@@ -103,15 +103,15 @@  discard block
 block discarded – undo
103 103
 	 * @param string $message warning message if not found
104 104
 	 * @return boolean true if found, or false
105 105
 	 */
106
-	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
106
+	protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
107 107
 	{
108 108
 	    if (!isset($option_array[$option_category][$option_name]))
109 109
 	    {
110 110
 	        if ($message === null)
111 111
 	        {
112
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
112
+	            $message='No '.$option_name.' in config file: '.$this->trap_module_config;
113 113
 	        }
114
-	        $this->logging->log($message,$log_level,'syslog');
114
+	        $this->logging->log($message, $log_level, 'syslog');
115 115
 	        return false;
116 116
 	    }
117 117
 	    else
@@ -129,24 +129,24 @@  discard block
 block discarded – undo
129 129
 	{
130 130
 
131 131
 		// Snmptranslate binary path
132
-		$this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
132
+		$this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
133 133
 
134 134
 		// mibs path
135
-		$this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
135
+		$this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
136 136
 
137 137
 		// icinga2cmd path
138
-		$this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
138
+		$this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
139 139
 		
140 140
 		// table prefix
141
-		$this->getOptionIfSet($trapConfig,'config','database_prefix', $this->db_prefix);
141
+		$this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->db_prefix);
142 142
 
143 143
 		// API options
144
-		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->api_hostname))
144
+		if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->api_hostname))
145 145
 		{
146 146
 		    $this->api_use=true;
147
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
148
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
149
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
147
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->api_port);
148
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->api_username);
149
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->api_password);
150 150
 		}
151 151
 	}
152 152
 	
@@ -157,40 +157,40 @@  discard block
 block discarded – undo
157 157
 	protected function setupDatabase($trapConfig)
158 158
 	{
159 159
 	    // Trap database
160
-	    if (!array_key_exists('database',$trapConfig['config']))
160
+	    if (!array_key_exists('database', $trapConfig['config']))
161 161
         {
162
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
162
+            $this->logging->log("No database in config file: ".$this->trap_module_config, ERROR, '');
163 163
             return;
164 164
         }
165 165
         $dbTrapName=$trapConfig['config']['database'];
166
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
166
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
167 167
 	    
168
-	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
168
+	   if (($dbConfig=parse_ini_file($this->icingaweb2_ressources, true)) === false)
169 169
 	    {
170
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
170
+	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources, ERROR, '');
171 171
 	        return;
172 172
 	    }
173
-	    if (!array_key_exists($dbTrapName,$dbConfig))
173
+	    if (!array_key_exists($dbTrapName, $dbConfig))
174 174
 	    {
175
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
175
+	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
176 176
 	        return;
177 177
 	    }
178 178
 	    
179
-	    $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix);
179
+	    $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->db_prefix);
180 180
 	    
181 181
 	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
182 182
         
183 183
 	    // IDO Database
184
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
184
+	    if (!array_key_exists('IDOdatabase', $trapConfig['config']))
185 185
 	    {
186
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
186
+	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config, ERROR, '');
187 187
 	    }
188 188
 	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
189 189
 
190
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
191
-        if (!array_key_exists($dbIdoName,$dbConfig))
190
+	    $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
191
+        if (!array_key_exists($dbIdoName, $dbConfig))
192 192
 	    {
193
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
193
+	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
194 194
 	        return;
195 195
 	    }
196 196
 	    
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 		// Database options
206 206
 		if ($this->logSetup === false) // Only if logging was no setup in constructor
207 207
 		{
208
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
209
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
210
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
208
+    		$this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
209
+    		$this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
210
+    		$this->getDBConfigIfSet('log_file', $this->logging->outputFile);
211 211
 		}
212 212
 	}
213 213
 
214
-	protected function getDBConfigIfSet($element,&$variable)
214
+	protected function getDBConfigIfSet($element, &$variable)
215 215
 	{
216 216
 		$value=$this->getDBConfig($element);
217 217
 		if ($value != 'null') $variable=$value;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		$db_conn=$this->trapsDB->db_connect_trap();
228 228
 		$sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )';
229 229
 		if (($ret_code=$db_conn->query($sql)) === false) {
230
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
230
+			$this->logging->log('No result in query : '.$sql, WARN, '');
231 231
 			return null;
232 232
 		}
233 233
 		$value=$ret_code->fetch();
@@ -244,22 +244,22 @@  discard block
 block discarded – undo
244 244
 	*	@param  string $destination file/syslog/display
245 245
 	*	@return void
246 246
 	**/	
247
-	public function trapLog( $message, $level, $destination ='') // OBSOLETE
247
+	public function trapLog($message, $level, $destination='') // OBSOLETE
248 248
 	{	
249 249
 		// TODO : replace ref with $this->logging->log 
250 250
 	    $this->logging->log($message, $level, $destination);
251 251
 	}
252 252
 	
253
-	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
253
+	public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
254 254
 	{
255
-		$this->logging->setLogging($debugLvl, $outputType,$outputOption);
255
+		$this->logging->setLogging($debugLvl, $outputType, $outputOption);
256 256
 	}
257 257
 	
258 258
 	protected function getAPI()
259 259
 	{
260 260
 	    if ($this->icinga2api == null)
261 261
 	    {
262
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
262
+	        $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port);
263 263
 	    }
264 264
 	    return $this->icinga2api;
265 265
 	}
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		if ($input_stream === false)
279 279
 		{
280 280
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
281
-			$this->logging->log("Error reading stdin !",ERROR,'');
281
+			$this->logging->log("Error reading stdin !", ERROR, '');
282 282
 			return null; // note : exception thrown by logging
283 283
 		}
284 284
 
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
 		if ($this->receivingHost === false)
288 288
 		{
289 289
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
290
-			$this->logging->log("Error reading Host !",ERROR,''); 
290
+			$this->logging->log("Error reading Host !", ERROR, ''); 
291 291
 		}
292 292
 		// line 2 IP:port=>IP:port
293 293
 		$IP=chop(fgets($input_stream));
294 294
 		if ($IP === false)
295 295
 		{
296 296
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
297
-			$this->logging->log("Error reading IP !",ERROR,''); 
297
+			$this->logging->log("Error reading IP !", ERROR, ''); 
298 298
 		}
299 299
 		$matches=array();
300
-		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
301
-		if ($ret_code===0 || $ret_code===false) 
300
+		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
301
+		if ($ret_code === 0 || $ret_code === false) 
302 302
 		{
303 303
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
304
-			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
304
+			$this->logging->log('Error parsing IP : '.$IP, ERROR, '');
305 305
 		} 
306 306
 		else 
307 307
 		{		
@@ -311,34 +311,34 @@  discard block
 block discarded – undo
311 311
 			$this->trap_data['destination_port']=$matches[4];
312 312
 		}
313 313
 
314
-		while (($vars=fgets($input_stream)) !==false)
314
+		while (($vars=fgets($input_stream)) !== false)
315 315
 		{
316 316
 			$vars=chop($vars);
317
-			$ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
318
-			if ($ret_code===0 || $ret_code===false) 
317
+			$ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
318
+			if ($ret_code === 0 || $ret_code === false) 
319 319
 			{
320
-				$this->logging->log('No match on trap data : '.$vars,WARN,'');
320
+				$this->logging->log('No match on trap data : '.$vars, WARN, '');
321 321
 			}
322 322
 			else 
323 323
 			{
324
-			    if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
324
+			    if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
325 325
 				{
326 326
 					$this->trap_data['trap_oid']=$matches[2];				
327 327
 				}
328 328
 				else
329 329
 				{
330
-					$object= new stdClass;
331
-					$object->oid =$matches[1];
332
-					$object->value = $matches[2];
333
-					array_push($this->trap_data_ext,$object);
330
+					$object=new stdClass;
331
+					$object->oid=$matches[1];
332
+					$object->value=$matches[2];
333
+					array_push($this->trap_data_ext, $object);
334 334
 				}
335 335
 			}
336 336
 		}
337 337
 
338
-		if ($this->trap_data['trap_oid']=='unknown') 
338
+		if ($this->trap_data['trap_oid'] == 'unknown') 
339 339
 		{
340
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
341
-			$this->logging->log('no trap oid found',ERROR,'');
340
+		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
341
+			$this->logging->log('no trap oid found', ERROR, '');
342 342
 		} 
343 343
 
344 344
 		// Translate oids.
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 		}
361 361
 		
362 362
 
363
-		$this->trap_data['status']= 'waiting';
363
+		$this->trap_data['status']='waiting';
364 364
 		
365 365
 		return $this->trap_data;
366 366
 	}
@@ -376,40 +376,40 @@  discard block
 block discarded – undo
376 376
 		$db_conn=$this->trapsDB->db_connect_trap();
377 377
 		
378 378
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';';
379
-		$this->logging->log('SQL query : '.$sql,DEBUG );
379
+		$this->logging->log('SQL query : '.$sql, DEBUG);
380 380
 		if (($ret_code=$db_conn->query($sql)) === false) {
381
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
381
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
382 382
 		}
383 383
 		$name=$ret_code->fetch();
384 384
 		if ($name['name'] != null)
385 385
 		{
386
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
386
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
387 387
 		}
388 388
 		
389 389
 		// Also check if it is an instance of OID
390
-		$oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
390
+		$oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
391 391
 		
392 392
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
393
-		$this->logging->log('SQL query : '.$sql,DEBUG );
393
+		$this->logging->log('SQL query : '.$sql, DEBUG);
394 394
 		if (($ret_code=$db_conn->query($sql)) === false) {
395
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
395
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
396 396
 		}
397 397
 		$name=$ret_code->fetch();
398 398
 		if ($name['name'] != null)
399 399
 		{
400
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
400
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
401 401
 		}
402 402
 		
403 403
 		// Try to get oid name from snmptranslate
404
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
404
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
405 405
 		    ' '.$oid);
406 406
 		$matches=array();
407
-		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
408
-		if ($ret_code===0 || $ret_code === false) {
407
+		$ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
408
+		if ($ret_code === 0 || $ret_code === false) {
409 409
 			return NULL;
410 410
 		} else {
411
-			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
412
-			return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
411
+			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
412
+			return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
413 413
 		}	
414 414
 	}
415 415
 	
@@ -420,90 +420,90 @@  discard block
 block discarded – undo
420 420
 	**/
421 421
 	public function eraseOldTraps($days=0)
422 422
 	{
423
-		if ($days==0)
423
+		if ($days == 0)
424 424
 		{
425 425
 			if (($days=$this->getDBConfig('db_remove_days')) == null)
426 426
 			{
427
-				$this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
427
+				$this->logging->log('No days specified & no db value : no tap erase', WARN, '');
428 428
 				return;
429 429
 			}
430 430
 		}
431 431
 		$db_conn=$this->trapsDB->db_connect_trap();
432
-		$daysago = strtotime("-".$days." day");
433
-		$sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
432
+		$daysago=strtotime("-".$days." day");
433
+		$sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
434 434
 		if ($db_conn->query($sql) === false) {
435
-			$this->logging->log('Error erasing traps : '.$sql,ERROR,'');
435
+			$this->logging->log('Error erasing traps : '.$sql, ERROR, '');
436 436
 		}
437
-		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
437
+		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
438 438
 	}
439 439
 
440 440
 	/** Write error to received trap database
441 441
 	 */
442
-	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
442
+	public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
443 443
 	{
444 444
 	    
445 445
 	    $db_conn=$this->trapsDB->db_connect_trap();
446 446
 	    
447 447
 	    // add date time
448
-	    $insert_col ='date_received,status';
449
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
448
+	    $insert_col='date_received,status';
449
+	    $insert_val="'".date("Y-m-d H:i:s")."','error'";
450 450
         
451
-	    if ($sourceIP !=null)
451
+	    if ($sourceIP != null)
452 452
 	    {
453
-	        $insert_col .=',source_ip';
454
-	        $insert_val .=",'". $sourceIP ."'";
453
+	        $insert_col.=',source_ip';
454
+	        $insert_val.=",'".$sourceIP."'";
455 455
 	    }
456
-	    if ($trapoid !=null)
456
+	    if ($trapoid != null)
457 457
 	    {
458
-	        $insert_col .=',trap_oid';
459
-	        $insert_val .=",'". $trapoid ."'";
458
+	        $insert_col.=',trap_oid';
459
+	        $insert_val.=",'".$trapoid."'";
460 460
 	    }
461
-	    $insert_col .=',status_detail';
462
-	    $insert_val .=",'". $message ."'";
461
+	    $insert_col.=',status_detail';
462
+	    $insert_val.=",'".$message."'";
463 463
 	    
464
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
464
+	    $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
465 465
 	    
466 466
 	    switch ($this->trapsDB->trapDBType)
467 467
 	    {
468 468
 	        case 'pgsql':
469
-	            $sql .= ' RETURNING id;';
470
-	            $this->logging->log('sql : '.$sql,INFO);
469
+	            $sql.=' RETURNING id;';
470
+	            $this->logging->log('sql : '.$sql, INFO);
471 471
 	            if (($ret_code=$db_conn->query($sql)) === false) {
472
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
472
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
473 473
 	            }
474
-	            $this->logging->log('SQL insertion OK',INFO );
474
+	            $this->logging->log('SQL insertion OK', INFO);
475 475
 	            // Get last id to insert oid/values in secondary table
476 476
 	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
477 477
 	                
478
-	                $this->logging->log('Erreur recuperation id',1,'');
478
+	                $this->logging->log('Erreur recuperation id', 1, '');
479 479
 	            }
480
-	            if (! isset($inserted_id_ret['id'])) {
481
-	                $this->logging->log('Error getting id',1,'');
480
+	            if (!isset($inserted_id_ret['id'])) {
481
+	                $this->logging->log('Error getting id', 1, '');
482 482
 	            }
483 483
 	            $this->trap_id=$inserted_id_ret['id'];
484 484
 	            break;
485 485
 	        case 'mysql':
486
-	            $sql .= ';';
487
-	            $this->logging->log('sql : '.$sql,INFO );
486
+	            $sql.=';';
487
+	            $this->logging->log('sql : '.$sql, INFO);
488 488
 	            if ($db_conn->query($sql) === false) {
489
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
489
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
490 490
 	            }
491
-	            $this->logging->log('SQL insertion OK',INFO );
491
+	            $this->logging->log('SQL insertion OK', INFO);
492 492
 	            // Get last id to insert oid/values in secondary table
493 493
 	            $sql='SELECT LAST_INSERT_ID();';
494 494
 	            if (($ret_code=$db_conn->query($sql)) === false) {
495
-	                $this->logging->log('Erreur recuperation id',1,'');
495
+	                $this->logging->log('Erreur recuperation id', 1, '');
496 496
 	            }
497 497
 	            
498 498
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
499
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
499
+	            if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
500 500
 	            $this->trap_id=$inserted_id;
501 501
 	            break;
502 502
 	        default:
503
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
503
+	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
504 504
 	    }
505 505
 	    
506
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
506
+	    $this->logging->log('id found: '.$this->trap_id, INFO);    
507 507
 	}
508 508
 	
509 509
 	/** Write trap data to trap database
@@ -520,86 +520,86 @@  discard block
 block discarded – undo
520 520
 		$insert_col='';
521 521
 		$insert_val='';
522 522
 		// add date time
523
-		$this->trap_data['date_received'] = date("Y-m-d H:i:s");
523
+		$this->trap_data['date_received']=date("Y-m-d H:i:s");
524 524
 
525 525
 		$firstcol=1;
526 526
 		foreach ($this->trap_data as $col => $val)
527 527
 		{
528
-			if ($firstcol==0) 
528
+			if ($firstcol == 0) 
529 529
 			{
530
-				$insert_col .=',';
531
-				$insert_val .=',';
530
+				$insert_col.=',';
531
+				$insert_val.=',';
532 532
 			}
533
-			$insert_col .= $col ;
534
-			$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
533
+			$insert_col.=$col;
534
+			$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
535 535
 			$firstcol=0;
536 536
 		}
537 537
 		
538
-		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
538
+		$sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
539 539
 		switch ($this->trapsDB->trapDBType)
540 540
 		{
541 541
 			case 'pgsql': 
542
-				$sql .= ' RETURNING id;';
543
-				$this->logging->log('sql : '.$sql,INFO );
542
+				$sql.=' RETURNING id;';
543
+				$this->logging->log('sql : '.$sql, INFO);
544 544
 				if (($ret_code=$db_conn->query($sql)) === false) {
545
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
545
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
546 546
 				}
547
-				$this->logging->log('SQL insertion OK',INFO );
547
+				$this->logging->log('SQL insertion OK', INFO);
548 548
 				// Get last id to insert oid/values in secondary table
549 549
 				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
550 550
 														   
551
-					$this->logging->log('Erreur recuperation id',ERROR,'');
551
+					$this->logging->log('Erreur recuperation id', ERROR, '');
552 552
 				}
553
-				if (! isset($inserted_id_ret['id'])) {
554
-					$this->logging->log('Error getting id',ERROR,'');
553
+				if (!isset($inserted_id_ret['id'])) {
554
+					$this->logging->log('Error getting id', ERROR, '');
555 555
 				}
556 556
 				$this->trap_id=$inserted_id_ret['id'];
557 557
 			break;
558 558
 			case 'mysql': 
559
-				$sql .= ';';
560
-				$this->logging->log('sql : '.$sql,INFO );
559
+				$sql.=';';
560
+				$this->logging->log('sql : '.$sql, INFO);
561 561
 				if ($db_conn->query($sql) === false) {
562
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
562
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
563 563
 				}
564
-				$this->logging->log('SQL insertion OK',INFO );
564
+				$this->logging->log('SQL insertion OK', INFO);
565 565
 				// Get last id to insert oid/values in secondary table
566 566
 				$sql='SELECT LAST_INSERT_ID();';
567 567
 				if (($ret_code=$db_conn->query($sql)) === false) {
568
-					$this->logging->log('Erreur recuperation id',ERROR,'');
568
+					$this->logging->log('Erreur recuperation id', ERROR, '');
569 569
 				}
570 570
 
571 571
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
572
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
572
+				if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
573 573
 				$this->trap_id=$inserted_id;
574 574
 			break;
575 575
 			default: 
576
-				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
576
+				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
577 577
 		}
578
-		$this->logging->log('id found: '.$this->trap_id,INFO );
578
+		$this->logging->log('id found: '.$this->trap_id, INFO);
579 579
 		
580 580
 		// Fill trap extended data table
581 581
 		foreach ($this->trap_data_ext as $value) {			
582 582
 			// TODO : detect if trap value is encoded and decode it to UTF-8 for database
583 583
 			$firstcol=1;
584
-			$value->trap_id = $this->trap_id;
584
+			$value->trap_id=$this->trap_id;
585 585
 			$insert_col='';
586 586
 			$insert_val='';
587 587
 			foreach ($value as $col => $val)
588 588
 			{
589
-				if ($firstcol==0) 
589
+				if ($firstcol == 0) 
590 590
 				{
591
-					$insert_col .=',';
592
-					$insert_val .=',';
591
+					$insert_col.=',';
592
+					$insert_val.=',';
593 593
 				}
594
-				$insert_col .= $col;
595
-				$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
594
+				$insert_col.=$col;
595
+				$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
596 596
 				$firstcol=0;
597 597
 			}
598 598
 
599
-			$sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';			
599
+			$sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';			
600 600
 
601 601
 			if ($db_conn->query($sql) === false) {
602
-				$this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
602
+				$this->logging->log('Erreur insertion data : '.$sql, WARN, '');
603 603
 			}	
604 604
 		}	
605 605
 	}
@@ -609,14 +609,14 @@  discard block
 block discarded – undo
609 609
 	*	@param $oid string oid in numeric
610 610
 	*	@return mixed : PDO object or false
611 611
 	*/	
612
-	protected function getRules($ip,$oid)
612
+	protected function getRules($ip, $oid)
613 613
 	{
614 614
 		$db_conn=$this->trapsDB->db_connect_trap();
615 615
 		// fetch rules based on IP in rule and OID
616 616
 		$sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' ';
617
-		$this->logging->log('SQL query : '.$sql,DEBUG );
617
+		$this->logging->log('SQL query : '.$sql, DEBUG);
618 618
 		if (($ret_code=$db_conn->query($sql)) === false) {
619
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
619
+			$this->logging->log('No result in query : '.$sql, WARN, '');
620 620
 			return false;
621 621
 		}
622 622
 		$rules_all=$ret_code->fetchAll();
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 		$rule_ret_key=0;
626 626
 		foreach ($rules_all as $key => $rule)
627 627
 		{
628
-			if ($rule['ip4']==$ip || $rule['ip6']==$ip)
628
+			if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
629 629
 			{
630 630
 				$rules_ret[$rule_ret_key]=$rules_all[$key];
631 631
 				//TODO : get host name by API (and check if correct in rule).
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 				continue;
634 634
 			}
635 635
 			// TODO : get hosts IP by API
636
-			if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
636
+			if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
637 637
 			{ // get ips of group members by oid
638 638
 				$db_conn2=$this->trapsDB->db_connect_ido();
639 639
 				$sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -644,15 +644,15 @@  discard block
 block discarded – undo
644 644
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
645 645
 						WHERE o.name1='".$rule['host_group_name']."';";
646 646
 				if (($ret_code2=$db_conn2->query($sql)) === false) {
647
-					$this->logging->log('No result in query : ' . $sql,WARN,'');
647
+					$this->logging->log('No result in query : '.$sql, WARN, '');
648 648
 					continue;
649 649
 				}
650 650
 				$grouphosts=$ret_code2->fetchAll();
651 651
 				//echo "rule grp :\n";print_r($grouphosts);echo "\n";
652
-				foreach ( $grouphosts as $host)
652
+				foreach ($grouphosts as $host)
653 653
 				{
654 654
 					//echo $host['ip4']."\n";
655
-					if ($host['ip4']==$ip || $host['ip6']==$ip)
655
+					if ($host['ip4'] == $ip || $host['ip6'] == $ip)
656 656
 					{
657 657
 						//echo "Rule added \n";
658 658
 						$rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 		$db_conn=$this->trapsDB->db_connect_trap();
676 676
 		$sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
677 677
 		if ($db_conn->query($sql) === false) {
678
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
678
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
679 679
 		}
680 680
 	}
681 681
 	
@@ -687,31 +687,31 @@  discard block
 block discarded – undo
687 687
 	 * @param string $display
688 688
 	 * @returnn bool true is service check was sent without error
689 689
 	*/
690
-	public function serviceCheckResult($host,$service,$state,$display)
690
+	public function serviceCheckResult($host, $service, $state, $display)
691 691
 	{
692 692
 	    if ($this->api_use === false)
693 693
 	    {
694
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
695
-    			$host.';' .$service .';' . $state . ';'.$display;
696
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
694
+    		$send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
695
+    			$host.';'.$service.';'.$state.';'.$display;
696
+    		$this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
697 697
     		
698 698
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
699
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
699
+    		exec('echo "'.$send.'" > '.$this->icinga2cmd);
700 700
     		return true;
701 701
 	    }
702 702
 	    else
703 703
 	    {
704
-	        $api = $this->getAPI();
704
+	        $api=$this->getAPI();
705 705
 	        $api->setCredentials($this->api_username, $this->api_password);
706
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
706
+	        list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display);
707 707
 	        if ($retcode == false)
708 708
 	        {
709
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
709
+	            $this->logging->log("Error sending result : ".$retmessage, WARN, '');
710 710
 	            return false;
711 711
 	        }
712 712
 	        else 
713 713
 	        {
714
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
714
+	            $this->logging->log("Sent result : ".$retmessage, INFO);
715 715
 	            return true;
716 716
 	        }
717 717
 	    }
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	
720 720
 	public function getHostByIP($ip)
721 721
 	{
722
-	    $api = $this->getAPI();
722
+	    $api=$this->getAPI();
723 723
 	    $api->setCredentials($this->api_username, $this->api_password);
724 724
 	    return $api->getHostByIP($ip);
725 725
 	}
@@ -732,32 +732,32 @@  discard block
 block discarded – undo
732 732
 	protected function applyDisplay($display)
733 733
 	{
734 734
 	    $matches=array();
735
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
735
+	    while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
736 736
 		{
737 737
 			$oid=$matches[1];
738 738
 			$found=0;
739
-			foreach($this->trap_data_ext as $val)
739
+			foreach ($this->trap_data_ext as $val)
740 740
 			{
741 741
 				if ($oid == $val->oid)
742 742
 				{
743
-					$val->value=preg_replace('/"/','',$val->value);
743
+					$val->value=preg_replace('/"/', '', $val->value);
744 744
 					$rep=0;
745
-					$display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
746
-					if ($rep==0)
745
+					$display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
746
+					if ($rep == 0)
747 747
 					{
748
-						$this->logging->log("Error in display",WARN,'');
748
+						$this->logging->log("Error in display", WARN, '');
749 749
 						return $display;
750 750
 					}
751 751
 					$found=1;
752 752
 					break;
753 753
 				}
754 754
 			}
755
-			if ($found==0)
755
+			if ($found == 0)
756 756
 			{
757
-				$display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
758
-				if ($rep==0)
757
+				$display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
758
+				if ($rep == 0)
759 759
 				{
760
-					$this->logging->log("Error in display",WARN,'');
760
+					$this->logging->log("Error in display", WARN, '');
761 761
 					return $display;
762 762
 				}				
763 763
 			}
@@ -767,27 +767,27 @@  discard block
 block discarded – undo
767 767
 
768 768
 	
769 769
 	/***************** Eval & tokenizer functions ****************/
770
-	protected function eval_getElement($rule,&$item)
770
+	protected function eval_getElement($rule, &$item)
771 771
 	{
772
-		while ($rule[$item]==' ') $item++;
773
-		if (preg_match('/[0-9\.]/',$rule[$item]))
772
+		while ($rule[$item] == ' ') $item++;
773
+		if (preg_match('/[0-9\.]/', $rule[$item]))
774 774
 		{ // number
775 775
 	
776
-			$item2=$item+1; 
777
-			while (($item2!=strlen($rule)) && (preg_match('/[0-9\.]/',$rule[$item2]))) { $item2++ ;}
778
-			$val=substr($rule,$item,$item2-$item);
776
+			$item2=$item + 1; 
777
+			while (($item2 != strlen($rule)) && (preg_match('/[0-9\.]/', $rule[$item2]))) { $item2++; }
778
+			$val=substr($rule, $item, $item2 - $item);
779 779
 			$item=$item2;
780 780
 			//echo "number ".$val."\n";
781
-			return array(0,$val);
781
+			return array(0, $val);
782 782
 		}
783 783
 		if ($rule[$item] == '"')
784 784
 		{ // string
785 785
 			$item++;
786
-			$item2=$this->eval_getNext($rule,$item,'"');
787
-			$val=substr($rule,$item,$item2-$item-1);
786
+			$item2=$this->eval_getNext($rule, $item, '"');
787
+			$val=substr($rule, $item, $item2 - $item - 1);
788 788
 			$item=$item2;
789 789
 			//echo "string : ".$val."\n";
790
-			return array(1,$val);
790
+			return array(1, $val);
791 791
 		}
792 792
 		
793 793
 		if ($rule[$item] == '(')
@@ -796,14 +796,14 @@  discard block
 block discarded – undo
796 796
 			$start=$item;
797 797
 			$parenthesis_count=0; 
798 798
 			while (($item < strlen($rule)) // Not end of string AND
799
-			      && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded ()
799
+			      && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded ()
800 800
 			{ 
801
-				if ($rule[$item] == '"' )
801
+				if ($rule[$item] == '"')
802 802
 				{ // pass through string
803 803
 					$item++;
804
-					$item=$this->eval_getNext($rule,$item,'"');
804
+					$item=$this->eval_getNext($rule, $item, '"');
805 805
 				} 
806
-				else{
806
+				else {
807 807
 				    if ($rule[$item] == '(')
808 808
 				    {
809 809
 				        $parenthesis_count++;
@@ -816,49 +816,49 @@  discard block
 block discarded – undo
816 816
 				}
817 817
 			}
818 818
 			
819
-			if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);}
820
-			$val=substr($rule,$start,$item-$start);
819
+			if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); }
820
+			$val=substr($rule, $start, $item - $start);
821 821
 			$item++;
822 822
 			$start=0;
823 823
 			//echo "group : ".$val."\n";
824 824
 			// returns evaluation of group as type 2 (boolean)
825
-			return array(2,$this->evaluation($val,$start));		
825
+			return array(2, $this->evaluation($val, $start));		
826 826
 		}
827
-		throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]);
827
+		throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]);
828 828
 		
829 829
 	}
830 830
 	
831
-	protected function eval_getNext($rule,$item,$tok)
831
+	protected function eval_getNext($rule, $item, $tok)
832 832
 	{
833
-		while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;}
834
-		if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item);
835
-		return $item+1;
833
+		while (($rule[$item] != $tok) && ($item < strlen($rule))) { $item++; }
834
+		if ($item == strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item);
835
+		return $item + 1;
836 836
 	}
837 837
 	
838
-	protected function eval_getOper($rule,&$item)
838
+	protected function eval_getOper($rule, &$item)
839 839
 	{
840
-		while ($rule[$item]==' ') $item++;
840
+		while ($rule[$item] == ' ') $item++;
841 841
 		switch ($rule[$item])
842 842
 		{
843 843
 			case '<':
844
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");}
845
-				$item++; return array(0,"<");
844
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); }
845
+				$item++; return array(0, "<");
846 846
 			case '>':
847
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");}
848
-				$item++; return array(0,">");
847
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); }
848
+				$item++; return array(0, ">");
849 849
 			case '=':
850
-				$item++; return array(0,"=");	
850
+				$item++; return array(0, "=");	
851 851
 			case '!':
852
-				if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");}
853
-				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule ." at " .$item);
852
+				if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); }
853
+				throw new Exception("Erreur in expr - incorrect operator '!'  found in ".$rule." at ".$item);
854 854
 			case '~':
855
-				$item++; return array(0,"~");	
855
+				$item++; return array(0, "~");	
856 856
 			case '|':
857
-				$item++; return array(1,"|");	
857
+				$item++; return array(1, "|");	
858 858
 			case '&':
859
-				$item++; return array(1,"&");
859
+				$item++; return array(1, "&");
860 860
 			default	:
861
-				throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item);
861
+				throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item);
862 862
 		}
863 863
 	}
864 864
 	
@@ -870,10 +870,10 @@  discard block
 block discarded – undo
870 870
 	*   comparison int vs strings will return null (error)
871 871
 	*	return : bool or null on error
872 872
 	*/
873
-	public function evaluation($rule,&$item)
873
+	public function evaluation($rule, &$item)
874 874
 	{
875 875
 	    //echo "Evaluation of ".substr($rule,$item)."\n";
876
-		if ( $rule[$item] == '!') // If '!' found, negate next expression.
876
+		if ($rule[$item] == '!') // If '!' found, negate next expression.
877 877
 		{
878 878
 		    $negate=true;
879 879
 		    $item++;
@@ -883,63 +883,63 @@  discard block
 block discarded – undo
883 883
 		    $negate=false;
884 884
 		}
885 885
 		// First element : number, string or ()
886
-		list($type1,$val1) = $this->eval_getElement($rule,$item);
886
+		list($type1, $val1)=$this->eval_getElement($rule, $item);
887 887
 		//echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n";
888 888
 		
889
-		if ($item==strlen($rule)) // If only element, return value, but only boolean
889
+		if ($item == strlen($rule)) // If only element, return value, but only boolean
890 890
 		{
891 891
 		  if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule);
892
-		  if ($negate === true) $val1= ! $val1;
892
+		  if ($negate === true) $val1=!$val1;
893 893
 		  return $val1;
894 894
 		}  
895 895
 		
896 896
 		// Second element : operator
897
-		list($typec,$comp) = $this->eval_getOper($rule,$item);
897
+		list($typec, $comp)=$this->eval_getOper($rule, $item);
898 898
 		//echo "Comp : ".$comp." : ".substr($rule,$item)."\n";
899 899
         
900 900
 		// Third element : number, string or ()
901
-		if ( $rule[$item] == '!') // starts with a ! so evaluate whats next
901
+		if ($rule[$item] == '!') // starts with a ! so evaluate whats next
902 902
 		{
903 903
 		    $item++;
904 904
 		    if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule);
905
-		    $val2= ! $this->evaluation($rule,$item);
905
+		    $val2=!$this->evaluation($rule, $item);
906 906
 		    $type2=2; // result is a boolean 
907 907
 		}
908 908
 		else 
909 909
 		{
910
-		    list($type2,$val2) = $this->eval_getElement($rule,$item);
910
+		    list($type2, $val2)=$this->eval_getElement($rule, $item);
911 911
 		}
912 912
 		//echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n";
913 913
 		
914
-		if ($type1!=$type2)  // cannot compare different types
914
+		if ($type1 != $type2)  // cannot compare different types
915 915
 		{ 
916 916
 		    throw new Exception("Cannot compare string & number : ".$rule);
917 917
 		}
918
-		if ($typec==1 && $type1 !=2) // cannot use & or | with string/number
918
+		if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number
919 919
 		{
920 920
 		    throw new Exception("Cannot use boolean operators with string & number : ".$rule);
921 921
 		}
922 922
 		
923
-		switch ($comp){
924
-			case '<':	$retVal= ($val1 < $val2); break;
925
-			case '<=':	$retVal= ($val1 <= $val2); break;
926
-			case '>':	$retVal= ($val1 > $val2); break;
927
-			case '>=':	$retVal= ($val1 >= $val2); break;
928
-			case '=':	$retVal= ($val1 == $val2); break;
929
-			case '!=':	$retVal= ($val1 != $val2); break;
930
-			case '~':	$retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break;
931
-			case '|':	$retVal= ($val1 || $val2); break;
932
-			case '&':	$retVal= ($val1 && $val2); break;
923
+		switch ($comp) {
924
+			case '<':	$retVal=($val1 < $val2); break;
925
+			case '<=':	$retVal=($val1 <= $val2); break;
926
+			case '>':	$retVal=($val1 > $val2); break;
927
+			case '>=':	$retVal=($val1 >= $val2); break;
928
+			case '=':	$retVal=($val1 == $val2); break;
929
+			case '!=':	$retVal=($val1 != $val2); break;
930
+			case '~':	$retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break;
931
+			case '|':	$retVal=($val1 || $val2); break;
932
+			case '&':	$retVal=($val1 && $val2); break;
933 933
 			default:  throw new Exception("Error in expression - unknown comp : ".$comp);
934 934
 		}
935
-		if ($negate === true) $retVal = ! $retVal; // Inverse result if negate before expression
935
+		if ($negate === true) $retVal=!$retVal; // Inverse result if negate before expression
936 936
 		
937
-		if ($item==strlen($rule)) return $retVal; // End of string : return evaluation
937
+		if ($item == strlen($rule)) return $retVal; // End of string : return evaluation
938 938
 		// check for logical operator :
939 939
 		switch ($rule[$item])
940 940
 		{
941
-			case '|':	$item++; return ($retVal || $this->evaluation($rule,$item) );
942
-			case '&':	$item++; return ($retVal && $this->evaluation($rule,$item) );
941
+			case '|':	$item++; return ($retVal || $this->evaluation($rule, $item));
942
+			case '&':	$item++; return ($retVal && $this->evaluation($rule, $item));
943 943
 			
944 944
 			default:  throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]);
945 945
 		}
@@ -951,17 +951,17 @@  discard block
 block discarded – undo
951 951
 		$rule2='';
952 952
 		while ($item < strlen($rule))
953 953
 		{
954
-			if ($rule[$item]==' ') { $item++; continue; }
955
-			if ($rule[$item]=='"')
954
+			if ($rule[$item] == ' ') { $item++; continue; }
955
+			if ($rule[$item] == '"')
956 956
 			{
957 957
 				$rule2.=$rule[$item];
958 958
 				$item++;
959
-				while (($rule[$item]!='"') && ($item < strlen($rule)))
959
+				while (($rule[$item] != '"') && ($item < strlen($rule)))
960 960
 				{
961 961
 					$rule2.=$rule[$item];
962 962
 					$item++;
963 963
 				}
964
-				if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item);
964
+				if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item);
965 965
 				$rule2.=$rule[$item];
966 966
 				$item++;
967 967
 				continue;
@@ -981,12 +981,12 @@  discard block
 block discarded – undo
981 981
 	
982 982
 	protected function eval_rule($rule)
983 983
 	{
984
-		if ($rule==null || $rule == '') // Empty rule is always true
984
+		if ($rule == null || $rule == '') // Empty rule is always true
985 985
 		{
986 986
 			return true;
987 987
 		}
988 988
 		$matches=array();
989
-		while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1)
989
+		while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1)
990 990
 		{
991 991
 			$oid=$matches[1];
992 992
 			$found=0;
@@ -998,49 +998,49 @@  discard block
 block discarded – undo
998 998
 			// replace * with \* in oid for preg_replace
999 999
 			$oid=preg_replace('/\*/', '\*', $oid);
1000 1000
 			
1001
-			$this->logging->log('OID in rule : '.$oid.' / '.$oidR,DEBUG );
1001
+			$this->logging->log('OID in rule : '.$oid.' / '.$oidR, DEBUG);
1002 1002
 			
1003
-			foreach($this->trap_data_ext as $val)
1003
+			foreach ($this->trap_data_ext as $val)
1004 1004
 			{
1005
-				if (preg_match("/^$oidR$/",$val->oid) == 1)
1005
+				if (preg_match("/^$oidR$/", $val->oid) == 1)
1006 1006
 				{
1007
-					if (!preg_match('/^[0-9]*\.?[0-9]+$/',$val->value))
1007
+					if (!preg_match('/^[0-9]*\.?[0-9]+$/', $val->value))
1008 1008
 					{ // If not a number, change " to ' and put " around it
1009
-						$val->value=preg_replace('/"/',"'",$val->value);
1009
+						$val->value=preg_replace('/"/', "'", $val->value);
1010 1010
 						$val->value='"'.$val->value.'"';
1011 1011
 					}
1012 1012
 					$rep=0;
1013
-					$rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep);
1014
-					if ($rep==0)
1013
+					$rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep);
1014
+					if ($rep == 0)
1015 1015
 					{
1016
-						$this->logging->log("Error in rule_eval",WARN,'');
1016
+						$this->logging->log("Error in rule_eval", WARN, '');
1017 1017
 						return false;
1018 1018
 					}
1019 1019
 					$found=1;
1020 1020
 					break;
1021 1021
 				}
1022 1022
 			}
1023
-			if ($found==0)
1023
+			if ($found == 0)
1024 1024
 			{	// OID not found : throw error
1025 1025
 			    throw new Exception('OID '.$oid.' not found in trap');
1026 1026
 			}
1027 1027
 		}
1028 1028
 		$item=0;
1029 1029
 		$rule=$this->eval_cleanup($rule);
1030
-		$this->logging->log('Rule after clenup: '.$rule,INFO );
1030
+		$this->logging->log('Rule after clenup: '.$rule, INFO);
1031 1031
 		
1032
-		return  $this->evaluation($rule,$item);
1032
+		return  $this->evaluation($rule, $item);
1033 1033
 	}
1034 1034
 	
1035 1035
 	/** Match rules for current trap and do action
1036 1036
 	*/
1037 1037
 	public function applyRules()
1038 1038
 	{
1039
-		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
1039
+		$rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
1040 1040
 		
1041
-		if ($rules===false || count($rules)==0)
1041
+		if ($rules === false || count($rules) == 0)
1042 1042
 		{
1043
-			$this->logging->log('No rules found for this trap',INFO );
1043
+			$this->logging->log('No rules found for this trap', INFO);
1044 1044
 			$this->trap_data['status']='unknown';
1045 1045
 			$this->trap_to_db=true;
1046 1046
 			return;
@@ -1055,58 +1055,58 @@  discard block
 block discarded – undo
1055 1055
 			$service_name=$rule['service_name'];
1056 1056
 			
1057 1057
 			$display=$this->applyDisplay($rule['display']);
1058
-			$this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
1058
+			$this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
1059 1059
 			try
1060 1060
 			{
1061
-				$this->logging->log('Rule to eval : '.$rule['rule'],INFO );
1061
+				$this->logging->log('Rule to eval : '.$rule['rule'], INFO);
1062 1062
 				$evalr=$this->eval_rule($rule['rule']);
1063 1063
 				
1064 1064
 				if ($evalr == true)
1065 1065
 				{
1066 1066
 					//$this->logging->log('rules OOK: '.print_r($rule),INFO );
1067 1067
 					$action=$rule['action_match'];
1068
-					$this->logging->log('action OK : '.$action,INFO );
1068
+					$this->logging->log('action OK : '.$action, INFO);
1069 1069
 					if ($action >= 0)
1070 1070
 					{
1071
-						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
1071
+						if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1072 1072
 						{
1073 1073
 						    $this->trap_action.='Error sending status : check cmd/API';
1074 1074
 						}
1075 1075
 						else
1076 1076
 						{
1077
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
1077
+						    $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1078 1078
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1079 1079
 						}
1080 1080
 					}
1081 1081
 					else
1082 1082
 					{
1083
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1083
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1084 1084
 					}
1085
-					$this->trap_to_db=($action==-2)?false:true;
1085
+					$this->trap_to_db=($action == -2) ?false:true;
1086 1086
 				}
1087 1087
 				else
1088 1088
 				{
1089 1089
 					//$this->logging->log('rules KOO : '.print_r($rule),INFO );
1090 1090
 					
1091 1091
 					$action=$rule['action_nomatch'];
1092
-					$this->logging->log('action NOK : '.$action,INFO );
1092
+					$this->logging->log('action NOK : '.$action, INFO);
1093 1093
 					if ($action >= 0)
1094 1094
 					{
1095
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
1095
+					    if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
1096 1096
 					    {
1097 1097
 					        $this->trap_action.='Error sending status : check cmd/API';
1098 1098
 					    }
1099 1099
 					    else
1100 1100
 					    {
1101
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1101
+    						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1102 1102
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
1103 1103
 					    }
1104 1104
 					}
1105 1105
 					else
1106 1106
 					{
1107
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
1107
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
1108 1108
 					}
1109
-					$this->trap_to_db=($action==-2)?false:true;					
1109
+					$this->trap_to_db=($action == -2) ?false:true;					
1110 1110
 				}
1111 1111
 				// Put name in source_name
1112 1112
 				if (!isset($this->trap_data['source_name']))
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
 				}
1116 1116
 				else
1117 1117
 				{
1118
-					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
1118
+					if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
1119 1119
 					{ // only add if not present
1120 1120
 						$this->trap_data['source_name'].=','.$rule['host_name'];
1121 1121
 					}
@@ -1123,13 +1123,13 @@  discard block
 block discarded – undo
1123 1123
 			}
1124 1124
 			catch (Exception $e) 
1125 1125
 			{ 
1126
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
1126
+			    $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
1127 1127
 			    $this->trap_action.=' ERR : '.$e->getMessage();
1128 1128
 			    $this->trap_data['status']='error';
1129 1129
 			}
1130 1130
 			
1131 1131
 		}
1132
-		if ($this->trap_data['status']=='error')
1132
+		if ($this->trap_data['status'] == 'error')
1133 1133
 		{
1134 1134
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
1135 1135
 		}
@@ -1145,13 +1145,13 @@  discard block
 block discarded – undo
1145 1145
 	public function add_rule_final($time)
1146 1146
 	{
1147 1147
 		$db_conn=$this->trapsDB->db_connect_trap();
1148
-		if ($this->trap_action==null) 
1148
+		if ($this->trap_action == null) 
1149 1149
 		{
1150 1150
 			$this->trap_action='No action';
1151 1151
 		}
1152 1152
 		$sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
1153 1153
 		if ($db_conn->query($sql) === false) {
1154
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
1154
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
1155 1155
 		}
1156 1156
 	}
1157 1157
 	
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
     WHERE s.current_state != 0;";
1175 1175
 		$db_conn=$this->trapsDB->db_connect_ido();
1176 1176
 		if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
1177
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,'');
1177
+			$this->logging->log('No result in query : '.$sql_query, ERROR, '');
1178 1178
 			return 0;
1179 1179
 		}
1180 1180
 		$services=$services_db->fetchAll();
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 		$sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;";
1184 1184
 		$db_conn2=$this->trapsDB->db_connect_trap();
1185 1185
 		if (($rules_db=$db_conn2->query($sql_query)) === false) {
1186
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,'');
1186
+			$this->logging->log('No result in query : '.$sql_query, ERROR, '');
1187 1187
 			return 0;
1188 1188
 		}
1189 1189
 		$rules=$rules_db->fetchAll();
@@ -1199,13 +1199,13 @@  discard block
 block discarded – undo
1199 1199
 					$service['host_name'] == $rule['host_name'] &&
1200 1200
 					($service['last_check'] + $rule['revert_ok']) < $now)
1201 1201
 				{
1202
-					$this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1202
+					$this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1203 1203
 					$numreset++;
1204 1204
 				}
1205 1205
 			}
1206 1206
 		}
1207 1207
 		echo "\n";
1208
-		echo $numreset . " service(s) reset to OK\n";
1208
+		echo $numreset." service(s) reset to OK\n";
1209 1209
 		return 0;
1210 1210
 		
1211 1211
 	}
Please login to merge, or discard this patch.