Passed
Push — master ( f4c14e...6af608 )
by Patrick
02:05
created
library/Trapdirector/Tables/HandlerTableList.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	
32 32
 	// Filters 
33 33
 	
34
-    protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
34
+	protected $filter;
35
+	protected $enforcedFilters = array();
36
+	protected $searchColumns = array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 		$this->doTranslate=true;
46 46
 	}
47 47
 	// ******************  Render table in html  
48
-    public function __toString()
49
-    {
50
-        return $this->render();
51
-    }
48
+	public function __toString()
49
+	{
50
+		return $this->render();
51
+	}
52 52
 	
53 53
 	public function render()
54 54
 	{
@@ -153,30 +153,30 @@  discard block
 block discarded – undo
153 153
 
154 154
 	}
155 155
 
156
-    public function count()
157
-    {
158
-        //$db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
160
-        $query->reset('order')->columns(array('COUNT(*)'));
161
-        $this->applyFiltersToQuery($query);
156
+	public function count()
157
+	{
158
+		//$db = $this->connection()->getConnection();
159
+		$query = clone($this->getBaseQuery());
160
+		$query->reset('order')->columns(array('COUNT(*)'));
161
+		$this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165 165
 		$query = $db->select()->from(
166
-            $this->moduleConfig->getTrapRuleName(),
167
-            array('COUNT(*)')
168
-        );
166
+			$this->moduleConfig->getTrapRuleName(),
167
+			array('COUNT(*)')
168
+		);
169 169
 		
170
-        return $db->fetchOne($query);
171
-    }
170
+		return $db->fetchOne($query);
171
+	}
172 172
 	
173
-    public function getPaginator()
174
-    {
175
-        $paginator = new Paginator();
176
-        $paginator->setQuery($this);
173
+	public function getPaginator()
174
+	{
175
+		$paginator = new Paginator();
176
+		$paginator->setQuery($this);
177 177
 
178
-        return $paginator;
179
-    }
178
+		return $paginator;
179
+	}
180 180
 	
181 181
 	// ****************** DB connection and query
182 182
 	
@@ -186,63 +186,63 @@  discard block
 block discarded – undo
186 186
 		
187 187
 		$query = $this->getBaseQuery();
188 188
 		
189
-       if ($this->hasLimit() || $this->hasOffset()) {
190
-            $query->limit($this->getLimit(), $this->getOffset());
191
-        }		
189
+	   if ($this->hasLimit() || $this->hasOffset()) {
190
+			$query->limit($this->getLimit(), $this->getOffset());
191
+		}		
192 192
 		
193 193
 		return $db->fetchAll($query);
194 194
 	}
195 195
 	 
196
-    public function getBaseQuery()
197
-    {
196
+	public function getBaseQuery()
197
+	{
198 198
 		$db=$this->db();
199 199
 		
200 200
 		$query = $db->select()->from(
201
-            $this->moduleConfig->getTrapRuleName(),
202
-            $this->moduleConfig->getHandlerListDisplayColumns()
203
-        )->order('host_name DESC,trap_oid DESC');
201
+			$this->moduleConfig->getTrapRuleName(),
202
+			$this->moduleConfig->getHandlerListDisplayColumns()
203
+		)->order('host_name DESC,trap_oid DESC');
204 204
 
205
-        return $query;
206
-    }	 
205
+		return $query;
206
+	}	 
207 207
 	
208 208
 	// ****************** Filters
209 209
 
210
-    protected function getSearchColumns()
211
-    {
212
-        return $this->getColumns();
213
-    }
210
+	protected function getSearchColumns()
211
+	{
212
+		return $this->getColumns();
213
+	}
214 214
 	
215 215
 	public function getColumns()
216 216
 	{
217 217
 		return $this->moduleConfig->getHandlerListDisplayColumns();
218 218
 	}
219 219
 
220
-    public function setFilter($filter)
221
-    {
222
-        $this->filter = $filter;
223
-        return $this;
224
-    }
220
+	public function setFilter($filter)
221
+	{
222
+		$this->filter = $filter;
223
+		return $this;
224
+	}
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227
-    {
228
-        $filterEditor = Widget::create('filterEditor')
229
-            ->setColumns(array_keys($this->getColumns()))
230
-            ->setSearchColumns(array_keys($this->getSearchColumns()))
231
-            ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
-            ->ignoreParams('page')
233
-            ->handleRequest($request);
227
+	{
228
+		$filterEditor = Widget::create('filterEditor')
229
+			->setColumns(array_keys($this->getColumns()))
230
+			->setSearchColumns(array_keys($this->getSearchColumns()))
231
+			->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232
+			->ignoreParams('page')
233
+			->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
236
-        $this->setFilter($filter);
235
+		$filter = $filterEditor->getFilter();
236
+		$this->setFilter($filter);
237 237
 
238
-        return $filterEditor;
239
-    }
238
+		return $filterEditor;
239
+	}
240 240
 	
241
-    protected function applyFiltersToQuery($query)
242
-    {
241
+	protected function applyFiltersToQuery($query)
242
+	{
243 243
 		// TODO : implement
244 244
 		
245
-        /*$filter = null;
245
+		/*$filter = null;
246 246
         $enforced = $this->enforcedFilters;
247 247
         if ($this->filter && ! $this->filter->isEmpty()) {
248 248
             $filter = $this->filter;
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
         }
258 258
 		*/
259 259
 		
260
-        return $query;
261
-    }	
260
+		return $query;
261
+	}	
262 262
 
263 263
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	// Filters 
33 33
 	
34 34
     protected $filter;
35
-    protected $enforcedFilters = array();
36
-    protected $searchColumns = array();
35
+    protected $enforcedFilters=array();
36
+    protected $searchColumns=array();
37 37
 	
38 38
 	protected function getTitles() {
39 39
 		return $this->moduleConfig->getHandlerListTitles();
@@ -53,34 +53,34 @@  discard block
 block discarded – undo
53 53
 	public function render()
54 54
 	{
55 55
 		$data=$this->getTable();
56
-		$view = $this->getView();
57
-		$this->columnCount = count($this->getTitles());
56
+		$view=$this->getView();
57
+		$this->columnCount=count($this->getTitles());
58 58
 		$this->lastDay=null;
59 59
 		// Table start
60
-		$htm  = '<table class="simple common-table table-row-selectable">';
60
+		$htm='<table class="simple common-table table-row-selectable">';
61 61
 		
62 62
 		// Titles
63
-		$htm .= "<thead>\n  <tr>\n";
64
-		$titles = $this->getTitles();
63
+		$htm.="<thead>\n  <tr>\n";
64
+		$titles=$this->getTitles();
65 65
 		foreach ($titles as $title) 
66 66
 		{
67
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
67
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
68 68
 		}
69
-		$htm .= "  </tr>\n</thead>\n";
69
+		$htm.="  </tr>\n</thead>\n";
70 70
 		
71 71
 		// Rows
72
-		$htm .= "<tbody>\n";
72
+		$htm.="<tbody>\n";
73 73
 		
74 74
 		foreach ($data as $row) 
75 75
 		{
76
-			$firstCol = true;
76
+			$firstCol=true;
77 77
 			// Put date header
78 78
 			//$htm .= $this->renderDayIfNew($row->timestamp);
79 79
 			
80 80
 			
81 81
 			// Render row
82
-			$htm .= '<tr '.' >';
83
-			foreach ( $titles as $rowkey => $title) 
82
+			$htm.='<tr '.' >';
83
+			foreach ($titles as $rowkey => $title) 
84 84
 			{
85 85
 				// Check missing value
86 86
 				if (property_exists($row, $rowkey)) 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 						break;
94 94
 						case 'trap_oid': // try to traslate oids.
95 95
 						
96
-							if ($this->doTranslate===true)
96
+							if ($this->doTranslate === true)
97 97
 							{
98 98
 								$oidName=$this->MIB->translateOID($row->$rowkey);
99 99
 								if (isset($oidName['name']))
@@ -102,52 +102,52 @@  discard block
 block discarded – undo
102 102
 								}
103 103
 								else
104 104
 								{
105
-									$val = $row->$rowkey;
105
+									$val=$row->$rowkey;
106 106
 								}								
107 107
 							}
108 108
 							else
109 109
 							{
110
-								$val = $row->$rowkey;
110
+								$val=$row->$rowkey;
111 111
 							}
112 112
 						break;
113 113
 						case 'host_name': // switch to hostgroup if name is null
114 114
 							if ($row->$rowkey == null)
115 115
 							{
116
-								$val = $row->host_group_name;
116
+								$val=$row->host_group_name;
117 117
 							}
118 118
 							else
119 119
 							{
120
-								$val = $row->$rowkey;
120
+								$val=$row->$rowkey;
121 121
 							}
122 122
 						break;
123 123
 						default:
124
-							$val = $row->$rowkey;
124
+							$val=$row->$rowkey;
125 125
 					}
126
-					if ($rowkey == 'trap_oid' && $this->doTranslate===true)
126
+					if ($rowkey == 'trap_oid' && $this->doTranslate === true)
127 127
 					{					
128 128
 							
129 129
 					}
130 130
 				} else {
131
-					$val = '-';
131
+					$val='-';
132 132
 				}
133 133
 				if ($firstCol === true) { // Put link in first column for trap detail.
134
-					$htm .= '<td>' 
134
+					$htm.='<td>' 
135 135
 							. $view->qlink(
136 136
 									$view->escape($val),  
137 137
 									Url::fromPath(
138
-										$this->moduleConfig->urlPath() . '/handler/add', 
138
+										$this->moduleConfig->urlPath().'/handler/add', 
139 139
 										array('ruleid' => $row->id)
140 140
 									)
141 141
 							)
142 142
 							. '</td>';
143 143
 				} else {
144
-					$htm .= '<td>' . $view->escape($val) . '</td>';
144
+					$htm.='<td>'.$view->escape($val).'</td>';
145 145
 				}
146 146
 				$firstCol=false;
147 147
 			}
148
-			$htm .= "<tr>\n";
148
+			$htm.="<tr>\n";
149 149
 		}
150
-		$htm .= "</tbody></table>\n";
150
+		$htm.="</tbody></table>\n";
151 151
 		//$htm .= "Filter : " . $this->filter."<br>\n";
152 152
 		return $htm;
153 153
 
@@ -156,13 +156,13 @@  discard block
 block discarded – undo
156 156
     public function count()
