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