157 157
     {
158 158
         //$db = $this->connection()->getConnection();
159
-        $query = clone($this->getBaseQuery());
159
+        $query=clone($this->getBaseQuery());
160 160
         $query->reset('order')->columns(array('COUNT(*)'));
161 161
         $this->applyFiltersToQuery($query);
162 162
 
163 163
 		$db=$this->db();
164 164
 		
165
-		$query = $db->select()->from(
165
+		$query=$db->select()->from(
166 166
             $this->moduleConfig->getTrapRuleName(),
167 167
             array('COUNT(*)')
168 168
         );
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	
173 173
     public function getPaginator()
174 174
     {
175
-        $paginator = new Paginator();
175
+        $paginator=new Paginator();
176 176
         $paginator->setQuery($this);
177 177
 
178 178
         return $paginator;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	{
185 185
 		$db=$this->db();
186 186
 		
187
-		$query = $this->getBaseQuery();
187
+		$query=$this->getBaseQuery();
188 188
 		
189 189
        if ($this->hasLimit() || $this->hasOffset()) {
190 190
             $query->limit($this->getLimit(), $this->getOffset());
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     {
198 198
 		$db=$this->db();
199 199
 		
200
-		$query = $db->select()->from(
200
+		$query=$db->select()->from(
201 201
             $this->moduleConfig->getTrapRuleName(),
202 202
             $this->moduleConfig->getHandlerListDisplayColumns()
203 203
         )->order('host_name DESC,trap_oid DESC');
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 
220 220
     public function setFilter($filter)
221 221
     {
222
-        $this->filter = $filter;
222
+        $this->filter=$filter;
223 223
         return $this;
224 224
     }
225 225
 	
226 226
 	public function getFilterEditor(Request $request)
227 227
     {
228
-        $filterEditor = Widget::create('filterEditor')
228
+        $filterEditor=Widget::create('filterEditor')
229 229
             ->setColumns(array_keys($this->getColumns()))
230 230
             ->setSearchColumns(array_keys($this->getSearchColumns()))
231 231
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
232 232
             ->ignoreParams('page')
233 233
             ->handleRequest($request);
234 234
 
235
-        $filter = $filterEditor->getFilter();
235
+        $filter=$filterEditor->getFilter();
236 236
         $this->setFilter($filter);
237 237
 
238 238
         return $filterEditor;
Please login to merge, or discard this patch.
library/Trapdirector/Icinga2Api.php 2 patches
Indentation   +330 added lines, -330 removed lines patch added patch discarded remove patch
@@ -8,361 +8,361 @@
 block discarded – undo
8 8
 
9 9
 class Icinga2API 
10 10
 {
11
-    protected $version = 'v1';      //< icinga2 api version
11
+	protected $version = 'v1';      //< icinga2 api version
12 12
     
13
-    protected $host;                //< icinga2 host name or IP
14
-    protected $port;                //< icinga2 api port
13
+	protected $host;                //< icinga2 host name or IP
14
+	protected $port;                //< icinga2 api port
15 15
     
16
-    protected $user;                //< user name
17
-    protected $pass;                //< user password
18
-    protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
-    protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
16
+	protected $user;                //< user name
17
+	protected $pass;                //< user password
18
+	protected $usercert;            //< user key for certificate auth (NOT IMPLEMENTED)
19
+	protected $authmethod='pass';   //< Authentication : 'pass' or 'cert'
20 20
 
21
-    protected $curl;
22
-    // http://php.net/manual/de/function.json-last-error.php#119985
23
-    protected $errorReference = [
24
-        JSON_ERROR_NONE => 'No error has occurred.',
25
-        JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
-        JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
-        JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
-        JSON_ERROR_SYNTAX => 'Syntax error.',
29
-        JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
-        JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
-        JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
-        JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
-    ];
34
-    const JSON_UNKNOWN_ERROR = 'Unknown error.';
21
+	protected $curl;
22
+	// http://php.net/manual/de/function.json-last-error.php#119985
23
+	protected $errorReference = [
24
+		JSON_ERROR_NONE => 'No error has occurred.',
25
+		JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.',
26
+		JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.',
27
+		JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.',
28
+		JSON_ERROR_SYNTAX => 'Syntax error.',
29
+		JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.',
30
+		JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.',
31
+		JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.',
32
+		JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.',
33
+	];
34
+	const JSON_UNKNOWN_ERROR = 'Unknown error.';
35 35
     
36
-    /**
37
-     * Creates Icinga2API object
38
-     * 
39
-     * @param string $host host name or IP
40
-     * @param number $port API port
41
-     */
42
-    public function __construct($host, $port = 5665)
43
-    {
44
-        $this->host=$host;
45
-        $this->port=$port;
46
-    }
47
-    /**
48
-     * Set user & pass
49
-     * @param string $user
50
-     * @param string $pass
51
-     */
52
-    public function setCredentials($user,$pass)
53
-    {
54
-        $this->user=$user;
55
-        $this->pass=$pass;
56
-        $this->authmethod='pass';
57
-    }
36
+	/**
37
+	 * Creates Icinga2API object
38
+	 * 
39
+	 * @param string $host host name or IP
40
+	 * @param number $port API port
41
+	 */
42
+	public function __construct($host, $port = 5665)
43
+	{
44
+		$this->host=$host;
45
+		$this->port=$port;
46
+	}
47
+	/**
48
+	 * Set user & pass
49
+	 * @param string $user
50
+	 * @param string $pass
51
+	 */
52
+	public function setCredentials($user,$pass)
53
+	{
54
+		$this->user=$user;
55
+		$this->pass=$pass;
56
+		$this->authmethod='pass';
57
+	}
58 58
     
59
-    /**
60
-     * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
-     * @param string $user
62
-     * @param string $usercert
63
-     */
64
-    public function setCredentialskey($user,$usercert)
65
-    {
66
-        $this->user=$user;
67
-        $this->usercert=$usercert;
68
-        $this->authmethod='cert';
69
-        throw new RuntimeException('Certificate auth not implemented');
70
-    }
59
+	/**
60
+	 * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException)
61
+	 * @param string $user
62
+	 * @param string $usercert
63
+	 */
64
+	public function setCredentialskey($user,$usercert)
65
+	{
66
+		$this->user=$user;
67
+		$this->usercert=$usercert;
68
+		$this->authmethod='cert';
69
+		throw new RuntimeException('Certificate auth not implemented');
70
+	}
71 71
 
72
-    public function test(array $permissions)
73
-    {
74
-       try
75
-        {
76
-            $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
79
-        {
80
-            return array(true, 'Error with API : '.$e->getMessage());
81
-        }
82
-        //var_dump($result);
83
-        $permOk=1;
84
-        $permMissing='';
85
-        if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
86
-        {
72
+	public function test(array $permissions)
73
+	{
74
+	   try
75
+		{
76
+			$result=$this->request('GET', "", NULL, NULL);
77
+		} 
78
+		catch (Exception $e)
79
+		{
80
+			return array(true, 'Error with API : '.$e->getMessage());
81
+		}
82
+		//var_dump($result);
83
+		$permOk=1;
84
+		$permMissing='';
85
+		if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions'))
86
+		{
87 87
             
88
-            foreach ( $permissions as $mustPermission)
89
-            {
90
-                $curPermOK=0;
91
-                foreach ( $result->results[0]->permissions as $curPermission)
92
-                {
93
-                    $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
94
-                    if (preg_match('#'.$curPermission.'#',$mustPermission))
95
-                    {
96
-                        $curPermOK=1;
97
-                        break;
98
-                    }
99
-                }
100
-                if ($curPermOK == 0)
101
-                {
102
-                    $permOk=0;
103
-                    $permMissing=$mustPermission;
104
-                    break;
105
-                }
106
-            }
107
-            if ($permOk == 0)
108
-            {
109
-                return array(true,'API connection OK, but missing permission : '.$permMissing);
110
-            }
111
-            return array(false,'API connection OK');
88
+			foreach ( $permissions as $mustPermission)
89
+			{
90
+				$curPermOK=0;
91
+				foreach ( $result->results[0]->permissions as $curPermission)
92
+				{
93
+					$curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp
94
+					if (preg_match('#'.$curPermission.'#',$mustPermission))
95
+					{
96
+						$curPermOK=1;
97
+						break;
98
+					}
99
+				}
100
+				if ($curPermOK == 0)
101
+				{
102
+					$permOk=0;
103
+					$permMissing=$mustPermission;
104
+					break;
105
+				}
106
+			}
107
+			if ($permOk == 0)
108
+			{
109
+				return array(true,'API connection OK, but missing permission : '.$permMissing);
110
+			}
111
+			return array(false,'API connection OK');
112 112
             
113
-        }
114
-        return array(true,'API connection OK, but cannot get permissions');
115
-    }
113
+		}
114
+		return array(true,'API connection OK, but cannot get permissions');
115
+	}
116 116
     
117 117
     
118
-    protected function url($url) {
119
-        return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
120
-    }
118
+	protected function url($url) {
119
+		return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url);
120
+	}
121 121
     
122
-    /**
123
-     * Create or return curl ressource
124
-     * @throws Exception
125
-     * @return resource
126
-     */
127
-    protected function curl() {
128
-        if ($this->curl === null) {
129
-            $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
130
-            if (!$this->curl) {
131
-                throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
132
-            }
133
-        }
134
-        return $this->curl;
135
-    }
122
+	/**
123
+	 * Create or return curl ressource
124
+	 * @throws Exception
125
+	 * @return resource
126
+	 */
127
+	protected function curl() {
128
+		if ($this->curl === null) {
129
+			$this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port));
130
+			if (!$this->curl) {
131
+				throw new Exception('CURL INIT ERROR: ' . curl_error($this->curl));
132
+			}
133
+		}
134
+		return $this->curl;
135
+	}
136 136
 
137
-    /**
138
-     * Send a passive service check
139
-     * @param string $host : host name 
140
-     * @param string $service : service name
141
-     * @param int $state : state of service
142
-     * @param string $display : service passive check output
143
-     * @return array (status = true (oK) or false (nok), string message)
144
-     */
145
-    public function serviceCheckResult($host,$service,$state,$display)
146
-    {
147
-        //Send a POST request to the URL endpoint /v1/actions/process-check-result
148
-        //actions/process-check-result?service=example.localdomain!passive-ping6
149
-        $url='actions/process-check-result';
150
-        $body=array(
151
-            "filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
152
-            'type'          => 'Service',
153
-            "exit_status"   => $state,
154
-            "plugin_output" => $display
155
-        );
156
-        try 
157
-        {
158
-            $result=$this->request('POST', $url, null, $body);
159
-        } catch (Exception $e) 
160
-        {
161
-            return array(false, $e->getMessage());
162
-        }
163
-        if (property_exists($result,'error') )
164
-        {
165
-            if (property_exists($result,'status'))
166
-            {
167
-                $message=$result->status;
168
-            }
169
-            else 
170
-            {
171
-                $message="Unkown status";
172
-            }
173
-            return array(false , 'Ret code ' .$result->error.' : '.$message);
174
-        }
175
-        if (property_exists($result, 'results'))
176
-        {
177
-            if (isset($result->results[0]))
178
-            {
179
-                return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
180
-            }
181
-            else
182
-            {
183
-                return array(false,'Service not found');
184
-            }
137
+	/**
138
+	 * Send a passive service check
139
+	 * @param string $host : host name 
140
+	 * @param string $service : service name
141
+	 * @param int $state : state of service
142
+	 * @param string $display : service passive check output
143
+	 * @return array (status = true (oK) or false (nok), string message)
144
+	 */
145
+	public function serviceCheckResult($host,$service,$state,$display)
146
+	{
147
+		//Send a POST request to the URL endpoint /v1/actions/process-check-result
148
+		//actions/process-check-result?service=example.localdomain!passive-ping6
149
+		$url='actions/process-check-result';
150
+		$body=array(
151
+			"filter"        => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"',
152
+			'type'          => 'Service',
153
+			"exit_status"   => $state,
154
+			"plugin_output" => $display
155
+		);
156
+		try 
157
+		{
158
+			$result=$this->request('POST', $url, null, $body);
159
+		} catch (Exception $e) 
160
+		{
161
+			return array(false, $e->getMessage());
162
+		}
163
+		if (property_exists($result,'error') )
164
+		{
165
+			if (property_exists($result,'status'))
166
+			{
167
+				$message=$result->status;
168
+			}
169
+			else 
170
+			{
171
+				$message="Unkown status";
172
+			}
173
+			return array(false , 'Ret code ' .$result->error.' : '.$message);
174
+		}
175
+		if (property_exists($result, 'results'))
176
+		{
177
+			if (isset($result->results[0]))
178
+			{
179
+				return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
180
+			}
181
+			else
182
+			{
183
+				return array(false,'Service not found');
184
+			}
185 185
             
186
-        }
187
-        return array(false,'Unkown result, open issue with this : '.print_r($result,true));
188
-    }
186
+		}
187
+		return array(false,'Unkown result, open issue with this : '.print_r($result,true));
188
+	}
189 189
  
190
-    /**
191
-     * return array of host by IP (4 or 6)
192
-     * @param string $ip
193
-     * @throws Exception
194
-     * @return array objects : array('__name','name','display_name')
195
-     */
196
-    public function getHostByIP($ip) 
197
-    {
198
-        /*
190
+	/**
191
+	 * return array of host by IP (4 or 6)
192
+	 * @param string $ip
193
+	 * @throws Exception
194
+	 * @return array objects : array('__name','name','display_name')
195
+	 */
196
+	public function getHostByIP($ip) 
197
+	{
198
+		/*
199 199
          *  curl -k -s -u  trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' 
200 200
          *  -d '{"filter":"host.group==\"test_trap\"","attrs": ["address" ,"address6"]}'
201 201
             
202 202
             {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]}
203 203
          */
204 204
         
205
-        $url='objects/hosts';
206
-        $body=array(
207
-            "filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
208
-            "attrs"         => array('__name','name','display_name')
209
-        );
210
-        try
211
-        {
212
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
213
-        } catch (Exception $e)
214
-        {
215
-            throw new Exception($e->getMessage());
216
-        }
205
+		$url='objects/hosts';
206
+		$body=array(
207
+			"filter"        => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"',
208
+			"attrs"         => array('__name','name','display_name')
209
+		);
210
+		try
211
+		{
212
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
213
+		} catch (Exception $e)
214
+		{
215
+			throw new Exception($e->getMessage());
216
+		}
217 217
         
218
-        if (property_exists($result,'error') )
219
-        {
220
-            if (property_exists($result,'status'))
221
-            {
222
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
223
-            }
224
-            else
225
-            {
226
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
227
-            }
228
-        }
229
-        if (property_exists($result, 'results'))
230
-        {
231
-            $numHost=0;
232
-            $hostArray=array();
233
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
234
-            {
235
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
236
-                $numHost++;
237
-            }
238
-            return $hostArray;            
239
-        }
240
-        throw new Exception('Unkown result');
241
-    }
218
+		if (property_exists($result,'error') )
219
+		{
220
+			if (property_exists($result,'status'))
221
+			{
222
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
223
+			}
224
+			else
225
+			{
226
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
227
+			}
228
+		}
229
+		if (property_exists($result, 'results'))
230
+		{
231
+			$numHost=0;
232
+			$hostArray=array();
233
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
234
+			{
235
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
236
+				$numHost++;
237
+			}
238
+			return $hostArray;            
239
+		}
240
+		throw new Exception('Unkown result');
241
+	}
242 242
 
243
-    /**
244
-     * Get all host and IP from hostgroup
245
-     * @param string $hostGroup
246
-     * @throws Exception
247
-     * @return array : attributes : address, address6, name
248
-     */
249
-    public function getHostsIPByHostGroup($hostGroup)
250
-    {        
251
-        $url='objects/hosts';
252
-        $body=array(
253
-            "filter"        => '\"'.$hostGroup.'\" in host.groups',
254
-            "attrs"         => array('address','address','name')
255
-        );
256
-        try
257
-        {
258
-            $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
259
-        } catch (Exception $e)
260
-        {
261
-            throw new Exception($e->getMessage());
262
-        }
243
+	/**
244
+	 * Get all host and IP from hostgroup
245
+	 * @param string $hostGroup
246
+	 * @throws Exception
247
+	 * @return array : attributes : address, address6, name
248
+	 */
249
+	public function getHostsIPByHostGroup($hostGroup)
250
+	{        
251
+		$url='objects/hosts';
252
+		$body=array(
253
+			"filter"        => '\"'.$hostGroup.'\" in host.groups',
254
+			"attrs"         => array('address','address','name')
255
+		);
256
+		try
257
+		{
258
+			$result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body);
259
+		} catch (Exception $e)
260
+		{
261
+			throw new Exception($e->getMessage());
262
+		}
263 263
         
264
-        if (property_exists($result,'error') )
265
-        {
266
-            if (property_exists($result,'status'))
267
-            {
268
-                throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
269
-            }
270
-            else
271
-            {
272
-                throw new Exception('Ret code ' .$result->error.' : Unkown status');
273
-            }
274
-        }
275
-        if (property_exists($result, 'results'))
276
-        {
277
-            $numHost=0;
278
-            $hostArray=array();
279
-            while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
280
-            {
281
-                $hostArray[$numHost] = $result->results[$numHost]->attrs;
282
-                $hostArray[$numHost]->name = $result->results[$numHost]->name;
283
-                $numHost++;
284
-            }
285
-            return $hostArray;
286
-        }
287
-        throw new Exception('Unkown result');
288
-    }
264
+		if (property_exists($result,'error') )
265
+		{
266
+			if (property_exists($result,'status'))
267
+			{
268
+				throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
269
+			}
270
+			else
271
+			{
272
+				throw new Exception('Ret code ' .$result->error.' : Unkown status');
273
+			}
274
+		}
275
+		if (property_exists($result, 'results'))
276
+		{
277
+			$numHost=0;
278
+			$hostArray=array();
279
+			while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs'))
280
+			{
281
+				$hostArray[$numHost] = $result->results[$numHost]->attrs;
282
+				$hostArray[$numHost]->name = $result->results[$numHost]->name;
283
+				$numHost++;
284
+			}
285
+			return $hostArray;
286
+		}
287
+		throw new Exception('Unkown result');
288
+	}
289 289
     
290
-    /**
291
-     * Send request to API
292
-     * @param string $method get/post/...
293
-     * @param string $url (after /v1/ )
294
-     * @param array $headers
295
-     * @param array $body 
296
-     * @throws Exception
297
-     * @return array
298
-     */
299
-    public function request($method, $url, $headers, $body) {
300
-        $auth = sprintf('%s:%s', $this->user, $this->pass);
301
-        $curlHeaders = array("Accept: application/json");
302
-        if ($body !== null) {
303
-            $body = json_encode($body);
304
-            array_push($curlHeaders, 'Content-Type: application/json');
305
-            //array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
306
-        }
307
-        //var_dump($body);
308
-        //var_dump($this->url($url));
309
-        if ($headers !== null) {
310
-            $curlFinalHeaders = array_merge($curlHeaders, $headers);
311
-        } else 
312
-        {
313
-            $curlFinalHeaders=$curlHeaders;
314
-        }
315
-        $curl = $this->curl();
316
-        $opts = array(
317
-            CURLOPT_URL		=> $this->url($url),
318
-            CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
319
-            CURLOPT_USERPWD		=> $auth,
320
-            CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
321
-            CURLOPT_RETURNTRANSFER 	=> true,
322
-            CURLOPT_CONNECTTIMEOUT 	=> 10,
323
-            CURLOPT_SSL_VERIFYHOST 	=> false,
324
-            CURLOPT_SSL_VERIFYPEER 	=> false,
325
-        );
326
-        if ($body !== null) {
327
-            $opts[CURLOPT_POSTFIELDS] = $body;
328
-        }
329
-        curl_setopt_array($curl, $opts);
330
-        $res = curl_exec($curl);
331
-        if ($res === false) {
332
-            throw new Exception('CURL ERROR: ' . curl_error($curl));
333
-        }
334
-        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
335
-        if ($statusCode === 401) {
336
-            throw new Exception('Unable to authenticate, please check your API credentials');
337
-        }
338
-        return $this->fromJsonResult($res);
339
-    }
290
+	/**
291
+	 * Send request to API
292
+	 * @param string $method get/post/...
293
+	 * @param string $url (after /v1/ )
294
+	 * @param array $headers
295
+	 * @param array $body 
296
+	 * @throws Exception
297
+	 * @return array
298
+	 */
299
+	public function request($method, $url, $headers, $body) {
300
+		$auth = sprintf('%s:%s', $this->user, $this->pass);
301
+		$curlHeaders = array("Accept: application/json");
302
+		if ($body !== null) {
303
+			$body = json_encode($body);
304
+			array_push($curlHeaders, 'Content-Type: application/json');
305
+			//array_push($curlHeaders, 'X-HTTP-Method-Override: GET');
306
+		}
307
+		//var_dump($body);
308
+		//var_dump($this->url($url));
309
+		if ($headers !== null) {
310
+			$curlFinalHeaders = array_merge($curlHeaders, $headers);
311
+		} else 
312
+		{
313
+			$curlFinalHeaders=$curlHeaders;
314
+		}
315
+		$curl = $this->curl();
316
+		$opts = array(
317
+			CURLOPT_URL		=> $this->url($url),
318
+			CURLOPT_HTTPHEADER 	=> $curlFinalHeaders,
319
+			CURLOPT_USERPWD		=> $auth,
320
+			CURLOPT_CUSTOMREQUEST	=> strtoupper($method),
321
+			CURLOPT_RETURNTRANSFER 	=> true,
322
+			CURLOPT_CONNECTTIMEOUT 	=> 10,
323
+			CURLOPT_SSL_VERIFYHOST 	=> false,
324
+			CURLOPT_SSL_VERIFYPEER 	=> false,
325
+		);
326
+		if ($body !== null) {
327
+			$opts[CURLOPT_POSTFIELDS] = $body;
328
+		}
329
+		curl_setopt_array($curl, $opts);
330
+		$res = curl_exec($curl);
331
+		if ($res === false) {
332
+			throw new Exception('CURL ERROR: ' . curl_error($curl));
333
+		}
334
+		$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
335
+		if ($statusCode === 401) {
336
+			throw new Exception('Unable to authenticate, please check your API credentials');
337
+		}
338
+		return $this->fromJsonResult($res);
339
+	}
340 340
     
341
-    /**
342
-     * 
343
-     * @param string $json json encoded 
344
-     * @throws Exception
345
-     * @return array json decoded
346
-     */
347
-    protected function fromJsonResult($json) {
348
-        $result = @json_decode($json);
349
-        //var_dump($json);
350
-        if ($result === null) {
351
-            throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
352
-        }
353
-        return $result;
354
-    }
341
+	/**
342
+	 * 
343
+	 * @param string $json json encoded 
344
+	 * @throws Exception
345
+	 * @return array json decoded
346
+	 */
347
+	protected function fromJsonResult($json) {
348
+		$result = @json_decode($json);
349
+		//var_dump($json);
350
+		if ($result === null) {
351
+			throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error()));
352
+		}
353
+		return $result;
354
+	}
355 355
     
356
-    /**
357
-     * Return text error no json error
358
-     * @param string $errorCode
359
-     * @return string
360
-     */
361
-    protected function getLastJsonErrorMessage($errorCode) {
362
-        if (!array_key_exists($errorCode, $this->errorReference)) {
363
-            return self::JSON_UNKNOWN_ERROR;
364
-        }
365
-        return $this->errorReference[$errorCode];
366
-    }
356
+	/**
357
+	 * Return text error no json error
358
+	 * @param string $errorCode
359
+	 * @return string
360
+	 */
361
+	protected function getLastJsonErrorMessage($errorCode) {
362
+		if (!array_key_exists($errorCode, $this->errorReference)) {
363
+			return self::JSON_UNKNOWN_ERROR;
364
+		}
365
+		return $this->errorReference[$errorCode];
366
+	}
367 367
 }
368 368
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@  discard block
 block discarded – undo
74 74
        try
75 75
         {
76 76
             $result=$this->request('GET', "", NULL, NULL);
77
-        } 
78
-        catch (Exception $e)
77
+        } catch (Exception $e)
79 78
         {
80 79
             return array(true, 'Error with API : '.$e->getMessage());
81 80
         }
@@ -165,8 +164,7 @@  discard block
 block discarded – undo
165 164
             if (property_exists($result,'status'))
166 165
             {
167 166
                 $message=$result->status;
168
-            }
169
-            else 
167
+            } else 
170 168
             {
171 169
                 $message="Unkown status";
172 170
             }
@@ -177,8 +175,7 @@  discard block
 block discarded – undo
177 175
             if (isset($result->results[0]))
178 176
             {
179 177
                 return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status);
180
-            }
181
-            else
178
+            } else
182 179
             {
183 180
                 return array(false,'Service not found');
184 181
             }
@@ -220,8 +217,7 @@  discard block
 block discarded – undo
220 217
             if (property_exists($result,'status'))
221 218
             {
222 219
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
223
-            }
224
-            else
220
+            } else
225 221
             {
226 222
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
227 223
             }
@@ -266,8 +262,7 @@  discard block
 block discarded – undo
266 262
             if (property_exists($result,'status'))
267 263
             {
268 264
                 throw new Exception('Ret code ' .$result->error.' : ' . $result->status);
269
-            }
270
-            else
265
+            } else
271 266
             {
272 267
                 throw new Exception('Ret code ' .$result->error.' : Unkown status');
273 268
             }
Please login to merge, or discard this patch.
bin/trap_class.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	
59 59
 	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
60 60
 	{
61
-	    // Paths of ini files
61
+		// Paths of ini files
62 62
 		$this->icingaweb2_etc=$etc_dir;
63 63
 		$this->trap_module_config=$this->icingaweb2_etc."/modules/trapdirector/config.ini";		
64 64
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
@@ -67,18 +67,18 @@  discard block
 block discarded – undo
67 67
 		$this->logging = new Logging();
68 68
 		if ($baseLogLevel != null)
69 69
 		{
70
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
71
-		    $this->logSetup=true;
70
+			$this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
71
+			$this->logSetup=true;
72 72
 		}
73 73
 		else
74
-		    $this->logSetup=false;
74
+			$this->logSetup=false;
75 75
 		$this->logging->log('Loggin started', INFO);
76 76
 
77 77
 		// Get options from ini files
78 78
 		$trapConfig=parse_ini_file($this->trap_module_config,true);
79 79
 		if ($trapConfig == false)
80 80
 		{
81
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
81
+			$this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
82 82
 		}
83 83
 		$this->getMainOptions($trapConfig); // Get main options from ini file
84 84
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -112,26 +112,26 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
114 114
 	{
115
-	    if (!isset($option_array[$option_category][$option_name]))
116
-	    {
117
-	        if ($message === null)
118
-	        {
119
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
120
-	        }
121
-	        $this->logging->log($message,$log_level,'syslog');
122
-	        return false;
123
-	    }
124
-	    else
125
-	    {
126
-	        $option_var=$option_array[$option_category][$option_name];
127
-	        return true;
128
-	    }
115
+		if (!isset($option_array[$option_category][$option_name]))
116
+		{
117
+			if ($message === null)
118
+			{
119
+				$message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
120
+			}
121
+			$this->logging->log($message,$log_level,'syslog');
122
+			return false;
123
+		}
124
+		else
125
+		{
126
+			$option_var=$option_array[$option_category][$option_name];
127
+			return true;
128
+		}
129 129
 	}
130 130
 	
131 131
 	/** 
132 132
 	 * Get options from ini file
133 133
 	 * @param array $trap_config : ini file array
134
-	*/
134
+	 */
135 135
 	protected function getMainOptions($trapConfig)
136 136
 	{
137 137
 
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 		// API options
151 151
 		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->api_hostname))
152 152
 		{
153
-		    $this->api_use=true;
154
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
155
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
156
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
153
+			$this->api_use=true;
154
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
155
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
156
+			$this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
157 157
 		}
158 158
 	}
159 159
 	
@@ -163,45 +163,45 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	protected function setupDatabase($trapConfig)
165 165
 	{
166
-	    // Trap database
167
-	    if (!array_key_exists('database',$trapConfig['config']))
168
-        {
169
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
170
-            return;
171
-        }
172
-        $dbTrapName=$trapConfig['config']['database'];
173
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
166
+		// Trap database
167
+		if (!array_key_exists('database',$trapConfig['config']))
168
+		{
169
+			$this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
170
+			return;
171
+		}
172
+		$dbTrapName=$trapConfig['config']['database'];
173
+		$this->logging->log("Found database in config file: ".$dbTrapName,INFO );
174 174
 	    
175 175
 	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
176
-	    {
177
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
178
-	        return;
179
-	    }
180
-	    if (!array_key_exists($dbTrapName,$dbConfig))
181
-	    {
182
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
183
-	        return;
184
-	    }
176
+		{
177
+			$this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
178
+			return;
179
+		}
180
+		if (!array_key_exists($dbTrapName,$dbConfig))
181
+		{
182
+			$this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
183
+			return;
184
+		}
185 185
 	    
186
-	    $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix);
186
+		$this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix);
187 187
 	    
188
-	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
188
+		if ($this->api_use === true) return; // In case of API use, no IDO is necessary
189 189
         
190
-	    // IDO Database
191
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
192
-	    {
193
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
194
-	    }
195
-	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
196
-
197
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
-        if (!array_key_exists($dbIdoName,$dbConfig))
199
-	    {
200
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
201
-	        return;
202
-	    }
190
+		// IDO Database
191
+		if (!array_key_exists('IDOdatabase',$trapConfig['config']))
192
+		{
193
+			$this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
194
+		}
195
+		$dbIdoName=$trapConfig['config']['IDOdatabase'];		
196
+
197
+		$this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
+		if (!array_key_exists($dbIdoName,$dbConfig))
199
+		{
200
+			$this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
201
+			return;
202
+		}
203 203
 	    
204
-	    $this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
204
+		$this->trapsDB->setupIDO($dbConfig[$dbIdoName]);
205 205
 	}
206 206
 	
207 207
 	/**
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		// Database options
213 213
 		if ($this->logSetup === false) // Only if logging was no setup in constructor
214 214
 		{
215
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
215
+			$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
+			$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
+			$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
218 218
 		}
219 219
 	}
220 220
 
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	}
226 226
 	
227 227
 	/** 
228
-	*   Get data from db_config
229
-	*	@param $element string name of param
230
-	*	@return mixed : value (or null)
231
-	*/	
228
+	 *   Get data from db_config
229
+	 *	@param $element string name of param
230
+	 *	@return mixed : value (or null)
231
+	 */	
232 232
 	protected function getDBConfig($element)
233 233
 	{
234 234
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
 	}
247 247
 	
248 248
 	/** OBSOLETE Send log. Throws exception on critical error
249
-	*	@param	string $message Message to log
250
-	*	@param	int $level 1=critical 2=warning 3=trace 4=debug
251
-	*	@param  string $destination file/syslog/display
252
-	*	@return void
253
-	**/	
249
+	 *	@param	string $message Message to log
250
+	 *	@param	int $level 1=critical 2=warning 3=trace 4=debug
251
+	 *	@param  string $destination file/syslog/display
252
+	 *	@return void
253
+	 **/	
254 254
 	public function trapLog( $message, $level, $destination ='') // OBSOLETE
255 255
 	{	
256 256
 		// TODO : replace ref with $this->logging->log 
257
-	    $this->logging->log($message, $level, $destination);
257
+		$this->logging->log($message, $level, $destination);
258 258
 	}
259 259
 	
260 260
 	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
@@ -264,19 +264,19 @@  discard block
 block discarded – undo
264 264
 	
265 265
 	protected function getAPI()
266 266
 	{
267
-	    if ($this->icinga2api == null)
268
-	    {
269
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
270
-	    }
271
-	    return $this->icinga2api;
267
+		if ($this->icinga2api == null)
268
+		{
269
+			$this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
270
+		}
271
+		return $this->icinga2api;
272 272
 	}
273 273
 	
274 274
 	
275 275
 	/** 
276 276
 	 * read data from stream
277
-	*	@param $stream string input stream, defaults to "php://stdin"
278
-	*	@return mixed array trap data or exception with error
279
-	*/
277
+	 *	@param $stream string input stream, defaults to "php://stdin"
278
+	 *	@return mixed array trap data or exception with error
279
+	 */
280 280
 	public function read_trap($stream='php://stdin')
281 281
 	{
282 282
 		//Read data from snmptrapd from stdin
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
 		if ($input_stream === false)
286 286
 		{
287
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
287
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
288 288
 			$this->logging->log("Error reading stdin !",ERROR,'');
289 289
 			return null; // note : exception thrown by logging
290 290
 		}
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		$this->receivingHost=chop(fgets($input_stream));
294 294
 		if ($this->receivingHost === false)
295 295
 		{
296
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
296
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
297 297
 			$this->logging->log("Error reading Host !",ERROR,''); 
298 298
 		}
299 299
 		// line 2 IP:port=>IP:port
300 300
 		$IP=chop(fgets($input_stream));
301 301
 		if ($IP === false)
302 302
 		{
303
-		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
303
+			$this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
304 304
 			$this->logging->log("Error reading IP !",ERROR,''); 
305 305
 		}
306 306
 		$matches=array();
307 307
 		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
308 308
 		if ($ret_code===0 || $ret_code===false) 
309 309
 		{
310
-		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
310
+			$this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
311 311
 			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
312 312
 		} 
313 313
 		else 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			}
329 329
 			else 
330 330
 			{
331
-			    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'))
331
+				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'))
332 332
 				{
333 333
 					$this->trap_data['trap_oid']=$matches[2];				
334 334
 				}
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
 		if ($this->trap_data['trap_oid']=='unknown') 
346 346
 		{
347
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
347
+			$this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
348 348
 			$this->logging->log('no trap oid found',ERROR,'');
349 349
 		} 
350 350
 
@@ -374,9 +374,9 @@  discard block
 block discarded – undo
374 374
 
375 375
 	/** 
376 376
 	 * Translate oid into array(MIB,Name)
377
-	* @param $oid string oid to translate
378
-	* @return mixed : null if not found or array(MIB,Name)
379
-	*/
377
+	 * @param $oid string oid to translate
378
+	 * @return mixed : null if not found or array(MIB,Name)
379
+	 */
380 380
 	public function translateOID($oid)
381 381
 	{
382 382
 		// try from database
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		
410 410
 		// Try to get oid name from snmptranslate
411 411
 		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
412
-		    ' '.$oid);
412
+			' '.$oid);
413 413
 		$matches=array();
414 414
 		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
415 415
 		if ($ret_code===0 || $ret_code === false) {
@@ -422,9 +422,9 @@  discard block
 block discarded – undo
422 422
 	
423 423
 	/** 
424 424
 	 * Erase old trap records 
425
-	*	@param integer $days : erase traps when more than $days old
426
-	*	@return integer : number of lines deleted
427
-	**/
425
+	 *	@param integer $days : erase traps when more than $days old
426
+	 *	@return integer : number of lines deleted
427
+	 **/
428 428
 	public function eraseOldTraps($days=0)
429 429
 	{
430 430
 		if ($days==0)
@@ -449,72 +449,72 @@  discard block
 block discarded – undo
449 449
 	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
450 450
 	{
451 451
 	    
452
-	    $db_conn=$this->trapsDB->db_connect_trap();
452
+		$db_conn=$this->trapsDB->db_connect_trap();
453 453
 	    
454
-	    // add date time
455
-	    $insert_col ='date_received,status';
456
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
454
+		// add date time
455
+		$insert_col ='date_received,status';
456
+		$insert_val = "'" . date("Y-m-d H:i:s")."','error'";
457 457
         
458
-	    if ($sourceIP !=null)
459
-	    {
460
-	        $insert_col .=',source_ip';
461
-	        $insert_val .=",'". $sourceIP ."'";
462
-	    }
463
-	    if ($trapoid !=null)
464
-	    {
465
-	        $insert_col .=',trap_oid';
466
-	        $insert_val .=",'". $trapoid ."'";
467
-	    }
468
-	    $insert_col .=',status_detail';
469
-	    $insert_val .=",'". $message ."'";
458
+		if ($sourceIP !=null)
459
+		{
460
+			$insert_col .=',source_ip';
461
+			$insert_val .=",'". $sourceIP ."'";
462
+		}
463
+		if ($trapoid !=null)
464
+		{
465
+			$insert_col .=',trap_oid';
466
+			$insert_val .=",'". $trapoid ."'";
467
+		}
468
+		$insert_col .=',status_detail';
469
+		$insert_val .=",'". $message ."'";
470 470
 	    
471
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
471
+		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
472 472
 	    
473
-	    switch ($this->trapsDB->trapDBType)
474
-	    {
475
-	        case 'pgsql':
476
-	            $sql .= ' RETURNING id;';
477
-	            $this->logging->log('sql : '.$sql,INFO);
478
-	            if (($ret_code=$db_conn->query($sql)) === false) {
479
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
480
-	            }
481
-	            $this->logging->log('SQL insertion OK',INFO );
482
-	            // Get last id to insert oid/values in secondary table
483
-	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
473
+		switch ($this->trapsDB->trapDBType)
474
+		{
475
+			case 'pgsql':
476
+				$sql .= ' RETURNING id;';
477
+				$this->logging->log('sql : '.$sql,INFO);
478
+				if (($ret_code=$db_conn->query($sql)) === false) {
479
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
480
+				}
481
+				$this->logging->log('SQL insertion OK',INFO );
482
+				// Get last id to insert oid/values in secondary table
483
+				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
484 484
 	                
485
-	                $this->logging->log('Erreur recuperation id',1,'');
486
-	            }
487
-	            if (! isset($inserted_id_ret['id'])) {
488
-	                $this->logging->log('Error getting id',1,'');
489
-	            }
490
-	            $this->trap_id=$inserted_id_ret['id'];
491
-	            break;
492
-	        case 'mysql':
493
-	            $sql .= ';';
494
-	            $this->logging->log('sql : '.$sql,INFO );
495
-	            if ($db_conn->query($sql) === false) {
496
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
497
-	            }
498
-	            $this->logging->log('SQL insertion OK',INFO );
499
-	            // Get last id to insert oid/values in secondary table
500
-	            $sql='SELECT LAST_INSERT_ID();';
501
-	            if (($ret_code=$db_conn->query($sql)) === false) {
502
-	                $this->logging->log('Erreur recuperation id',1,'');
503
-	            }
485
+					$this->logging->log('Erreur recuperation id',1,'');
486
+				}
487
+				if (! isset($inserted_id_ret['id'])) {
488
+					$this->logging->log('Error getting id',1,'');
489
+				}
490
+				$this->trap_id=$inserted_id_ret['id'];
491
+				break;
492
+			case 'mysql':
493
+				$sql .= ';';
494
+				$this->logging->log('sql : '.$sql,INFO );
495
+				if ($db_conn->query($sql) === false) {
496
+					$this->logging->log('Error SQL insert : '.$sql,1,'');
497
+				}
498
+				$this->logging->log('SQL insertion OK',INFO );
499
+				// Get last id to insert oid/values in secondary table
500
+				$sql='SELECT LAST_INSERT_ID();';
501
+				if (($ret_code=$db_conn->query($sql)) === false) {
502
+					$this->logging->log('Erreur recuperation id',1,'');
503
+				}
504 504
 	            
505
-	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507
-	            $this->trap_id=$inserted_id;
508
-	            break;
509
-	        default:
510
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
511
-	    }
505
+				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
+				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507
+				$this->trap_id=$inserted_id;
508
+				break;
509
+			default:
510
+				$this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
511
+		}
512 512
 	    
513
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
513
+		$this->logging->log('id found: '. $this->trap_id,INFO );    
514 514
 	}
515 515
 	
516 516
 	/** Write trap data to trap database
517
-	*/
517
+	 */
518 518
 	public function writeTrapToDB()
519 519
 	{
520 520
 		
@@ -612,10 +612,10 @@  discard block
 block discarded – undo
612 612
 	}
613 613
 
614 614
 	/** Get rules from rule database with ip and oid
615
-	*	@param $ip string ipv4 or ipv6
616
-	*	@param $oid string oid in numeric
617
-	*	@return mixed|boolean : PDO object or false
618
-	*/	
615
+	 *	@param $ip string ipv4 or ipv6
616
+	 *	@param $oid string oid in numeric
617
+	 *	@return mixed|boolean : PDO object or false
618
+	 */	
619 619
 	protected function getRules($ip,$oid)
620 620
 	{
621 621
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -674,9 +674,9 @@  discard block
 block discarded – undo
674 674
 	}
675 675
 
676 676
 	/** Add rule match to rule
677
-	*	@param id int : rule id
678
-	*   @param set int : value to set
679
-	*/
677
+	 *	@param id int : rule id
678
+	 *   @param set int : value to set
679
+	 */
680 680
 	protected function add_rule_match($id, $set)
681 681
 	{
682 682
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -693,53 +693,53 @@  discard block
 block discarded – undo
693 693
 	 * @param integer $state numerical staus 
694 694
 	 * @param string $display
695 695
 	 * @returnn bool true is service check was sent without error
696
-	*/
696
+	 */
697 697
 	public function serviceCheckResult($host,$service,$state,$display)
698 698
 	{
699
-	    if ($this->api_use === false)
700
-	    {
701
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
-    			$host.';' .$service .';' . $state . ';'.$display;
703
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
699
+		if ($this->api_use === false)
700
+		{
701
+			$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
+				$host.';' .$service .';' . $state . ';'.$display;
703
+			$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
704 704
     		
705
-    		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707
-    		return true;
708
-	    }
709
-	    else
710
-	    {
711
-	        $api = $this->getAPI();
712
-	        $api->setCredentials($this->api_username, $this->api_password);
713
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
714
-	        if ($retcode == false)
715
-	        {
716
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
717
-	            return false;
718
-	        }
719
-	        else 
720
-	        {
721
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
722
-	            return true;
723
-	        }
724
-	    }
705
+			// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
+			exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707
+			return true;
708
+		}
709
+		else
710
+		{
711
+			$api = $this->getAPI();
712
+			$api->setCredentials($this->api_username, $this->api_password);
713
+			list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
714
+			if ($retcode == false)
715
+			{
716
+				$this->logging->log( "Error sending result : " .$retmessage,WARN,'');
717
+				return false;
718
+			}
719
+			else 
720
+			{
721
+				$this->logging->log( "Sent result : " .$retmessage,INFO );
722
+				return true;
723
+			}
724
+		}
725 725
 	}
726 726
 	
727 727
 	public function getHostByIP($ip)
728 728
 	{
729
-	    $api = $this->getAPI();
730
-	    $api->setCredentials($this->api_username, $this->api_password);
731
-	    return $api->getHostByIP($ip);
729
+		$api = $this->getAPI();
730
+		$api->setCredentials($this->api_username, $this->api_password);
731
+		return $api->getHostByIP($ip);
732 732
 	}
733 733
 	
734 734
 	/** Resolve display. 
735
-	*	Changes OID(<oid>) to value if found or text "<not in trap>"
736
-	*	@param $display string
737
-	*	@return string display
738
-	*/
735
+	 *	Changes OID(<oid>) to value if found or text "<not in trap>"
736
+	 *	@param $display string
737
+	 *	@return string display
738
+	 */
739 739
 	protected function applyDisplay($display)
740 740
 	{
741
-	    $matches=array();
742
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
741
+		$matches=array();
742
+		while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
743 743
 		{
744 744
 			$oid=$matches[1];
745 745
 			$found=0;
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 	}
774 774
 	
775 775
 	/** Match rules for current trap and do action
776
-	*/
776
+	 */
777 777
 	public function applyRules()
778 778
 	{
779 779
 		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
@@ -811,12 +811,12 @@  discard block
 block discarded – undo
811 811
 					{
812 812
 						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
813 813
 						{
814
-						    $this->trap_action.='Error sending status : check cmd/API';
814
+							$this->trap_action.='Error sending status : check cmd/API';
815 815
 						}
816 816
 						else
817 817
 						{
818
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
819
-						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
818
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
819
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
820 820
 						}
821 821
 					}
822 822
 					else
@@ -833,15 +833,15 @@  discard block
 block discarded – undo
833 833
 					$this->logging->log('action NOK : '.$action,INFO );
834 834
 					if ($action >= 0)
835 835
 					{
836
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
837
-					    {
838
-					        $this->trap_action.='Error sending status : check cmd/API';
839
-					    }
840
-					    else
841
-					    {
842
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
843
-    						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
844
-					    }
836
+						if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
837
+						{
838
+							$this->trap_action.='Error sending status : check cmd/API';
839
+						}
840
+						else
841
+						{
842
+							$this->add_rule_match($rule['id'],$rule['num_match']+1);
843
+							$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
844
+						}
845 845
 					}
846 846
 					else
847 847
 					{
@@ -864,9 +864,9 @@  discard block
 block discarded – undo
864 864
 			}
865 865
 			catch (Exception $e) 
866 866
 			{ 
867
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
868
-			    $this->trap_action.=' ERR : '.$e->getMessage();
869
-			    $this->trap_data['status']='error';
867
+				$this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
868
+				$this->trap_action.=' ERR : '.$e->getMessage();
869
+				$this->trap_data['status']='error';
870 870
 			}
871 871
 			
872 872
 		}
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 	}
882 882
 
883 883
 	/** Add Time a action to rule
884
-	*	@param string $time : time to process to insert in SQL
885
-	*/
884
+	 *	@param string $time : time to process to insert in SQL
885
+	 */
886 886
 	public function add_rule_final($time)
887 887
 	{
888 888
 		$db_conn=$this->trapsDB->db_connect_trap();
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
 	/*********** UTILITIES *********************/
900 900
 	
901 901
 	/** reset service to OK after time defined in rule
902
-	*	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
903
-	*	@return integer : not in use
904
-	**/
902
+	 *	TODO logic is : get all service in error + all rules, see if getting all rules then select services is better 
903
+	 *	@return integer : not in use
904
+	 **/
905 905
 	public function reset_services()
906 906
 	{
907 907
 		// Get all services not in 'ok' state
Please login to merge, or discard this patch.
Spacing   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 	protected $api_password='';
37 37
 
38 38
 	// Logs 
39
-	protected $logging;    //< Logging class.
40
-	protected $logSetup;   //< bool true if log was setup in constructor
39
+	protected $logging; //< Logging class.
40
+	protected $logSetup; //< bool true if log was setup in constructor
41 41
 	
42 42
 	// Databases
43 43
 	public $trapsDB; //< Database class
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	// Rule evaluation 
57 57
 	public $ruleClass; // Rule class
58 58
 	
59
-	function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
59
+	function __construct($etc_dir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
60 60
 	{
61 61
 	    // Paths of ini files
62 62
 		$this->icingaweb2_etc=$etc_dir;
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 		$this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
65 65
 
66 66
 		// Setup logging
67
-		$this->logging = new Logging();
67
+		$this->logging=new Logging();
68 68
 		if ($baseLogLevel != null)
69 69
 		{
70
-		    $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
70
+		    $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
71 71
 		    $this->logSetup=true;
72 72
 		}
73 73
 		else
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
 		$this->logging->log('Loggin started', INFO);
76 76
 
77 77
 		// Get options from ini files
78
-		$trapConfig=parse_ini_file($this->trap_module_config,true);
78
+		$trapConfig=parse_ini_file($this->trap_module_config, true);
79 79
 		if ($trapConfig == false)
80 80
 		{
81
-		    $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
81
+		    $this->logging->log("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog');
82 82
 		}
83 83
 		$this->getMainOptions($trapConfig); // Get main options from ini file
84 84
 		$this->setupDatabase($trapConfig); // Setup database class
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		$this->getDatabaseOptions(); // Get options in database
87 87
 		if ($this->api_use === true) $this->getAPI(); // Setup API
88 88
 		
89
-		$this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
89
+		$this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
90 90
 		
91
-		$this->ruleClass = new Rule($this->logging); //< Create Rule class
91
+		$this->ruleClass=new Rule($this->logging); //< Create Rule class
92 92
 		
93 93
 		$this->trap_data=array(
94 94
 			'source_ip'	=> 'unknown',
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
 	 * @param string $message warning message if not found
111 111
 	 * @return boolean true if found, or false
112 112
 	 */
113
-	protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
113
+	protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
114 114
 	{
115 115
 	    if (!isset($option_array[$option_category][$option_name]))
116 116
 	    {
117 117
 	        if ($message === null)
118 118
 	        {
119
-	            $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
119
+	            $message='No '.$option_name.' in config file: '.$this->trap_module_config;
120 120
 	        }
121
-	        $this->logging->log($message,$log_level,'syslog');
121
+	        $this->logging->log($message, $log_level, 'syslog');
122 122
 	        return false;
123 123
 	    }
124 124
 	    else
@@ -136,24 +136,24 @@  discard block
 block discarded – undo
136 136
 	{
137 137
 
138 138
 		// Snmptranslate binary path
139
-		$this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
139
+		$this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
140 140
 
141 141
 		// mibs path
142
-		$this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
142
+		$this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
143 143
 
144 144
 		// icinga2cmd path
145
-		$this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
145
+		$this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
146 146
 		
147 147
 		// table prefix
148
-		$this->getOptionIfSet($trapConfig,'config','database_prefix', $this->db_prefix);
148
+		$this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->db_prefix);
149 149
 
150 150
 		// API options
151
-		if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->api_hostname))
151
+		if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->api_hostname))
152 152
 		{
153 153
 		    $this->api_use=true;
154
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
155
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
156
-		    $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
154
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->api_port);
155
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->api_username);
156
+		    $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->api_password);
157 157
 		}
158 158
 	}
159 159
 	
@@ -164,40 +164,40 @@  discard block
 block discarded – undo
164 164
 	protected function setupDatabase($trapConfig)
165 165
 	{
166 166
 	    // Trap database
167
-	    if (!array_key_exists('database',$trapConfig['config']))
167
+	    if (!array_key_exists('database', $trapConfig['config']))
168 168
         {
169
-            $this->logging->log("No database in config file: ".$this->trap_module_config,ERROR,'');
169
+            $this->logging->log("No database in config file: ".$this->trap_module_config, ERROR, '');
170 170
             return;
171 171
         }
172 172
         $dbTrapName=$trapConfig['config']['database'];
173
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
173
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
174 174
 	    
175
-	   if ( ($dbConfig=parse_ini_file($this->icingaweb2_ressources,true)) === false)
175
+	   if (($dbConfig=parse_ini_file($this->icingaweb2_ressources, true)) === false)
176 176
 	    {
177
-	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
177
+	        $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources, ERROR, '');
178 178
 	        return;
179 179
 	    }
180
-	    if (!array_key_exists($dbTrapName,$dbConfig))
180
+	    if (!array_key_exists($dbTrapName, $dbConfig))
181 181
 	    {
182
-	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
182
+	        $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
183 183
 	        return;
184 184
 	    }
185 185
 	    
186
-	    $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix);
186
+	    $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->db_prefix);
187 187
 	    
188 188
 	    if ($this->api_use === true) return; // In case of API use, no IDO is necessary
189 189
         
190 190
 	    // IDO Database
191
-	    if (!array_key_exists('IDOdatabase',$trapConfig['config']))
191
+	    if (!array_key_exists('IDOdatabase', $trapConfig['config']))
192 192
 	    {
193
-	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
193
+	        $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config, ERROR, '');
194 194
 	    }
195 195
 	    $dbIdoName=$trapConfig['config']['IDOdatabase'];		
196 196
 
197
-	    $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
198
-        if (!array_key_exists($dbIdoName,$dbConfig))
197
+	    $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
198
+        if (!array_key_exists($dbIdoName, $dbConfig))
199 199
 	    {
200
-	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
200
+	        $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
201 201
 	        return;
202 202
 	    }
203 203
 	    
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 		// Database options
213 213
 		if ($this->logSetup === false) // Only if logging was no setup in constructor
214 214
 		{
215
-    		$this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
216
-    		$this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
217
-    		$this->getDBConfigIfSet('log_file',$this->logging->outputFile);
215
+    		$this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
216
+    		$this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
217
+    		$this->getDBConfigIfSet('log_file', $this->logging->outputFile);
218 218
 		}
219 219
 	}
220 220
 
221
-	protected function getDBConfigIfSet($element,&$variable)
221
+	protected function getDBConfigIfSet($element, &$variable)
222 222
 	{
223 223
 		$value=$this->getDBConfig($element);
224 224
 		if ($value != 'null') $variable=$value;
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		$db_conn=$this->trapsDB->db_connect_trap();
235 235
 		$sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )';
236 236
 		if (($ret_code=$db_conn->query($sql)) === false) {
237
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
237
+			$this->logging->log('No result in query : '.$sql, WARN, '');
238 238
 			return null;
239 239
 		}
240 240
 		$value=$ret_code->fetch();
@@ -251,22 +251,22 @@  discard block
 block discarded – undo
251 251
 	*	@param  string $destination file/syslog/display
252 252
 	*	@return void
253 253
 	**/	
254
-	public function trapLog( $message, $level, $destination ='') // OBSOLETE
254
+	public function trapLog($message, $level, $destination='') // OBSOLETE
255 255
 	{	
256 256
 		// TODO : replace ref with $this->logging->log 
257 257
 	    $this->logging->log($message, $level, $destination);
258 258
 	}
259 259
 	
260
-	public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
260
+	public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
261 261
 	{
262
-		$this->logging->setLogging($debugLvl, $outputType,$outputOption);
262
+		$this->logging->setLogging($debugLvl, $outputType, $outputOption);
263 263
 	}
264 264
 	
265 265
 	protected function getAPI()
266 266
 	{
267 267
 	    if ($this->icinga2api == null)
268 268
 	    {
269
-	        $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
269
+	        $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port);
270 270
 	    }
271 271
 	    return $this->icinga2api;
272 272
 	}
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if ($input_stream === false)
286 286
 		{
287 287
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
288
-			$this->logging->log("Error reading stdin !",ERROR,'');
288
+			$this->logging->log("Error reading stdin !", ERROR, '');
289 289
 			return null; // note : exception thrown by logging
290 290
 		}
291 291
 
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 		if ($this->receivingHost === false)
295 295
 		{
296 296
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
297
-			$this->logging->log("Error reading Host !",ERROR,''); 
297
+			$this->logging->log("Error reading Host !", ERROR, ''); 
298 298
 		}
299 299
 		// line 2 IP:port=>IP:port
300 300
 		$IP=chop(fgets($input_stream));
301 301
 		if ($IP === false)
302 302
 		{
303 303
 		    $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
304
-			$this->logging->log("Error reading IP !",ERROR,''); 
304
+			$this->logging->log("Error reading IP !", ERROR, ''); 
305 305
 		}
306 306
 		$matches=array();
307
-		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
308
-		if ($ret_code===0 || $ret_code===false) 
307
+		$ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
308
+		if ($ret_code === 0 || $ret_code === false) 
309 309
 		{
310 310
 		    $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
311
-			$this->logging->log('Error parsing IP : '.$IP,ERROR,'');
311
+			$this->logging->log('Error parsing IP : '.$IP, ERROR, '');
312 312
 		} 
313 313
 		else 
314 314
 		{		
@@ -318,34 +318,34 @@  discard block
 block discarded – undo
318 318
 			$this->trap_data['destination_port']=$matches[4];
319 319
 		}
320 320
 
321
-		while (($vars=fgets($input_stream)) !==false)
321
+		while (($vars=fgets($input_stream)) !== false)
322 322
 		{
323 323
 			$vars=chop($vars);
324
-			$ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
325
-			if ($ret_code===0 || $ret_code===false) 
324
+			$ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
325
+			if ($ret_code === 0 || $ret_code === false) 
326 326
 			{
327
-				$this->logging->log('No match on trap data : '.$vars,WARN,'');
327
+				$this->logging->log('No match on trap data : '.$vars, WARN, '');
328 328
 			}
329 329
 			else 
330 330
 			{
331
-			    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'))
331
+			    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'))
332 332
 				{
333 333
 					$this->trap_data['trap_oid']=$matches[2];				
334 334
 				}
335 335
 				else
336 336
 				{
337
-					$object= new stdClass;
338
-					$object->oid =$matches[1];
339
-					$object->value = $matches[2];
340
-					array_push($this->trap_data_ext,$object);
337
+					$object=new stdClass;
338
+					$object->oid=$matches[1];
339
+					$object->value=$matches[2];
340
+					array_push($this->trap_data_ext, $object);
341 341
 				}
342 342
 			}
343 343
 		}
344 344
 
345
-		if ($this->trap_data['trap_oid']=='unknown') 
345
+		if ($this->trap_data['trap_oid'] == 'unknown') 
346 346
 		{
347
-		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
348
-			$this->logging->log('no trap oid found',ERROR,'');
347
+		    $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
348
+			$this->logging->log('no trap oid found', ERROR, '');
349 349
 		} 
350 350
 
351 351
 		// Translate oids.
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 		
369 369
 
370
-		$this->trap_data['status']= 'waiting';
370
+		$this->trap_data['status']='waiting';
371 371
 		
372 372
 		return $this->trap_data;
373 373
 	}
@@ -383,40 +383,40 @@  discard block
 block discarded – undo
383 383
 		$db_conn=$this->trapsDB->db_connect_trap();
384 384
 		
385 385
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';';
386
-		$this->logging->log('SQL query : '.$sql,DEBUG );
386
+		$this->logging->log('SQL query : '.$sql, DEBUG);
387 387
 		if (($ret_code=$db_conn->query($sql)) === false) {
388
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
388
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
389 389
 		}
390 390
 		$name=$ret_code->fetch();
391 391
 		if ($name['name'] != null)
392 392
 		{
393
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
393
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
394 394
 		}
395 395
 		
396 396
 		// Also check if it is an instance of OID
397
-		$oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
397
+		$oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
398 398
 		
399 399
 		$sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
400
-		$this->logging->log('SQL query : '.$sql,DEBUG );
400
+		$this->logging->log('SQL query : '.$sql, DEBUG);
401 401
 		if (($ret_code=$db_conn->query($sql)) === false) {
402
-			$this->logging->log('No result in query : ' . $sql,ERROR,'');
402
+			$this->logging->log('No result in query : '.$sql, ERROR, '');
403 403
 		}
404 404
 		$name=$ret_code->fetch();
405 405
 		if ($name['name'] != null)
406 406
 		{
407
-			return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
407
+			return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
408 408
 		}
409 409
 		
410 410
 		// Try to get oid name from snmptranslate
411
-		$translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
411
+		$translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
412 412
 		    ' '.$oid);
413 413
 		$matches=array();
414
-		$ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
415
-		if ($ret_code===0 || $ret_code === false) {
414
+		$ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
415
+		if ($ret_code === 0 || $ret_code === false) {
416 416
 			return NULL;
417 417
 		} else {
418
-			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
419
-			return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
418
+			$this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
419
+			return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
420 420
 		}	
421 421
 	}
422 422
 	
@@ -427,90 +427,90 @@  discard block
 block discarded – undo
427 427
 	**/
428 428
 	public function eraseOldTraps($days=0)
429 429
 	{
430
-		if ($days==0)
430
+		if ($days == 0)
431 431
 		{
432 432
 			if (($days=$this->getDBConfig('db_remove_days')) == null)
433 433
 			{
434
-				$this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
434
+				$this->logging->log('No days specified & no db value : no tap erase', WARN, '');
435 435
 				return;
436 436
 			}
437 437
 		}
438 438
 		$db_conn=$this->trapsDB->db_connect_trap();
439
-		$daysago = strtotime("-".$days." day");
440
-		$sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
439
+		$daysago=strtotime("-".$days." day");
440
+		$sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
441 441
 		if ($db_conn->query($sql) === false) {
442
-			$this->logging->log('Error erasing traps : '.$sql,ERROR,'');
442
+			$this->logging->log('Error erasing traps : '.$sql, ERROR, '');
443 443
 		}
444
-		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
444
+		$this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
445 445
 	}
446 446
 
447 447
 	/** Write error to received trap database
448 448
 	 */
449
-	public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
449
+	public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
450 450
 	{
451 451
 	    
452 452
 	    $db_conn=$this->trapsDB->db_connect_trap();
453 453
 	    
454 454
 	    // add date time
455
-	    $insert_col ='date_received,status';
456
-	    $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
455
+	    $insert_col='date_received,status';
456
+	    $insert_val="'".date("Y-m-d H:i:s")."','error'";
457 457
         
458
-	    if ($sourceIP !=null)
458
+	    if ($sourceIP != null)
459 459
 	    {
460
-	        $insert_col .=',source_ip';
461
-	        $insert_val .=",'". $sourceIP ."'";
460
+	        $insert_col.=',source_ip';
461
+	        $insert_val.=",'".$sourceIP."'";
462 462
 	    }
463
-	    if ($trapoid !=null)
463
+	    if ($trapoid != null)
464 464
 	    {
465
-	        $insert_col .=',trap_oid';
466
-	        $insert_val .=",'". $trapoid ."'";
465
+	        $insert_col.=',trap_oid';
466
+	        $insert_val.=",'".$trapoid."'";
467 467
 	    }
468
-	    $insert_col .=',status_detail';
469
-	    $insert_val .=",'". $message ."'";
468
+	    $insert_col.=',status_detail';
469
+	    $insert_val.=",'".$message."'";
470 470
 	    
471
-	    $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
471
+	    $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
472 472
 	    
473 473
 	    switch ($this->trapsDB->trapDBType)
474 474
 	    {
475 475
 	        case 'pgsql':
476
-	            $sql .= ' RETURNING id;';
477
-	            $this->logging->log('sql : '.$sql,INFO);
476
+	            $sql.=' RETURNING id;';
477
+	            $this->logging->log('sql : '.$sql, INFO);
478 478
 	            if (($ret_code=$db_conn->query($sql)) === false) {
479
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
479
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
480 480
 	            }
481
-	            $this->logging->log('SQL insertion OK',INFO );
481
+	            $this->logging->log('SQL insertion OK', INFO);
482 482
 	            // Get last id to insert oid/values in secondary table
483 483
 	            if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
484 484
 	                
485
-	                $this->logging->log('Erreur recuperation id',1,'');
485
+	                $this->logging->log('Erreur recuperation id', 1, '');
486 486
 	            }
487
-	            if (! isset($inserted_id_ret['id'])) {
488
-	                $this->logging->log('Error getting id',1,'');
487
+	            if (!isset($inserted_id_ret['id'])) {
488
+	                $this->logging->log('Error getting id', 1, '');
489 489
 	            }
490 490
 	            $this->trap_id=$inserted_id_ret['id'];
491 491
 	            break;
492 492
 	        case 'mysql':
493
-	            $sql .= ';';
494
-	            $this->logging->log('sql : '.$sql,INFO );
493
+	            $sql.=';';
494
+	            $this->logging->log('sql : '.$sql, INFO);
495 495
 	            if ($db_conn->query($sql) === false) {
496
-	                $this->logging->log('Error SQL insert : '.$sql,1,'');
496
+	                $this->logging->log('Error SQL insert : '.$sql, 1, '');
497 497
 	            }
498
-	            $this->logging->log('SQL insertion OK',INFO );
498
+	            $this->logging->log('SQL insertion OK', INFO);
499 499
 	            // Get last id to insert oid/values in secondary table
500 500
 	            $sql='SELECT LAST_INSERT_ID();';
501 501
 	            if (($ret_code=$db_conn->query($sql)) === false) {
502
-	                $this->logging->log('Erreur recuperation id',1,'');
502
+	                $this->logging->log('Erreur recuperation id', 1, '');
503 503
 	            }
504 504
 	            
505 505
 	            $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
506
-	            if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
506
+	            if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507 507
 	            $this->trap_id=$inserted_id;
508 508
 	            break;
509 509
 	        default:
510
-	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
510
+	            $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
511 511
 	    }
512 512
 	    
513
-	    $this->logging->log('id found: '. $this->trap_id,INFO );    
513
+	    $this->logging->log('id found: '.$this->trap_id, INFO);    
514 514
 	}
515 515
 	
516 516
 	/** Write trap data to trap database
@@ -527,86 +527,86 @@  discard block
 block discarded – undo
527 527
 		$insert_col='';
528 528
 		$insert_val='';
529 529
 		// add date time
530
-		$this->trap_data['date_received'] = date("Y-m-d H:i:s");
530
+		$this->trap_data['date_received']=date("Y-m-d H:i:s");
531 531
 
532 532
 		$firstcol=1;
533 533
 		foreach ($this->trap_data as $col => $val)
534 534
 		{
535
-			if ($firstcol==0) 
535
+			if ($firstcol == 0) 
536 536
 			{
537
-				$insert_col .=',';
538
-				$insert_val .=',';
537
+				$insert_col.=',';
538
+				$insert_val.=',';
539 539
 			}
540
-			$insert_col .= $col ;
541
-			$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
540
+			$insert_col.=$col;
541
+			$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
542 542
 			$firstcol=0;
543 543
 		}
544 544
 		
545
-		$sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
545
+		$sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
546 546
 		switch ($this->trapsDB->trapDBType)
547 547
 		{
548 548
 			case 'pgsql': 
549
-				$sql .= ' RETURNING id;';
550
-				$this->logging->log('sql : '.$sql,INFO );
549
+				$sql.=' RETURNING id;';
550
+				$this->logging->log('sql : '.$sql, INFO);
551 551
 				if (($ret_code=$db_conn->query($sql)) === false) {
552
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
552
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
553 553
 				}
554
-				$this->logging->log('SQL insertion OK',INFO );
554
+				$this->logging->log('SQL insertion OK', INFO);
555 555
 				// Get last id to insert oid/values in secondary table
556 556
 				if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
557 557
 														   
558
-					$this->logging->log('Erreur recuperation id',ERROR,'');
558
+					$this->logging->log('Erreur recuperation id', ERROR, '');
559 559
 				}
560
-				if (! isset($inserted_id_ret['id'])) {
561
-					$this->logging->log('Error getting id',ERROR,'');
560
+				if (!isset($inserted_id_ret['id'])) {
561
+					$this->logging->log('Error getting id', ERROR, '');
562 562
 				}
563 563
 				$this->trap_id=$inserted_id_ret['id'];
564 564
 			break;
565 565
 			case 'mysql': 
566
-				$sql .= ';';
567
-				$this->logging->log('sql : '.$sql,INFO );
566
+				$sql.=';';
567
+				$this->logging->log('sql : '.$sql, INFO);
568 568
 				if ($db_conn->query($sql) === false) {
569
-					$this->logging->log('Error SQL insert : '.$sql,ERROR,'');
569
+					$this->logging->log('Error SQL insert : '.$sql, ERROR, '');
570 570
 				}
571
-				$this->logging->log('SQL insertion OK',INFO );
571
+				$this->logging->log('SQL insertion OK', INFO);
572 572
 				// Get last id to insert oid/values in secondary table
573 573
 				$sql='SELECT LAST_INSERT_ID();';
574 574
 				if (($ret_code=$db_conn->query($sql)) === false) {
575
-					$this->logging->log('Erreur recuperation id',ERROR,'');
575
+					$this->logging->log('Erreur recuperation id', ERROR, '');
576 576
 				}
577 577
 
578 578
 				$inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
579
-				if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
579
+				if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
580 580
 				$this->trap_id=$inserted_id;
581 581
 			break;
582 582
 			default: 
583
-				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
583
+				$this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
584 584
 		}
585
-		$this->logging->log('id found: '.$this->trap_id,INFO );
585
+		$this->logging->log('id found: '.$this->trap_id, INFO);
586 586
 		
587 587
 		// Fill trap extended data table
588 588
 		foreach ($this->trap_data_ext as $value) {			
589 589
 			// TODO : detect if trap value is encoded and decode it to UTF-8 for database
590 590
 			$firstcol=1;
591
-			$value->trap_id = $this->trap_id;
591
+			$value->trap_id=$this->trap_id;
592 592
 			$insert_col='';
593 593
 			$insert_val='';
594 594
 			foreach ($value as $col => $val)
595 595
 			{
596
-				if ($firstcol==0) 
596
+				if ($firstcol == 0) 
597 597
 				{
598
-					$insert_col .=',';
599
-					$insert_val .=',';
598
+					$insert_col.=',';
599
+					$insert_val.=',';
600 600
 				}
601
-				$insert_col .= $col;
602
-				$insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
601
+				$insert_col.=$col;
602
+				$insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
603 603
 				$firstcol=0;
604 604
 			}
605 605
 
606
-			$sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';			
606
+			$sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';			
607 607
 
608 608
 			if ($db_conn->query($sql) === false) {
609
-				$this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
609
+				$this->logging->log('Erreur insertion data : '.$sql, WARN, '');
610 610
 			}	
611 611
 		}	
612 612
 	}
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
 	*	@param $oid string oid in numeric
617 617
 	*	@return mixed|boolean : PDO object or false
618 618
 	*/	
619
-	protected function getRules($ip,$oid)
619
+	protected function getRules($ip, $oid)
620 620
 	{
621 621
 		$db_conn=$this->trapsDB->db_connect_trap();
622 622
 		// fetch rules based on IP in rule and OID
623 623
 		$sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' ';
624
-		$this->logging->log('SQL query : '.$sql,DEBUG );
624
+		$this->logging->log('SQL query : '.$sql, DEBUG);
625 625
 		if (($ret_code=$db_conn->query($sql)) === false) {
626
-			$this->logging->log('No result in query : ' . $sql,WARN,'');
626
+			$this->logging->log('No result in query : '.$sql, WARN, '');
627 627
 			return false;
628 628
 		}
629 629
 		$rules_all=$ret_code->fetchAll();
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
 		$rule_ret_key=0;
633 633
 		foreach ($rules_all as $key => $rule)
634 634
 		{
635
-			if ($rule['ip4']==$ip || $rule['ip6']==$ip)
635
+			if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
636 636
 			{
637 637
 				$rules_ret[$rule_ret_key]=$rules_all[$key];
638 638
 				//TODO : get host name by API (and check if correct in rule).
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 				continue;
641 641
 			}
642 642
 			// TODO : get hosts IP by API
643
-			if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
643
+			if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
644 644
 			{ // get ips of group members by oid
645 645
 				$db_conn2=$this->trapsDB->db_connect_ido();
646 646
 				$sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
652 652
 						WHERE o.name1='".$rule['host_group_name']."';";
653 653
 				if (($ret_code2=$db_conn2->query($sql)) === false) {
654
-					$this->logging->log('No result in query : ' . $sql,WARN,'');
654
+					$this->logging->log('No result in query : '.$sql, WARN, '');
655 655
 					continue;
656 656
 				}
657 657
 				$grouphosts=$ret_code2->fetchAll();
658 658
 				//echo "rule grp :\n";print_r($grouphosts);echo "\n";
659
-				foreach ( $grouphosts as $host)
659
+				foreach ($grouphosts as $host)
660 660
 				{
661 661
 					//echo $host['ip4']."\n";
662
-					if ($host['ip4']==$ip || $host['ip6']==$ip)
662
+					if ($host['ip4'] == $ip || $host['ip6'] == $ip)
663 663
 					{
664 664
 						//echo "Rule added \n";
665 665
 						$rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 		$db_conn=$this->trapsDB->db_connect_trap();
683 683
 		$sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
684 684
 		if ($db_conn->query($sql) === false) {
685
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
685
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
686 686
 		}
687 687
 	}
688 688
 	
@@ -694,31 +694,31 @@  discard block
 block discarded – undo
694 694
 	 * @param string $display
695 695
 	 * @returnn bool true is service check was sent without error
696 696
 	*/
697
-	public function serviceCheckResult($host,$service,$state,$display)
697
+	public function serviceCheckResult($host, $service, $state, $display)
698 698
 	{
699 699
 	    if ($this->api_use === false)
700 700
 	    {
701
-    		$send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
702
-    			$host.';' .$service .';' . $state . ';'.$display;
703
-    		$this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
701
+    		$send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
702
+    			$host.';'.$service.';'.$state.';'.$display;
703
+    		$this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
704 704
     		
705 705
     		// TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
706
-    		exec('echo "'.$send.'" > ' .$this->icinga2cmd);
706
+    		exec('echo "'.$send.'" > '.$this->icinga2cmd);
707 707
     		return true;
708 708
 	    }
709 709
 	    else
710 710
 	    {
711
-	        $api = $this->getAPI();
711
+	        $api=$this->getAPI();
712 712
 	        $api->setCredentials($this->api_username, $this->api_password);
713
-	        list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display);
713
+	        list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display);
714 714
 	        if ($retcode == false)
715 715
 	        {
716
-	            $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
716
+	            $this->logging->log("Error sending result : ".$retmessage, WARN, '');
717 717
 	            return false;
718 718
 	        }
719 719
 	        else 
720 720
 	        {
721
-	            $this->logging->log( "Sent result : " .$retmessage,INFO );
721
+	            $this->logging->log("Sent result : ".$retmessage, INFO);
722 722
 	            return true;
723 723
 	        }
724 724
 	    }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 	
727 727
 	public function getHostByIP($ip)
728 728
 	{
729
-	    $api = $this->getAPI();
729
+	    $api=$this->getAPI();
730 730
 	    $api->setCredentials($this->api_username, $this->api_password);
731 731
 	    return $api->getHostByIP($ip);
732 732
 	}
@@ -739,32 +739,32 @@  discard block
 block discarded – undo
739 739
 	protected function applyDisplay($display)
740 740
 	{
741 741
 	    $matches=array();
742
-	    while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
742
+	    while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
743 743
 		{
744 744
 			$oid=$matches[1];
745 745
 			$found=0;
746
-			foreach($this->trap_data_ext as $val)
746
+			foreach ($this->trap_data_ext as $val)
747 747
 			{
748 748
 				if ($oid == $val->oid)
749 749
 				{
750
-					$val->value=preg_replace('/"/','',$val->value);
750
+					$val->value=preg_replace('/"/', '', $val->value);
751 751
 					$rep=0;
752
-					$display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
753
-					if ($rep==0)
752
+					$display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
753
+					if ($rep == 0)
754 754
 					{
755
-						$this->logging->log("Error in display",WARN,'');
755
+						$this->logging->log("Error in display", WARN, '');
756 756
 						return $display;
757 757
 					}
758 758
 					$found=1;
759 759
 					break;
760 760
 				}
761 761
 			}
762
-			if ($found==0)
762
+			if ($found == 0)
763 763
 			{
764
-				$display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
765
-				if ($rep==0)
764
+				$display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
765
+				if ($rep == 0)
766 766
 				{
767
-					$this->logging->log("Error in display",WARN,'');
767
+					$this->logging->log("Error in display", WARN, '');
768 768
 					return $display;
769 769
 				}				
770 770
 			}
@@ -776,11 +776,11 @@  discard block
 block discarded – undo
776 776
 	*/
777 777
 	public function applyRules()
778 778
 	{
779
-		$rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
779
+		$rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
780 780
 		
781
-		if ($rules===false || count($rules)==0)
781
+		if ($rules === false || count($rules) == 0)
782 782
 		{
783
-			$this->logging->log('No rules found for this trap',INFO );
783
+			$this->logging->log('No rules found for this trap', INFO);
784 784
 			$this->trap_data['status']='unknown';
785 785
 			$this->trap_to_db=true;
786 786
 			return;
@@ -795,59 +795,59 @@  discard block
 block discarded – undo
795 795
 			$service_name=$rule['service_name'];
796 796
 			
797 797
 			$display=$this->applyDisplay($rule['display']);
798
-			$this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
798
+			$this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
799 799
 			try
800 800
 			{
801
-				$this->logging->log('Rule to eval : '.$rule['rule'],INFO );
802
-				$evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext) ;
801
+				$this->logging->log('Rule to eval : '.$rule['rule'], INFO);
802
+				$evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext);
803 803
 				//->eval_rule($rule['rule']);
804 804
 				
805 805
 				if ($evalr == true)
806 806
 				{
807 807
 					//$this->logging->log('rules OOK: '.print_r($rule),INFO );
808 808
 					$action=$rule['action_match'];
809
-					$this->logging->log('action OK : '.$action,INFO );
809
+					$this->logging->log('action OK : '.$action, INFO);
810 810
 					if ($action >= 0)
811 811
 					{
812
-						if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
812
+						if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
813 813
 						{
814 814
 						    $this->trap_action.='Error sending status : check cmd/API';
815 815
 						}
816 816
 						else
817 817
 						{
818
-						    $this->add_rule_match($rule['id'],$rule['num_match']+1);
818
+						    $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
819 819
 						    $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
820 820
 						}
821 821
 					}
822 822
 					else
823 823
 					{
824
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
824
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
825 825
 					}
826
-					$this->trap_to_db=($action==-2)?false:true;
826
+					$this->trap_to_db=($action == -2) ?false:true;
827 827
 				}
828 828
 				else
829 829
 				{
830 830
 					//$this->logging->log('rules KOO : '.print_r($rule),INFO );
831 831
 					
832 832
 					$action=$rule['action_nomatch'];
833
-					$this->logging->log('action NOK : '.$action,INFO );
833
+					$this->logging->log('action NOK : '.$action, INFO);
834 834
 					if ($action >= 0)
835 835
 					{
836
-					    if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
836
+					    if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
837 837
 					    {
838 838
 					        $this->trap_action.='Error sending status : check cmd/API';
839 839
 					    }
840 840
 					    else
841 841
 					    {
842
-    						$this->add_rule_match($rule['id'],$rule['num_match']+1);
842
+    						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
843 843
     						$this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
844 844
 					    }
845 845
 					}
846 846
 					else
847 847
 					{
848
-						$this->add_rule_match($rule['id'],$rule['num_match']+1);
848
+						$this->add_rule_match($rule['id'], $rule['num_match'] + 1);
849 849
 					}
850
-					$this->trap_to_db=($action==-2)?false:true;					
850
+					$this->trap_to_db=($action == -2) ?false:true;					
851 851
 				}
852 852
 				// Put name in source_name
853 853
 				if (!isset($this->trap_data['source_name']))
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
 				}
857 857
 				else
858 858
 				{
859
-					if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
859
+					if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
860 860
 					{ // only add if not present
861 861
 						$this->trap_data['source_name'].=','.$rule['host_name'];
862 862
 					}
@@ -864,13 +864,13 @@  discard block
 block discarded – undo
864 864
 			}
865 865
 			catch (Exception $e) 
866 866
 			{ 
867
-			    $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
867
+			    $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
868 868
 			    $this->trap_action.=' ERR : '.$e->getMessage();
869 869
 			    $this->trap_data['status']='error';
870 870
 			}
871 871
 			
872 872
 		}
873
-		if ($this->trap_data['status']=='error')
873
+		if ($this->trap_data['status'] == 'error')
874 874
 		{
875 875
 		  $this->trap_to_db=true; // Always put errors in DB for the use can see
876 876
 		}
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 	public function add_rule_final($time)
887 887
 	{
888 888
 		$db_conn=$this->trapsDB->db_connect_trap();
889
-		if ($this->trap_action==null) 
889
+		if ($this->trap_action == null) 
890 890
 		{
891 891
 			$this->trap_action='No action';
892 892
 		}
893 893
 		$sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
894 894
 		if ($db_conn->query($sql) === false) {
895
-			$this->logging->log('Error in update query : ' . $sql,WARN,'');
895
+			$this->logging->log('Error in update query : '.$sql, WARN, '');
896 896
 		}
897 897
 	}
898 898
 	
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
     WHERE s.current_state != 0;";
916 916
 		$db_conn=$this->trapsDB->db_connect_ido();
917 917
 		if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
918
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,'');
918
+			$this->logging->log('No result in query : '.$sql_query, ERROR, '');
919 919
 			return 0;
920 920
 		}
921 921
 		$services=$services_db->fetchAll();
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 		$sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;";
925 925
 		$db_conn2=$this->trapsDB->db_connect_trap();
926 926
 		if (($rules_db=$db_conn2->query($sql_query)) === false) {
927
-			$this->logging->log('No result in query : ' . $sql_query,ERROR,'');
927
+			$this->logging->log('No result in query : '.$sql_query, ERROR, '');
928 928
 			return 0;
929 929
 		}
930 930
 		$rules=$rules_db->fetchAll();
@@ -940,13 +940,13 @@  discard block
 block discarded – undo
940 940
 					$service['host_name'] == $rule['host_name'] &&
941 941
 					($service['last_check'] + $rule['revert_ok']) < $now)
942 942
 				{
943
-					$this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
943
+					$this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
944 944
 					$numreset++;
945 945
 				}
946 946
 			}
947 947
 		}
948 948
 		echo "\n";
949
-		echo $numreset . " service(s) reset to OK\n";
949
+		echo $numreset." service(s) reset to OK\n";
950 950
 		return 0;
951 951
 		
952 952
 	}
Please login to merge, or discard this patch.
application/controllers/HandlerController.php 3 patches
Indentation   +235 added lines, -236 removed lines patch added patch discarded remove patch
@@ -11,13 +11,12 @@  discard block
 block discarded – undo
11 11
 
12 12
 //use Icinga\Web\Form as Form;
13 13
 /** Rules management
14
-
15
-*/
14
+ */
16 15
 class HandlerController extends TrapsController
17 16
 {
18 17
 
19 18
 	/** index : list existing rules 
20
-	*/
19
+	 */
21 20
 	public function indexAction()
22 21
 	{	
23 22
 		$this->checkReadPermission();
@@ -39,23 +38,23 @@  discard block
 block discarded – undo
39 38
 	 */
40 39
 	public function testruleAction()
41 40
 	{
42
-	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
44
-	        'active'	=> true,
45
-	        'label'		=> $this->translate('Test Rule'),
46
-	        'url'		=> Url::fromRequest()
47
-	    ));
41
+		$this->checkReadPermission();
42
+		$this->getTabs()->add('get',array(
43
+			'active'	=> true,
44
+			'label'		=> $this->translate('Test Rule'),
45
+			'url'		=> Url::fromRequest()
46
+		));
48 47
 	    
49
-	    //$db = $this->getDb();
48
+		//$db = $this->getDb();
50 49
 
51
-	    if ($this->params->get('rule') !== null) 
52
-	    {
53
-	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
56
-	    {
57
-	        $this->view->rule='';
58
-	    }
50
+		if ($this->params->get('rule') !== null) 
51
+		{
52
+			$this->view->rule= $this->params->get('rule');
53
+		}
54
+		else
55
+		{
56
+			$this->view->rule='';
57
+		}
59 58
 	}
60 59
 	
61 60
 	/**
@@ -63,31 +62,31 @@  discard block
 block discarded – undo
63 62
 	 */
64 63
 	private function add_setup_vars()
65 64
 	{
66
-	    // variables to send to view
67
-	    $this->view->hostlist=array(); // host list to input datalist
68
-	    $this->view->hostname=''; // Host name in input text
69
-	    $this->view->serviceGet=false; // Set to true to get list of service if only one host set
70
-	    $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
71
-	    $this->view->mainoid=''; // Trap OID
72
-	    $this->view->mib=''; // Trap mib
73
-	    $this->view->name=''; // Trap name
74
-	    $this->view->trapListForMIB=array(); // Trap list if mib exists for trap
75
-	    $this->view->objectList=array(); // objects sent with trap
76
-	    $this->view->display=''; // Initial display
77
-	    $this->view->rule=''; // rule display
78
-	    $this->view->revertOK=''; // revert OK in seconds
79
-	    $this->view->hostid=-1; // normally set by javascript serviceGet()
80
-	    $this->view->ruleid=-1; // Rule id in DB for update & delete
81
-	    $this->view->setToUpdate=false; // set form as update form
82
-	    $this->view->setRuleMatch=-1; // set action on rule match (default nothing)
83
-	    $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
65
+		// variables to send to view
66
+		$this->view->hostlist=array(); // host list to input datalist
67
+		$this->view->hostname=''; // Host name in input text
68
+		$this->view->serviceGet=false; // Set to true to get list of service if only one host set
69
+		$this->view->serviceSet=null; // Select service in services select (must have serviceGet=true).
70
+		$this->view->mainoid=''; // Trap OID
71
+		$this->view->mib=''; // Trap mib
72
+		$this->view->name=''; // Trap name
73
+		$this->view->trapListForMIB=array(); // Trap list if mib exists for trap
74
+		$this->view->objectList=array(); // objects sent with trap
75
+		$this->view->display=''; // Initial display
76
+		$this->view->rule=''; // rule display
77
+		$this->view->revertOK=''; // revert OK in seconds
78
+		$this->view->hostid=-1; // normally set by javascript serviceGet()
79
+		$this->view->ruleid=-1; // Rule id in DB for update & delete
80
+		$this->view->setToUpdate=false; // set form as update form
81
+		$this->view->setRuleMatch=-1; // set action on rule match (default nothing)
82
+		$this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing)
84 83
 	    
85
-	    $this->view->selectGroup=false; // Select by group if true
86
-	    $this->view->hostgroupid=-1; // host group id
87
-	    $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
84
+		$this->view->selectGroup=false; // Select by group if true
85
+		$this->view->hostgroupid=-1; // host group id
86
+		$this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one)
88 87
 	    
89
-	    $this->view->modifier=null;
90
-	    $this->view->modified=null;
88
+		$this->view->modifier=null;
89
+		$this->view->modified=null;
91 90
 	}
92 91
 	
93 92
 	/**
@@ -96,102 +95,102 @@  discard block
 block discarded – undo
96 95
 	 */
97 96
 	private function add_from_existing($trapid)
98 97
 	{
99
-	    /********** Setup from existing trap ***************/
100
-	    // Get the full trap info
101
-	    $trapDetail=$this->getTrapDetail($trapid);
98
+		/********** Setup from existing trap ***************/
99
+		// Get the full trap info
100
+		$trapDetail=$this->getTrapDetail($trapid);
102 101
 	    
103
-	    $hostfilter=$trapDetail->source_ip;
102
+		$hostfilter=$trapDetail->source_ip;
104 103
 	    
105
-	    // Get host
106
-	    try
107
-	    {
108
-	        $hosts=$this->getHostByIP($hostfilter);
109
-	    }
110
-	    catch (Exception $e)
111
-	    {
112
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113
-	    }
104
+		// Get host
105
+		try
106
+		{
107
+			$hosts=$this->getHostByIP($hostfilter);
108
+		}
109
+		catch (Exception $e)
110
+		{
111
+			$this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
112
+		}
114 113
 	    
115 114
 	    
116
-	    // if one unique host found -> put id text input
117
-	    if (count($hosts)==1) {
118
-	        $this->view->hostname=$hosts[0]->name;
119
-	        //$hostid=$hosts[0]->id;
120
-	        // Tell JS to get services when page is loaded
121
-	        $this->view->serviceGet=true;
115
+		// if one unique host found -> put id text input
116
+		if (count($hosts)==1) {
117
+			$this->view->hostname=$hosts[0]->name;
118
+			//$hostid=$hosts[0]->id;
119
+			// Tell JS to get services when page is loaded
120
+			$this->view->serviceGet=true;
122 121
 	        
123
-	    }
124
-	    else
125
-	    {
126
-	        foreach($hosts as $key=>$val)
127
-	        {
128
-	            array_push($this->view->hostlist,$hosts[$key]->name);
129
-	        }
130
-	    }
122
+		}
123
+		else
124
+		{
125
+			foreach($hosts as $key=>$val)
126
+			{
127
+				array_push($this->view->hostlist,$hosts[$key]->name);
128
+			}
129
+		}
131 130
 	    
132
-	    // set up trap oid and objects received by the trap
131
+		// set up trap oid and objects received by the trap
133 132
 	    
134
-	    $this->view->mainoid=$trapDetail->trap_oid;
135
-	    if ($trapDetail->trap_name_mib != null)
136
-	    {
137
-	        $this->view->mib=$trapDetail->trap_name_mib;
138
-	        $this->view->name=$trapDetail->trap_name;
139
-	        $this->view->trapListForMIB=$this->getMIB()
140
-	        ->getTrapList($trapDetail->trap_name_mib);
141
-	    }
133
+		$this->view->mainoid=$trapDetail->trap_oid;
134
+		if ($trapDetail->trap_name_mib != null)
135
+		{
136
+			$this->view->mib=$trapDetail->trap_name_mib;
137
+			$this->view->name=$trapDetail->trap_name;
138
+			$this->view->trapListForMIB=$this->getMIB()
139
+			->getTrapList($trapDetail->trap_name_mib);
140
+		}
142 141
 	    
143
-	    // Get all objects that can be in trap from MIB
144
-	    $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
145
-	    // Get all objects in current Trap
146
-	    $currentTrapObjects=$this->getTrapobjects($trapid);
147
-	    $oid_index=1;
148
-	    foreach ($currentTrapObjects as $key => $val)
149
-	    {
150
-	        $currentObjectType='Unknown';
151
-	        $currentObjectTypeEnum='Unknown';
152
-	        if (isset($allObjects[$val->oid]['type']))
153
-	        {
154
-	            $currentObjectType=$allObjects[$val->oid]['type'];
155
-	            $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
156
-	        }
157
-	        $currentObject=array(
158
-	            $oid_index,
159
-	            $val->oid,
160
-	            $val->oid_name_mib,
161
-	            $val->oid_name,
162
-	            $val->value,
163
-	            $currentObjectType,
164
-	            $currentObjectTypeEnum
165
-	        );
166
-	        $oid_index++;
167
-	        array_push($this->view->objectList,$currentObject);
168
-	        // set currrent object to null in allObjects
169
-	        if (isset($allObjects[$val->oid]))
170
-	        {
171
-	            $allObjects[$val->oid]=null;
172
-	        }
173
-	    }
174
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
175
-	    {
176
-	        foreach ($allObjects as $key => $val)
177
-	        {
178
-	            if ($val==null) { continue; }
179
-	            array_push($this->view->objectList, array(
180
-	                $oid_index,
181
-	                $key,
182
-	                $allObjects[$key]['mib'],
183
-	                $allObjects[$key]['name'],
184
-	                '',
185
-	                $allObjects[$key]['type'],
186
-	                $allObjects[$key]['type_enum']
187
-	            ));
188
-	            $oid_index++;
189
-	        }
190
-	    }
142
+		// Get all objects that can be in trap from MIB
143
+		$allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid);
144
+		// Get all objects in current Trap
145
+		$currentTrapObjects=$this->getTrapobjects($trapid);
146
+		$oid_index=1;
147
+		foreach ($currentTrapObjects as $key => $val)
148
+		{
149
+			$currentObjectType='Unknown';
150
+			$currentObjectTypeEnum='Unknown';
151
+			if (isset($allObjects[$val->oid]['type']))
152
+			{
153
+				$currentObjectType=$allObjects[$val->oid]['type'];
154
+				$currentObjectTypeEnum=$allObjects[$val->oid]['type_enum'];
155
+			}
156
+			$currentObject=array(
157
+				$oid_index,
158
+				$val->oid,
159
+				$val->oid_name_mib,
160
+				$val->oid_name,
161
+				$val->value,
162
+				$currentObjectType,
163
+				$currentObjectTypeEnum
164
+			);
165
+			$oid_index++;
166
+			array_push($this->view->objectList,$currentObject);
167
+			// set currrent object to null in allObjects
168
+			if (isset($allObjects[$val->oid]))
169
+			{
170
+				$allObjects[$val->oid]=null;
171
+			}
172
+		}
173
+		if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+		{
175
+			foreach ($allObjects as $key => $val)
176
+			{
177
+				if ($val==null) { continue; }
178
+				array_push($this->view->objectList, array(
179
+					$oid_index,
180
+					$key,
181
+					$allObjects[$key]['mib'],
182
+					$allObjects[$key]['name'],
183
+					'',
184
+					$allObjects[$key]['type'],
185
+					$allObjects[$key]['type_enum']
186
+				));
187
+				$oid_index++;
188
+			}
189
+		}
191 190
 	    
192
-	    // Add a simple display
193
-	    $this->view->display='Trap '.$trapDetail->trap_name.' received';
194
-	    $this->view->create_basic_rule=true;
191
+		// Add a simple display
192
+		$this->view->display='Trap '.$trapDetail->trap_name.' received';
193
+		$this->view->create_basic_rule=true;
195 194
 	}
196 195
 
197 196
 	/**
@@ -200,29 +199,29 @@  discard block
 block discarded – undo
200 199
 	 */
201 200
 	private function add_check_host_exists($ruleDetail)
202 201
 	{
203
-	    // Check if hostname still exists
204
-	    $host_get=$this->getHostByName($this->view->hostname);
202
+		// Check if hostname still exists
203
+		$host_get=$this->getHostByName($this->view->hostname);
205 204
 	    
206
-	    if (count($host_get)==0)
207
-	    {
208
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209
-	        $this->view->serviceGet=false;
210
-	    }
211
-	    else
212
-	    {
213
-	        // Tell JS to get services when page is loaded
214
-	        $this->view->serviceGet=true;
215
-	        // get service id for form to set :
216
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
-	        if (count($serviceID) ==0)
218
-	        {
219
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
-	        }
221
-	        else
222
-	        {
223
-	            $this->view->serviceSet=$serviceID[0]->id;
224
-	        }
225
-	    }
205
+		if (count($host_get)==0)
206
+		{
207
+			$this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
208
+			$this->view->serviceGet=false;
209
+		}
210
+		else
211
+		{
212
+			// Tell JS to get services when page is loaded
213
+			$this->view->serviceGet=true;
214
+			// get service id for form to set :
215
+			$serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
216
+			if (count($serviceID) ==0)
217
+			{
218
+				$this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
219
+			}
220
+			else
221
+			{
222
+				$this->view->serviceSet=$serviceID[0]->id;
223
+			}
224
+		}
226 225
 	}
227 226
 
228 227
 	/**
@@ -231,33 +230,33 @@  discard block
 block discarded – undo
231 230
 	 */
232 231
 	private function add_check_hostgroup_exists($ruleDetail)
233 232
 	{
234
-	    // Check if groupe exists
235
-	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
236
-	    if (count($group_get)==0)
237
-	    {
238
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239
-	        $this->view->serviceGroupGet=false;
240
-	    }
241
-	    else
242
-	    {
243
-	        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
244
-	        $foundGrpService=0;
245
-	        foreach ($grpServices as $grpService)
246
-	        {
247
-	            if ($grpService[0] == $ruleDetail->service_name)
248
-	            {
249
-	                $foundGrpService=1;
250
-	                $this->view->serviceSet=$ruleDetail->service_name;
251
-	            }
252
-	        }
233
+		// Check if groupe exists
234
+		$group_get=$this->getHostGroupByName($this->view->hostgroupname);
235
+		if (count($group_get)==0)
236
+		{
237
+			$this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
238
+			$this->view->serviceGroupGet=false;
239
+		}
240
+		else
241
+		{
242
+			$grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
243
+			$foundGrpService=0;
244
+			foreach ($grpServices as $grpService)
245
+			{
246
+				if ($grpService[0] == $ruleDetail->service_name)
247
+				{
248
+					$foundGrpService=1;
249
+					$this->view->serviceSet=$ruleDetail->service_name;
250
+				}
251
+			}
253 252
 	        
254
-	        // Tell JS to get services when page is loaded
255
-	        $this->view->serviceGroupGet=true;
256
-	        if ($foundGrpService==0)
257
-	        {
258
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
259
-	        }
260
-	    }
253
+			// Tell JS to get services when page is loaded
254
+			$this->view->serviceGroupGet=true;
255
+			if ($foundGrpService==0)
256
+			{
257
+				$this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
258
+			}
259
+		}
261 260
 	}
262 261
 	
263 262
 	/**
@@ -269,48 +268,48 @@  discard block
 block discarded – undo
269 268
 	 */
270 269
 	private function add_create_trap_object_list(&$display, &$rule)
271 270
 	{
272
-	    $curObjectList=array();
273
-	    $index=1;
274
-	    // check in display & rule for : OID(<oid>)
275
-	    $matches=array();
276
-	    while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
277
-	        preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
278
-	    {
279
-	        $curOid=$matches[1];
280
-	        if (($object=$this->getMIB()->translateOID($curOid)) != null)
281
-	        {
282
-	            array_push($curObjectList, array(
283
-	                $index,
284
-	                $curOid,
285
-	                $object['mib'],
286
-	                $object['name'],
287
-	                '',
288
-	                $object['type'],
289
-	                $object['type_enum']
290
-	            ));
291
-	        }
292
-	        else
293
-	        {
294
-	            array_push($curObjectList, array(
295
-	                $index,
296
-	                $curOid,
297
-	                'not found',
298
-	                'not found',
299
-	                '',
300
-	                'not found'
301
-	            ));
302
-	        }
303
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
304
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
305
-	        $index++;
306
-	    }
307
-	    return $curObjectList;
271
+		$curObjectList=array();
272
+		$index=1;
273
+		// check in display & rule for : OID(<oid>)
274
+		$matches=array();
275
+		while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
276
+			preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
277
+		{
278
+			$curOid=$matches[1];
279
+			if (($object=$this->getMIB()->translateOID($curOid)) != null)
280
+			{
281
+				array_push($curObjectList, array(
282
+					$index,
283
+					$curOid,
284
+					$object['mib'],
285
+					$object['name'],
286
+					'',
287
+					$object['type'],
288
+					$object['type_enum']
289
+				));
290
+			}
291
+			else
292
+			{
293
+				array_push($curObjectList, array(
294
+					$index,
295
+					$curOid,
296
+					'not found',
297
+					'not found',
298
+					'',
299
+					'not found'
300
+				));
301
+			}
302
+			$display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
303
+			$rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
304
+			$index++;
305
+		}
306
+		return $curObjectList;
308 307
 	}
309 308
 	
310 309
 	/** Add a handler  
311
-	*	Get params fromid : setup from existing trap (id of trap table)
312
-	*	Get param ruleid : edit from existing handler (id of rule table)
313
-	*/
310
+	 *	Get params fromid : setup from existing trap (id of trap table)
311
+	 *	Get param ruleid : edit from existing handler (id of rule table)
312
+	 */
314 313
 	public function addAction()
315 314
 	{
316 315
 		$this->checkConfigPermission();
@@ -329,8 +328,8 @@  discard block
 block discarded – undo
329 328
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
330 329
 		
331 330
 		if (($trapid = $this->params->get('fromid')) !== null) {
332
-		    /********** Setup from existing trap ***************/
333
-            $this->add_from_existing($trapid);
331
+			/********** Setup from existing trap ***************/
332
+			$this->add_from_existing($trapid);
334 333
 			return;
335 334
 		}
336 335
 		
@@ -355,14 +354,14 @@  discard block
 block discarded – undo
355 354
 			$this->view->warning_message='';
356 355
 			if ($this->view->hostname != null)
357 356
 			{
358
-			    $this->view->selectGroup=false;
359
-			    // Check if hostname still exists
360
-			    $this->add_check_host_exists($ruleDetail);
357
+				$this->view->selectGroup=false;
358
+				// Check if hostname still exists
359
+				$this->add_check_host_exists($ruleDetail);
361 360
 			}
362 361
 			else
363 362
 			{
364
-			    $this->view->selectGroup=true;
365
-			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
363
+				$this->view->selectGroup=true;
364
+				$this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
366 365
 			}
367 366
 			
368 367
 			$this->view->mainoid=$ruleDetail->trap_oid;
@@ -390,9 +389,9 @@  discard block
 block discarded – undo
390 389
 	}
391 390
 	
392 391
 	/** Validate form and output message to user  
393
-	*	@param in postdata 
394
-	* 	@return string status : OK / <Message>
395
-	**/
392
+	 *	@param in postdata 
393
+	 * 	@return string status : OK / <Message>
394
+	 **/
396 395
 	protected function handlerformAction()
397 396
 	{
398 397
 		$postData=$this->getRequest()->getPost();
@@ -433,7 +432,7 @@  discard block
 block discarded – undo
433 432
 			//$this->Module()->
434 433
 			$this->_helper->json(array(
435 434
 				'status'=>'OK',
436
-			    'redirect'=>'trapdirector/handler'
435
+				'redirect'=>'trapdirector/handler'
437 436
 			      
438 437
 			));
439 438
 		}		
@@ -517,9 +516,9 @@  discard block
 block discarded – undo
517 516
 	}
518 517
 
519 518
 	/** Get trap detail by trapid. 
520
-	*	@param integer $trapid : id of trap in received table
521
-	*	@return array (objects)
522
-	*/
519
+	 *	@param integer $trapid : id of trap in received table
520
+	 *	@return array (objects)
521
+	 */
523 522
 	protected function getTrapDetail($trapid) 
524 523
 	{
525 524
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -551,9 +550,9 @@  discard block
 block discarded – undo
551 550
 	}
552 551
 
553 552
 	/** Get trap objects
554
-	*	@param integer $trapid : trap id
555
-	* 	@return array : full column in db of trap id
556
-	*/
553
+	 *	@param integer $trapid : trap id
554
+	 * 	@return array : full column in db of trap id
555
+	 */
557 556
 	protected function getTrapobjects($trapid)
558 557
 	{	
559 558
 		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
@@ -584,9 +583,9 @@  discard block
 block discarded – undo
584 583
 	}
585 584
 
586 585
 	/** Get rule detail by ruleid.
587
-	*	@param integer $ruleid int id of rule in rule table
588
-	*	@return array : column objects in db
589
-	*/
586
+	 *	@param integer $ruleid int id of rule in rule table
587
+	 *	@return array : column objects in db
588
+	 */
590 589
 	protected function getRuleDetail($ruleid) 
591 590
 	{
592 591
 		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
@@ -613,7 +612,7 @@  discard block
 block discarded – undo
613 612
 	}
614 613
 
615 614
 	/** Setup tabs for rules 
616
-	*/
615
+	 */
617 616
 	protected function prepareTabs()
618 617
 	{
619 618
 		return $this->getTabs()->add('status', array(
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		$this->checkReadPermission();
24 24
 		$this->prepareTabs()->activate('status');
25 25
 
26
-		$db = $this->getDb();
26
+		$db=$this->getDb();
27 27
 		$this->getHandlerListTable()->setConnection($db);
28 28
 		$this->getHandlerListTable()->setMibloader($this->getMIB());
29 29
 		// Apply pagination limits 
30
-		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay());		
30
+		$this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay());		
31 31
 		
32 32
 		// Set Filter
33
-		$this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest());		
33
+		$this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest());		
34 34
 	
35 35
 		//$this->displayExitError('Handler/indexAction','Not implemented');
36 36
 	}
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	public function testruleAction()
41 41
 	{
42 42
 	    $this->checkReadPermission();
43
-	    $this->getTabs()->add('get',array(
43
+	    $this->getTabs()->add('get', array(
44 44
 	        'active'	=> true,
45 45
 	        'label'		=> $this->translate('Test Rule'),
46 46
 	        'url'		=> Url::fromRequest()
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53
-	        $this->view->rule= $this->params->get('rule');
53
+	        $this->view->rule=$this->params->get('rule');
54 54
 	    }
55 55
 	    else
56 56
 	    {
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
 	    }
110 110
 	    catch (Exception $e)
111 111
 	    {
112
-	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
112
+	        $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage());
113 113
 	    }
114 114
 	    
115 115
 	    
116 116
 	    // if one unique host found -> put id text input
117
-	    if (count($hosts)==1) {
117
+	    if (count($hosts) == 1) {
118 118
 	        $this->view->hostname=$hosts[0]->name;
119 119
 	        //$hostid=$hosts[0]->id;
120 120
 	        // Tell JS to get services when page is loaded
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
 	    }
124 124
 	    else
125 125
 	    {
126
-	        foreach($hosts as $key=>$val)
126
+	        foreach ($hosts as $key=>$val)
127 127
 	        {
128
-	            array_push($this->view->hostlist,$hosts[$key]->name);
128
+	            array_push($this->view->hostlist, $hosts[$key]->name);
129 129
 	        }
130 130
 	    }
131 131
 	    
@@ -164,18 +164,18 @@  discard block
 block discarded – undo
164 164
 	            $currentObjectTypeEnum
165 165
 	        );
166 166
 	        $oid_index++;
167
-	        array_push($this->view->objectList,$currentObject);
167
+	        array_push($this->view->objectList, $currentObject);
168 168
 	        // set currrent object to null in allObjects
169 169
 	        if (isset($allObjects[$val->oid]))
170 170
 	        {
171 171
 	            $allObjects[$val->oid]=null;
172 172
 	        }
173 173
 	    }
174
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
174
+	    if ($allObjects != null) // in case trap doesn't have objects or is not resolved
175 175
 	    {
176 176
 	        foreach ($allObjects as $key => $val)
177 177
 	        {
178
-	            if ($val==null) { continue; }
178
+	            if ($val == null) { continue; }
179 179
 	            array_push($this->view->objectList, array(
180 180
 	                $oid_index,
181 181
 	                $key,
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 	    // Check if hostname still exists
204 204
 	    $host_get=$this->getHostByName($this->view->hostname);
205 205
 	    
206
-	    if (count($host_get)==0)
206
+	    if (count($host_get) == 0)
207 207
 	    {
208
-	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
208
+	        $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore';
209 209
 	        $this->view->serviceGet=false;
210 210
 	    }
211 211
 	    else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	        // Tell JS to get services when page is loaded
214 214
 	        $this->view->serviceGet=true;
215 215
 	        // get service id for form to set :
216
-	        $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name);
217
-	        if (count($serviceID) ==0)
216
+	        $serviceID=$this->getServiceIDByName($this->view->hostname, $ruleDetail->service_name);
217
+	        if (count($serviceID) == 0)
218 218
 	        {
219
-	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
219
+	            $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
220 220
 	        }
221 221
 	        else
222 222
 	        {
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	{
234 234
 	    // Check if groupe exists
235 235
 	    $group_get=$this->getHostGroupByName($this->view->hostgroupname);
236
-	    if (count($group_get)==0)
236
+	    if (count($group_get) == 0)
237 237
 	    {
238
-	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
238
+	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore';
239 239
 	        $this->view->serviceGroupGet=false;
240 240
 	    }
241 241
 	    else
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
 	        
254 254
 	        // Tell JS to get services when page is loaded
255 255
 	        $this->view->serviceGroupGet=true;
256
-	        if ($foundGrpService==0)
256
+	        if ($foundGrpService == 0)
257 257
 	        {
258
-	            $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
258
+	            $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore';
259 259
 	        }
260 260
 	    }
261 261
 	}
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	    $index=1;
274 274
 	    // check in display & rule for : OID(<oid>)
275 275
 	    $matches=array();
276
-	    while ( preg_match('/_OID\(([\.0-9]+)\)/',$display,$matches) ||
277
-	        preg_match('/_OID\(([\.0-9]+)\)/',$rule,$matches))
276
+	    while (preg_match('/_OID\(([\.0-9]+)\)/', $display, $matches) ||
277
+	        preg_match('/_OID\(([\.0-9]+)\)/', $rule, $matches))
278 278
 	    {
279 279
 	        $curOid=$matches[1];
280 280
 	        if (($object=$this->getMIB()->translateOID($curOid)) != null)
@@ -300,8 +300,8 @@  discard block
 block discarded – undo
300 300
 	                'not found'
301 301
 	            ));
302 302
 	        }
303
-	        $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display);
304
-	        $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule);
303
+	        $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display);
304
+	        $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule);
305 305
 	        $index++;
306 306
 	    }
307 307
 	    return $curObjectList;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	{
316 316
 		$this->checkConfigPermission();
317 317
 		// set up tab
318
-		$this->getTabs()->add('get',array(
318
+		$this->getTabs()->add('get', array(
319 319
 			'active'	=> true,
320 320
 			'label'		=> $this->translate('Add handler'),
321 321
 			'url'		=> Url::fromRequest()
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 		
329 329
 		//$this->view->trapvalues=false; // Set to true to display 'value' colum in objects
330 330
 		
331
-		if (($trapid = $this->params->get('fromid')) !== null) {
331
+		if (($trapid=$this->params->get('fromid')) !== null) {
332 332
 		    /********** Setup from existing trap ***************/
333 333
             $this->add_from_existing($trapid);
334 334
 			return;
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
 			$this->view->setRuleMatch=$ruleDetail->action_match;
349 349
 			$this->view->setRuleNoMatch=$ruleDetail->action_nomatch;
350 350
 			$this->view->hostgroupname=$ruleDetail->host_group_name;
351
-			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified);
351
+			$this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified);
352 352
 			$this->view->modifier=$ruleDetail->modifier;
353 353
 			
354 354
 			// Warning message if host/service don't exists anymore
@@ -400,26 +400,26 @@  discard block
 block discarded – undo
400 400
 	
401 401
 		$params=array(
402 402
 			// id (also db) => 	array('post' => post id, 'val' => default val, 'db' => send to table)
403
-			'hostgroup'		=>	array('post' => 'hostgroup','db'=>false),
404
-			'db_rule'		=>	array('post' => 'db_rule','db'=>false),
405
-			'hostid'		=>	array('post' => 'hostid','db'=>false),
406
-			'host_name'		=>	array('post' => 'hostname','val' => null,'db'=>true),
407
-			'host_group_name'=>	array('post' => null,'val' => null,'db'=>true),
408
-			'serviceid'		=>	array('post' => 'serviceid','db'=>false),
409
-			'service_name'	=>	array('post' => 'serviceName','db'=>true),
410
-			'trap_oid'		=>	array('post' => 'oid','db'=>true),
411
-			'revert_ok'		=>	array('post' => 'revertOK','val' => 0,'db'=>true),
412
-			'display'		=>	array('post' => 'display','val' => '','db'=>true),
413
-			'rule'			=>	array('post' => 'rule','val' => '','db'=>true),			
414
-			'action_match'	=>	array('post' => 'ruleMatch','val' => -1,'db'=>true),
415
-			'action_nomatch'=>	array('post' => 'ruleNoMatch','val' => -1,'db'=>true),					
416
-			'ip4'			=>	array('post' => null,'val' => null,'db'=>true),
417
-			'ip6'			=>	array('post' => null,'val' => null,'db'=>true),
418
-			'action_form'	=>	array('post' => 'action_form','db'=>false)
403
+			'hostgroup'		=>	array('post' => 'hostgroup', 'db'=>false),
404
+			'db_rule'		=>	array('post' => 'db_rule', 'db'=>false),
405
+			'hostid'		=>	array('post' => 'hostid', 'db'=>false),
406
+			'host_name'		=>	array('post' => 'hostname', 'val' => null, 'db'=>true),
407
+			'host_group_name'=>	array('post' => null, 'val' => null, 'db'=>true),
408
+			'serviceid'		=>	array('post' => 'serviceid', 'db'=>false),
409
+			'service_name'	=>	array('post' => 'serviceName', 'db'=>true),
410
+			'trap_oid'		=>	array('post' => 'oid', 'db'=>true),
411
+			'revert_ok'		=>	array('post' => 'revertOK', 'val' => 0, 'db'=>true),
412
+			'display'		=>	array('post' => 'display', 'val' => '', 'db'=>true),
413
+			'rule'			=>	array('post' => 'rule', 'val' => '', 'db'=>true),			
414
+			'action_match'	=>	array('post' => 'ruleMatch', 'val' => -1, 'db'=>true),
415
+			'action_nomatch'=>	array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true),					
416
+			'ip4'			=>	array('post' => null, 'val' => null, 'db'=>true),
417
+			'ip6'			=>	array('post' => null, 'val' => null, 'db'=>true),
418
+			'action_form'	=>	array('post' => 'action_form', 'db'=>false)
419 419
 		);
420 420
 		
421 421
 		if (isset($postData[$params['action_form']['post']]) 
422
-			&& $postData[$params['action_form']['post']] == 'delete' )
422
+			&& $postData[$params['action_form']['post']] == 'delete')
423 423
 		{
424 424
 			try
425 425
 			{
@@ -439,16 +439,16 @@  discard block
 block discarded – undo
439 439
 		}		
440 440
 		foreach (array_keys($params) as $key)
441 441
 		{
442
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
443
-			if (! isset($postData[$params[$key]['post']]))
442
+			if ($params[$key]['post'] == null) continue; // data not sent in post vars
443
+			if (!isset($postData[$params[$key]['post']]))
444 444
 			{
445 445
 				// should not happen as the js checks data
446
-				$this->_helper->json(array('status'=>'No ' . $key));
446
+				$this->_helper->json(array('status'=>'No '.$key));
447 447
 			}
448 448
 			else
449 449
 			{
450 450
 				$data=$postData[$params[$key]['post']];
451
-				if ($data!=null && $data !="")
451
+				if ($data != null && $data != "")
452 452
 				{
453 453
 					$params[$key]['val']=$postData[$params[$key]['post']];
454 454
 				}
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 
458 458
 		try 
459 459
 		{
460
-			$isHostGroup=($params['hostgroup']['val'] == 1)?true:false;
461
-			if (! $isHostGroup ) 
460
+			$isHostGroup=($params['hostgroup']['val'] == 1) ?true:false;
461
+			if (!$isHostGroup) 
462 462
 			{  // checks if selection by host 
463 463
 				$hostAddr=$this->getHostInfoByID($params['hostid']['val']);
464 464
 				$params['ip4']['val']=$hostAddr->ip4;
@@ -485,25 +485,25 @@  discard block
 block discarded – undo
485 485
 					return;					
486 486
 				}
487 487
 				// Put param in correct column (group_name)
488
-				$params['host_group_name']['val'] = $params['host_name']['val'];
488
+				$params['host_group_name']['val']=$params['host_name']['val'];
489 489
 				$params['host_name']['val']=null;
490 490
 			}
491 491
 			$dbparams=array();
492 492
 			foreach ($params as $key=>$val)
493 493
 			{
494
-				if ($val['db']==true )
494
+				if ($val['db'] == true)
495 495
 				{
496
-					$dbparams[$key] = $val['val'];
496
+					$dbparams[$key]=$val['val'];
497 497
 				}
498 498
 			}
499 499
 			// echo '<br>';	print_r($dbparams);echo '<br>';
500
-			if ($params['db_rule']['val'] == -1 ) 
500
+			if ($params['db_rule']['val'] == -1) 
501 501
 			{
502 502
 				$ruleID=$this->addHandlerRule($dbparams);
503 503
 			}
504 504
 			else
505 505
 			{
506
-				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
506
+				$this->updateHandlerRule($dbparams, $params['db_rule']['val']);
507 507
 				$ruleID=$params['db_rule']['val'];
508 508
 			}
509 509
 		}
@@ -522,10 +522,10 @@  discard block
 block discarded – undo
522 522
 	*/
523 523
 	protected function getTrapDetail($trapid) 
524 524
 	{
525
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
525
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
526 526
 		$queryArray=$this->getModuleConfig()->trapDetailQuery();
527 527
 		
528
-		$db = $this->getDb()->getConnection();
528
+		$db=$this->getDb()->getConnection();
529 529
 		// ***************  Get main data
530 530
 		// extract columns and titles;
531 531
 		$elmts=NULL;
@@ -534,15 +534,15 @@  discard block
 block discarded – undo
534 534
 		}
535 535
 		try
536 536
 		{		
537
-			$query = $db->select()
538
-				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
539
-				->where('id=?',$trapid);
537
+			$query=$db->select()
538
+				->from($this->getModuleConfig()->getTrapTableName(), $elmts)
539
+				->where('id=?', $trapid);
540 540
 			$trapDetail=$db->fetchRow($query);
541
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
541
+			if ($trapDetail == null) throw new Exception('No traps was found with id = '.$trapid);
542 542
 		}
543 543
 		catch (Exception $e)
544 544
 		{
545
-			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
545
+			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage());
546 546
 			return;
547 547
 		}
548 548
 
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
 	*/
557 557
 	protected function getTrapobjects($trapid)
558 558
 	{	
559
-		if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id');  }
559
+		if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); }
560 560
 		$queryArrayData=$this->getModuleConfig()->trapDataDetailQuery();
561 561
 		
562
-		$db = $this->getDb()->getConnection();
562
+		$db=$this->getDb()->getConnection();
563 563
 		// ***************  Get object data
564 564
 		// extract columns and titles;
565 565
 		$data_elmts=NULL;
@@ -568,15 +568,15 @@  discard block
 block discarded – undo
568 568
 		}
569 569
 		try
570 570
 		{		
571
-			$query = $db->select()
572
-				->from($this->moduleConfig->getTrapDataTableName(),$data_elmts)
573
-				->where('trap_id=?',$trapid);
571
+			$query=$db->select()
572
+				->from($this->moduleConfig->getTrapDataTableName(), $data_elmts)
573
+				->where('trap_id=?', $trapid);
574 574
 			$trapDetail=$db->fetchAll($query);
575 575
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
576 576
 		}
577 577
 		catch (Exception $e)
578 578
 		{
579
-			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
579
+			$this->displayExitError('Add handler : get trap data detail : ', $e->getMessage());
580 580
 			return array();
581 581
 		}
582 582
 
@@ -589,22 +589,22 @@  discard block
 block discarded – undo
589 589
 	*/
590 590
 	protected function getRuleDetail($ruleid) 
591 591
 	{
592
-		if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id');  }
592
+		if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); }
593 593
 		$queryArray=$this->getModuleConfig()->ruleDetailQuery();
594 594
 		
595
-		$db = $this->getDb()->getConnection();
595
+		$db=$this->getDb()->getConnection();
596 596
 		// ***************  Get main data
597 597
 		try
598 598
 		{		
599
-			$query = $db->select()
600
-				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
601
-				->where('id=?',$ruleid);
599
+			$query=$db->select()
600
+				->from($this->getModuleConfig()->getTrapRuleName(), $queryArray)
601
+				->where('id=?', $ruleid);
602 602
 			$ruleDetail=$db->fetchRow($query);
603
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
603
+			if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid);
604 604
 		}
605 605
 		catch (Exception $e)
606 606
 		{
607
-			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
607
+			$this->displayExitError('Update handler : get rule detail', $e->getMessage());
608 608
 			return array();
609 609
 		}
610 610
 
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	{
619 619
 		return $this->getTabs()->add('status', array(
620 620
 			'label' => $this->translate('Traps'),
621
-			'url'   => $this->getModuleConfig()->urlPath() . '/handler')
621
+			'url'   => $this->getModuleConfig()->urlPath().'/handler')
622 622
 		);
623 623
 	} 
624 624
 	
Please login to merge, or discard this patch.
Braces   +35 added lines, -39 removed lines patch added patch discarded remove patch
@@ -51,8 +51,7 @@  discard block
 block discarded – undo
51 51
 	    if ($this->params->get('rule') !== null) 
52 52
 	    {
53 53
 	        $this->view->rule= $this->params->get('rule');
54
-	    }
55
-	    else
54
+	    } else
56 55
 	    {
57 56
 	        $this->view->rule='';
58 57
 	    }
@@ -106,8 +105,7 @@  discard block
 block discarded – undo
106 105
 	    try
107 106
 	    {
108 107
 	        $hosts=$this->getHostByIP($hostfilter);
109
-	    }
110
-	    catch (Exception $e)
108
+	    } catch (Exception $e)
111 109
 	    {
112 110
 	        $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage());
113 111
 	    }
@@ -120,8 +118,7 @@  discard block
 block discarded – undo
120 118
 	        // Tell JS to get services when page is loaded
121 119
 	        $this->view->serviceGet=true;
122 120
 	        
123
-	    }
124
-	    else
121
+	    } else
125 122
 	    {
126 123
 	        foreach($hosts as $key=>$val)
127 124
 	        {
@@ -171,11 +168,14 @@  discard block
 block discarded – undo
171 168
 	            $allObjects[$val->oid]=null;
172 169
 	        }
173 170
 	    }
174
-	    if ($allObjects!=null) // in case trap doesn't have objects or is not resolved
171
+	    if ($allObjects!=null) {
172
+	    	// in case trap doesn't have objects or is not resolved
175 173
 	    {
176 174
 	        foreach ($allObjects as $key => $val)
177 175
 	        {
178
-	            if ($val==null) { continue; }
176
+	            if ($val==null) { continue;
177
+	    }
178
+	    }
179 179
 	            array_push($this->view->objectList, array(
180 180
 	                $oid_index,
181 181
 	                $key,
@@ -207,8 +207,7 @@  discard block
 block discarded – undo
207 207
 	    {
208 208
 	        $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore';
209 209
 	        $this->view->serviceGet=false;
210
-	    }
211
-	    else
210
+	    } else
212 211
 	    {
213 212
 	        // Tell JS to get services when page is loaded
214 213
 	        $this->view->serviceGet=true;
@@ -217,8 +216,7 @@  discard block
 block discarded – undo
217 216
 	        if (count($serviceID) ==0)
218 217
 	        {
219 218
 	            $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore';
220
-	        }
221
-	        else
219
+	        } else
222 220
 	        {
223 221
 	            $this->view->serviceSet=$serviceID[0]->id;
224 222
 	        }
@@ -237,8 +235,7 @@  discard block
 block discarded – undo
237 235
 	    {
238 236
 	        $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore';
239 237
 	        $this->view->serviceGroupGet=false;
240
-	    }
241
-	    else
238
+	    } else
242 239
 	    {
243 240
 	        $grpServices=$this->getServicesByHostGroupid($group_get[0]->id);
244 241
 	        $foundGrpService=0;
@@ -288,8 +285,7 @@  discard block
 block discarded – undo
288 285
 	                $object['type'],
289 286
 	                $object['type_enum']
290 287
 	            ));
291
-	        }
292
-	        else
288
+	        } else
293 289
 	        {
294 290
 	            array_push($curObjectList, array(
295 291
 	                $index,
@@ -358,8 +354,7 @@  discard block
 block discarded – undo
358 354
 			    $this->view->selectGroup=false;
359 355
 			    // Check if hostname still exists
360 356
 			    $this->add_check_host_exists($ruleDetail);
361
-			}
362
-			else
357
+			} else
363 358
 			{
364 359
 			    $this->view->selectGroup=true;
365 360
 			    $this->add_check_hostgroup_exists($ruleDetail); //  Check if groupe exists				
@@ -367,9 +362,11 @@  discard block
 block discarded – undo
367 362
 			
368 363
 			$this->view->mainoid=$ruleDetail->trap_oid;
369 364
 			$oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid);
370
-			if ($oidName != null)  // oid is found in mibs
365
+			if ($oidName != null) {
366
+				// oid is found in mibs
371 367
 			{
372
-				$this->view->mib=$oidName['mib']; 
368
+				$this->view->mib=$oidName['mib'];
369
+			}
373 370
 				$this->view->name=$oidName['name'];
374 371
 				$this->view->trapListForMIB=$this->getMIB()
375 372
 					->getTrapList($oidName['mib']);				
@@ -424,8 +421,7 @@  discard block
 block discarded – undo
424 421
 			try
425 422
 			{
426 423
 				$this->deleteRule($postData[$params['db_rule']['post']]);
427
-			}
428
-			catch (Exception $e)
424
+			} catch (Exception $e)
429 425
 			{
430 426
 				$this->_helper->json(array('status'=>$e->getMessage()));
431 427
 				return;
@@ -439,13 +435,15 @@  discard block
 block discarded – undo
439 435
 		}		
440 436
 		foreach (array_keys($params) as $key)
441 437
 		{
442
-			if ($params[$key]['post']==null) continue; // data not sent in post vars
438
+			if ($params[$key]['post']==null) {
439
+				continue;
440
+			}
441
+			// data not sent in post vars
443 442
 			if (! isset($postData[$params[$key]['post']]))
444 443
 			{
445 444
 				// should not happen as the js checks data
446 445
 				$this->_helper->json(array('status'=>'No ' . $key));
447
-			}
448
-			else
446
+			} else
449 447
 			{
450 448
 				$data=$postData[$params[$key]['post']];
451 449
 				if ($data!=null && $data !="")
@@ -475,8 +473,7 @@  discard block
 block discarded – undo
475 473
 					$this->_helper->json(array('status'=>"Invalid service id : Please re enter service"));
476 474
 					return;
477 475
 				}
478
-			}
479
-			else
476
+			} else
480 477
 			{
481 478
 				$object=$this->getObjectNameByid($params['hostid']['val']);
482 479
 				if ($params['host_name']['val'] != $object->name1)
@@ -500,14 +497,12 @@  discard block
 block discarded – undo
500 497
 			if ($params['db_rule']['val'] == -1 ) 
501 498
 			{
502 499
 				$ruleID=$this->addHandlerRule($dbparams);
503
-			}
504
-			else
500
+			} else
505 501
 			{
506 502
 				$this->updateHandlerRule($dbparams,$params['db_rule']['val']);
507 503
 				$ruleID=$params['db_rule']['val'];
508 504
 			}
509
-		}
510
-		catch (Exception $e)
505
+		} catch (Exception $e)
511 506
 		{
512 507
 			$this->_helper->json(array('status'=>$e->getMessage()));
513 508
 			return;
@@ -538,9 +533,10 @@  discard block
 block discarded – undo
538 533
 				->from($this->getModuleConfig()->getTrapTableName(),$elmts)
539 534
 				->where('id=?',$trapid);
540 535
 			$trapDetail=$db->fetchRow($query);
541
-			if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
542
-		}
543
-		catch (Exception $e)
536
+			if ( $trapDetail == null ) {
537
+				throw new Exception('No traps was found with id = '.$trapid);
538
+			}
539
+		} catch (Exception $e)
544 540
 		{
545 541
 			$this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage());
546 542
 			return;
@@ -573,8 +569,7 @@  discard block
 block discarded – undo
573 569
 				->where('trap_id=?',$trapid);
574 570
 			$trapDetail=$db->fetchAll($query);
575 571
 			// if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid);
576
-		}
577
-		catch (Exception $e)
572
+		} catch (Exception $e)
578 573
 		{
579 574
 			$this->displayExitError('Add handler : get trap data detail : ',$e->getMessage());
580 575
 			return array();
@@ -600,9 +595,10 @@  discard block
 block discarded – undo
600 595
 				->from($this->getModuleConfig()->getTrapRuleName(),$queryArray)
601 596
 				->where('id=?',$ruleid);
602 597
 			$ruleDetail=$db->fetchRow($query);
603
-			if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid);
604
-		}
605
-		catch (Exception $e)
598
+			if ( $ruleDetail == null ) {
599
+				throw new Exception('No rule was found with id = '.$ruleid);
600
+			}
601
+		} catch (Exception $e)
606 602
 		{
607 603
 			$this->displayExitError('Update handler : get rule detail',$e->getMessage());
608 604
 			return array();
Please login to merge, or discard this patch.