Passed
Push — master ( 767740...736a2c )
by Patrick
01:57
created
library/Trapdirector/Icinga2API.php 3 patches
Indentation   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -10,281 +10,281 @@
 block discarded – undo
10 10
 class Icinga2API extends IcingaApiBase
11 11
 {
12 12
     
13
-    /**
14
-     * Creates Icinga2API object
15
-     * 
16
-     * @param string $host host name or IP
17
-     * @param number $port API port
18
-     */
19
-    public function __construct($host, $port = 5665)
20
-    {
21
-        parent::__construct($host,$port);
22
-    }
23
-    /**
13
+	/**
14
+	 * Creates Icinga2API object
15
+	 * 
16
+	 * @param string $host host name or IP
17
+	 * @param number $port API port
18
+	 */
19
+	public function __construct($host, $port = 5665)
20
+	{
21
+		parent::__construct($host,$port);
22
+	}
23
+	/**
24 24
 
25 25
 /************ Host query ************/  
26 26
 
27
-    /**
28
-     * return array of host by filter
29
-     * @param string $hostfilter
30
-     * @throws Exception
31
-     * @return array objects : array('__name','name','display_name','id' (=__name), 'address', 'ip4' (=address), 'address6', 'ip6' (=address6)
32
-     */
33
-    public function getHostByFilter(string $hostfilter)
34
-    {
35
-        $hosts = $this->standardQuery(
36
-            'host',
37
-            $hostfilter,
38
-            //'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
39
-            array('__name','name','display_name','address','address6')
40
-            );
41
-        foreach ( array_keys($hosts) as $key )
42
-        {
43
-            $hosts[$key]->id = $hosts[$key]->__name;
44
-            $hosts[$key]->ip4 = $hosts[$key]->address;
45
-            $hosts[$key]->ip6 = $hosts[$key]->address6;
46
-        }
47
-        return $hosts;
48
-    }
27
+	/**
28
+	 * return array of host by filter
29
+	 * @param string $hostfilter
30
+	 * @throws Exception
31
+	 * @return array objects : array('__name','name','display_name','id' (=__name), 'address', 'ip4' (=address), 'address6', 'ip6' (=address6)
32
+	 */
33
+	public function getHostByFilter(string $hostfilter)
34
+	{
35
+		$hosts = $this->standardQuery(
36
+			'host',
37
+			$hostfilter,
38
+			//'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
39
+			array('__name','name','display_name','address','address6')
40
+			);
41
+		foreach ( array_keys($hosts) as $key )
42
+		{
43
+			$hosts[$key]->id = $hosts[$key]->__name;
44
+			$hosts[$key]->ip4 = $hosts[$key]->address;
45
+			$hosts[$key]->ip6 = $hosts[$key]->address6;
46
+		}
47
+		return $hosts;
48
+	}
49 49
     
50
-    /**
51
-     * return array of host by IP (4 or 6)
52
-     * @param string $ip
53
-     * @throws Exception
54
-     * @return array objects : array('__name','name','display_name')
55
-     */
56
-    public function getHostByIP(string $ip) 
57
-    {
58
-        return $this->getHostByFilter('match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6)');
59
-    }
50
+	/**
51
+	 * return array of host by IP (4 or 6)
52
+	 * @param string $ip
53
+	 * @throws Exception
54
+	 * @return array objects : array('__name','name','display_name')
55
+	 */
56
+	public function getHostByIP(string $ip) 
57
+	{
58
+		return $this->getHostByFilter('match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6)');
59
+	}
60 60
 
61 61
     
62
-    /**
63
-     * Get host(s) by name in API
64
-     * @param string $name
65
-     * @return array|NULL[] : see getHostByIP
66
-     */
67
-    public function getHostByName(string $name)
68
-    {
69
-        return $this->getHostByFilter('match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name)');
70
-    }
62
+	/**
63
+	 * Get host(s) by name in API
64
+	 * @param string $name
65
+	 * @return array|NULL[] : see getHostByIP
66
+	 */
67
+	public function getHostByName(string $name)
68
+	{
69
+		return $this->getHostByFilter('match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name)');
70
+	}
71 71
 
72
-    /**
73
-     * Get host(s) by name in API
74
-     * @param string $name
75
-     * @return array|NULL[] : see getHostByIP
76
-     */
77
-    public function getHostByNameOrIP(string $name)
78
-    {
79
-        return $this->getHostByFilter( 
80
-            'match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name) || match("*' . $name . '*",host.address) || match("*' . $name . '*",host.address6)');
81
-    }
72
+	/**
73
+	 * Get host(s) by name in API
74
+	 * @param string $name
75
+	 * @return array|NULL[] : see getHostByIP
76
+	 */
77
+	public function getHostByNameOrIP(string $name)
78
+	{
79
+		return $this->getHostByFilter( 
80
+			'match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name) || match("*' . $name . '*",host.address) || match("*' . $name . '*",host.address6)');
81
+	}
82 82
     
83
-    public function getHostInfoByID(string $name)
84
-    {
85
-        $host = $this->getHostByFilter(
86
-            'host.__name=="'. $name .'"');
87
-        if (isset($host[0]))
88
-            return $host[0];
89
-        else
90
-            return NULL;
91
-    }
83
+	public function getHostInfoByID(string $name)
84
+	{
85
+		$host = $this->getHostByFilter(
86
+			'host.__name=="'. $name .'"');
87
+		if (isset($host[0]))
88
+			return $host[0];
89
+		else
90
+			return NULL;
91
+	}
92 92
  
93
-    /**
94
-     * Get all host and IP from hostgroup
95
-     * @param string $hostGroup
96
-     * @throws Exception
97
-     * @return array : attributes : address, address6, name
98
-     */
99
-    public function getHostsIPByHostGroup($hostGroup)
100
-    {        
101
-        return $this->standardQuery(
102
-            'host', 
103
-            '"' . $hostGroup . '" in host.groups',
104
-            array('address','address6','name')
93
+	/**
94
+	 * Get all host and IP from hostgroup
95
+	 * @param string $hostGroup
96
+	 * @throws Exception
97
+	 * @return array : attributes : address, address6, name
98
+	 */
99
+	public function getHostsIPByHostGroup($hostGroup)
100
+	{        
101
+		return $this->standardQuery(
102
+			'host', 
103
+			'"' . $hostGroup . '" in host.groups',
104
+			array('address','address6','name')
105 105
                 
106
-        );
107
-    }
106
+		);
107
+	}
108 108
 
109 109
 
110
-    /** Get services from host in API
111
-     *	
112
-     *  @throws Exception
113
-     *	@param $id string host name
114
-     *  @param bool $active
115
-     *  @param bool $passive_svc
116
-     *	@return array display_name (of service), service_object_id
117
-     */
118
-    public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
119
-    {
120
-        $filter = 'match("' . $id . '!*", service.__name)';
121
-        if ($active === TRUE)
122
-        {
123
-            $filter .= ' && service.active==true';
124
-        }
125
-        if ($passive_svc === TRUE)
126
-        {
127
-            $filter .= ' && service.enable_passive_checks==true';
128
-        }
129
-        $services =  $this->standardQuery(
130
-            'service',
131
-            $filter,
132
-            array('__name','name','display_name','active')
133
-            );
110
+	/** Get services from host in API
111
+	 *	
112
+	 *  @throws Exception
113
+	 *	@param $id string host name
114
+	 *  @param bool $active
115
+	 *  @param bool $passive_svc
116
+	 *	@return array display_name (of service), service_object_id
117
+	 */
118
+	public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
119
+	{
120
+		$filter = 'match("' . $id . '!*", service.__name)';
121
+		if ($active === TRUE)
122
+		{
123
+			$filter .= ' && service.active==true';
124
+		}
125
+		if ($passive_svc === TRUE)
126
+		{
127
+			$filter .= ' && service.enable_passive_checks==true';
128
+		}
129
+		$services =  $this->standardQuery(
130
+			'service',
131
+			$filter,
132
+			array('__name','name','display_name','active')
133
+			);
134 134
         
135
-        foreach ( array_keys($services) as $key )
136
-        {
137
-            $services[$key]->id = $services[$key]->__name;
138
-        }
135
+		foreach ( array_keys($services) as $key )
136
+		{
137
+			$services[$key]->id = $services[$key]->__name;
138
+		}
139 139
         
140
-        return $services;
140
+		return $services;
141 141
         
142
-    }
142
+	}
143 143
 
144 144
 /************  Host group query ************/    
145
-    /**
146
-     * return array of host by IP (4 or 6) or name
147
-     * @param string $group Host group name
148
-     * @throws Exception
149
-     * @return array objects : array('name','display_name')
150
-     */
151
-    public function getHostsByGroup(string $group)
152
-    {
153
-         return $this->standardQuery(
154
-            'host',
155
-            '"' . $group . '" in host.groups',
156
-            array('name','display_name')
157
-            );
158
-    }
145
+	/**
146
+	 * return array of host by IP (4 or 6) or name
147
+	 * @param string $group Host group name
148
+	 * @throws Exception
149
+	 * @return array objects : array('name','display_name')
150
+	 */
151
+	public function getHostsByGroup(string $group)
152
+	{
153
+		 return $this->standardQuery(
154
+			'host',
155
+			'"' . $group . '" in host.groups',
156
+			array('name','display_name')
157
+			);
158
+	}
159 159
     
160
-    public function getServicesByHostGroupid(string $group)
161
-    {
162
-        $hostList = $this->getHostsByGroup($group);
163
-        //return $hostList;
164
-        $hostNum = count($hostList);
165
-        $serviceList=array();
166
-        foreach ($hostList as $curHost)
167
-        {
168
-            $services = $this->getServicesByHostid($curHost->name);
169
-            foreach ($services as $service)
170
-            {
171
-                //return $service;
172
-                if (! isset($serviceList[$service->name]))
173
-                {
174
-                    $serviceList[$service->name]=
175
-                        array('num'=> 1 ,'__name' => $service->__name,'display_name' => $service->display_name);
176
-                }
177
-                else
178
-                {
179
-                    $serviceList[$service->name]['num']++;
180
-                }
181
-            }
182
-        }
183
-        $commonServices=array();
184
-        foreach ($serviceList as $key => $values)
185
-        {
186
-            if ($values['num'] >= $hostNum)
187
-            {
188
-                array_push($commonServices,array($key,$values['display_name']));
189
-            }
190
-        }
191
-        return $commonServices;
192
-    }
160
+	public function getServicesByHostGroupid(string $group)
161
+	{
162
+		$hostList = $this->getHostsByGroup($group);
163
+		//return $hostList;
164
+		$hostNum = count($hostList);
165
+		$serviceList=array();
166
+		foreach ($hostList as $curHost)
167
+		{
168
+			$services = $this->getServicesByHostid($curHost->name);
169
+			foreach ($services as $service)
170
+			{
171
+				//return $service;
172
+				if (! isset($serviceList[$service->name]))
173
+				{
174
+					$serviceList[$service->name]=
175
+						array('num'=> 1 ,'__name' => $service->__name,'display_name' => $service->display_name);
176
+				}
177
+				else
178
+				{
179
+					$serviceList[$service->name]['num']++;
180
+				}
181
+			}
182
+		}
183
+		$commonServices=array();
184
+		foreach ($serviceList as $key => $values)
185
+		{
186
+			if ($values['num'] >= $hostNum)
187
+			{
188
+				array_push($commonServices,array($key,$values['display_name']));
189
+			}
190
+		}
191
+		return $commonServices;
192
+	}
193 193
  
194
-    /**
195
-     * Get all host and IP from hostgroup
196
-     * @param string $hostGroup
197
-     * @throws Exception
198
-     * @return array : attributes : address, address6, name
199
-     */
200
-    public function getHostGroupByName($name)
201
-    {
202
-        $hosts = $this->standardQuery(
203
-            'hostgroup',
204
-            'match("*' . $name . '*",hostgroup.name)',
205
-            array('__name','name','display_name')
194
+	/**
195
+	 * Get all host and IP from hostgroup
196
+	 * @param string $hostGroup
197
+	 * @throws Exception
198
+	 * @return array : attributes : address, address6, name
199
+	 */
200
+	public function getHostGroupByName($name)
201
+	{
202
+		$hosts = $this->standardQuery(
203
+			'hostgroup',
204
+			'match("*' . $name . '*",hostgroup.name)',
205
+			array('__name','name','display_name')
206 206
             
207
-            );
208
-        foreach ( array_keys($hosts) as $key )
209
-        {
210
-            $hosts[$key]->id = $hosts[$key]->__name;
211
-        }
212
-        return $hosts;
213
-    }
207
+			);
208
+		foreach ( array_keys($hosts) as $key )
209
+		{
210
+			$hosts[$key]->id = $hosts[$key]->__name;
211
+		}
212
+		return $hosts;
213
+	}
214 214
     
215
-    /**
216
-     * Get hostgroup by id (__name)
217
-     * @param string $hostGroup
218
-     * @throws Exception
219
-     * @return array : __name, name, display_name
220
-     */
221
-    public function getHostGroupById($name)
222
-    {
223
-        $hosts = $this->standardQuery(
224
-            'hostgroup',
225
-            'hostgroup.__name=="'. $name .'"',
226
-            array('__name','name','display_name')
215
+	/**
216
+	 * Get hostgroup by id (__name)
217
+	 * @param string $hostGroup
218
+	 * @throws Exception
219
+	 * @return array : __name, name, display_name
220
+	 */
221
+	public function getHostGroupById($name)
222
+	{
223
+		$hosts = $this->standardQuery(
224
+			'hostgroup',
225
+			'hostgroup.__name=="'. $name .'"',
226
+			array('__name','name','display_name')
227 227
             
228
-            );
229
-        $hosts[0]->id = $hosts[0]->__name;
230
-        return $hosts[0];
231
-    }
228
+			);
229
+		$hosts[0]->id = $hosts[0]->__name;
230
+		return $hosts[0];
231
+	}
232 232
     
233 233
 /****************   Service queries ************/
234
-    /** Get services object id by host name / service name
235
-     *	does not catch exceptions
236
-     *	@param $hostname string host name
237
-     *	@param $name string service name
238
-     *  @param bool $active : if true, return only active service
239
-     *  @param bool $passive_svc : if true, return only service accepting passive checks
240
-     *	@return array  service id
241
-     */
242
-    public function getServiceIDByName($hostname,$name,bool $active = TRUE, bool $passive_svc = TRUE)
243
-    {
244
-        $filter = 'service.__name=="' . $hostname . '!'. $name .'"';
245
-        if ($active === TRUE)
246
-        {
247
-            $filter .= ' && service.active==true';
248
-        }
249
-        if ($passive_svc === TRUE)
250
-        {
251
-            $filter .= ' && service.enable_passive_checks==true';
252
-        }
253
-        $services =  $this->standardQuery(
254
-            'service',
255
-            $filter,
256
-            array('__name','name','display_name','active','enable_passive_checks')
257
-            );
234
+	/** Get services object id by host name / service name
235
+	 *	does not catch exceptions
236
+	 *	@param $hostname string host name
237
+	 *	@param $name string service name
238
+	 *  @param bool $active : if true, return only active service
239
+	 *  @param bool $passive_svc : if true, return only service accepting passive checks
240
+	 *	@return array  service id
241
+	 */
242
+	public function getServiceIDByName($hostname,$name,bool $active = TRUE, bool $passive_svc = TRUE)
243
+	{
244
+		$filter = 'service.__name=="' . $hostname . '!'. $name .'"';
245
+		if ($active === TRUE)
246
+		{
247
+			$filter .= ' && service.active==true';
248
+		}
249
+		if ($passive_svc === TRUE)
250
+		{
251
+			$filter .= ' && service.enable_passive_checks==true';
252
+		}
253
+		$services =  $this->standardQuery(
254
+			'service',
255
+			$filter,
256
+			array('__name','name','display_name','active','enable_passive_checks')
257
+			);
258 258
         
259
-        foreach ( array_keys($services) as $key )
260
-        {
261
-            $services[$key]->id = $services[$key]->__name;
262
-        }
259
+		foreach ( array_keys($services) as $key )
260
+		{
261
+			$services[$key]->id = $services[$key]->__name;
262
+		}
263 263
         
264
-        return $services;
265
-    }
264
+		return $services;
265
+	}
266 266
  
267
-    /** Get services object by id (host!name)
268
-     *	does not catch exceptions
269
-     *	@param $name string service __name (host!name)
270
-     *	@return array  service id
271
-     */
272
-    public function getServiceById($name)
273
-    {
274
-        $filter = 'service.__name=="' .  $name .'"';
275
-        $services =  $this->standardQuery(
276
-            'service',
277
-            $filter,
278
-            array('__name','name','display_name','active','enable_passive_checks')
279
-            );
267
+	/** Get services object by id (host!name)
268
+	 *	does not catch exceptions
269
+	 *	@param $name string service __name (host!name)
270
+	 *	@return array  service id
271
+	 */
272
+	public function getServiceById($name)
273
+	{
274
+		$filter = 'service.__name=="' .  $name .'"';
275
+		$services =  $this->standardQuery(
276
+			'service',
277
+			$filter,
278
+			array('__name','name','display_name','active','enable_passive_checks')
279
+			);
280 280
         
281
-        foreach ( array_keys($services) as $key )
282
-        {
283
-            $services[$key]->id = $services[$key]->__name;
284
-        }
281
+		foreach ( array_keys($services) as $key )
282
+		{
283
+			$services[$key]->id = $services[$key]->__name;
284
+		}
285 285
         
286
-        return $services;
287
-    }
286
+		return $services;
287
+	}
288 288
     
289 289
     
290 290
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      * @param string $host host name or IP
17 17
      * @param number $port API port
18 18
      */
19
-    public function __construct($host, $port = 5665)
19
+    public function __construct($host, $port=5665)
20 20
     {
21
-        parent::__construct($host,$port);
21
+        parent::__construct($host, $port);
22 22
     }
23 23
     /**
24 24
 
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function getHostByFilter(string $hostfilter)
34 34
     {
35
-        $hosts = $this->standardQuery(
35
+        $hosts=$this->standardQuery(
36 36
             'host',
37 37
             $hostfilter,
38 38
             //'match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6) || match("*' . $ip . '*",host.name) || match("*' . $ip . '*",host.display_name)',
39
-            array('__name','name','display_name','address','address6')
39
+            array('__name', 'name', 'display_name', 'address', 'address6')
40 40
             );
41
-        foreach ( array_keys($hosts) as $key )
41
+        foreach (array_keys($hosts) as $key)
42 42
         {
43
-            $hosts[$key]->id = $hosts[$key]->__name;
44
-            $hosts[$key]->ip4 = $hosts[$key]->address;
45
-            $hosts[$key]->ip6 = $hosts[$key]->address6;
43
+            $hosts[$key]->id=$hosts[$key]->__name;
44
+            $hosts[$key]->ip4=$hosts[$key]->address;
45
+            $hosts[$key]->ip6=$hosts[$key]->address6;
46 46
         }
47 47
         return $hosts;
48 48
     }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function getHostByIP(string $ip) 
57 57
     {
58
-        return $this->getHostByFilter('match("*' . $ip . '*",host.address) || match("*' . $ip . '*",host.address6)');
58
+        return $this->getHostByFilter('match("*'.$ip.'*",host.address) || match("*'.$ip.'*",host.address6)');
59 59
     }
60 60
 
61 61
     
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function getHostByName(string $name)
68 68
     {
69
-        return $this->getHostByFilter('match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name)');
69
+        return $this->getHostByFilter('match("*'.$name.'*",host.name) || match("*'.$name.'*",host.display_name)');
70 70
     }
71 71
 
72 72
     /**
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
     public function getHostByNameOrIP(string $name)
78 78
     {
79 79
         return $this->getHostByFilter( 
80
-            'match("*' . $name . '*",host.name) || match("*' . $name . '*",host.display_name) || match("*' . $name . '*",host.address) || match("*' . $name . '*",host.address6)');
80
+            'match("*'.$name.'*",host.name) || match("*'.$name.'*",host.display_name) || match("*'.$name.'*",host.address) || match("*'.$name.'*",host.address6)');
81 81
     }
82 82
     
83 83
     public function getHostInfoByID(string $name)
84 84
     {
85
-        $host = $this->getHostByFilter(
86
-            'host.__name=="'. $name .'"');
85
+        $host=$this->getHostByFilter(
86
+            'host.__name=="'.$name.'"');
87 87
         if (isset($host[0]))
88 88
             return $host[0];
89 89
         else
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
     {        
101 101
         return $this->standardQuery(
102 102
             'host', 
103
-            '"' . $hostGroup . '" in host.groups',
104
-            array('address','address6','name')
103
+            '"'.$hostGroup.'" in host.groups',
104
+            array('address', 'address6', 'name')
105 105
                 
106 106
         );
107 107
     }
@@ -115,26 +115,26 @@  discard block
 block discarded – undo
115 115
      *  @param bool $passive_svc
116 116
      *	@return array display_name (of service), service_object_id
117 117
      */
118
-    public function getServicesByHostid(string $id, bool $active = TRUE, bool $passive_svc = TRUE)
118
+    public function getServicesByHostid(string $id, bool $active=TRUE, bool $passive_svc=TRUE)
119 119
     {
120
-        $filter = 'match("' . $id . '!*", service.__name)';
120
+        $filter='match("'.$id.'!*", service.__name)';
121 121
         if ($active === TRUE)
122 122
         {
123
-            $filter .= ' && service.active==true';
123
+            $filter.=' && service.active==true';
124 124
         }
125 125
         if ($passive_svc === TRUE)
126 126
         {
127
-            $filter .= ' && service.enable_passive_checks==true';
127
+            $filter.=' && service.enable_passive_checks==true';
128 128
         }
129
-        $services =  $this->standardQuery(
129
+        $services=$this->standardQuery(
130 130
             'service',
131 131
             $filter,
132
-            array('__name','name','display_name','active')
132
+            array('__name', 'name', 'display_name', 'active')
133 133
             );
134 134
         
135
-        foreach ( array_keys($services) as $key )
135
+        foreach (array_keys($services) as $key)
136 136
         {
137
-            $services[$key]->id = $services[$key]->__name;
137
+            $services[$key]->id=$services[$key]->__name;
138 138
         }
139 139
         
140 140
         return $services;
@@ -152,27 +152,27 @@  discard block
 block discarded – undo
152 152
     {
153 153
          return $this->standardQuery(
154 154
             'host',
155
-            '"' . $group . '" in host.groups',
156
-            array('name','display_name')
155
+            '"'.$group.'" in host.groups',
156
+            array('name', 'display_name')
157 157
             );
158 158
     }
159 159
     
160 160
     public function getServicesByHostGroupid(string $group)
161 161
     {
162
-        $hostList = $this->getHostsByGroup($group);
162
+        $hostList=$this->getHostsByGroup($group);
163 163
         //return $hostList;
164
-        $hostNum = count($hostList);
164
+        $hostNum=count($hostList);
165 165
         $serviceList=array();
166 166
         foreach ($hostList as $curHost)
167 167
         {
168
-            $services = $this->getServicesByHostid($curHost->name);
168
+            $services=$this->getServicesByHostid($curHost->name);
169 169
             foreach ($services as $service)
170 170
             {
171 171
                 //return $service;
172
-                if (! isset($serviceList[$service->name]))
172
+                if (!isset($serviceList[$service->name]))
173 173
                 {
174 174
                     $serviceList[$service->name]=
175
-                        array('num'=> 1 ,'__name' => $service->__name,'display_name' => $service->display_name);
175
+                        array('num'=> 1, '__name' => $service->__name, 'display_name' => $service->display_name);
176 176
                 }
177 177
                 else
178 178
                 {
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         {
186 186
             if ($values['num'] >= $hostNum)
187 187
             {
188
-                array_push($commonServices,array($key,$values['display_name']));
188
+                array_push($commonServices, array($key, $values['display_name']));
189 189
             }
190 190
         }
191 191
         return $commonServices;
@@ -199,15 +199,15 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function getHostGroupByName($name)
201 201
     {
202
-        $hosts = $this->standardQuery(
202
+        $hosts=$this->standardQuery(
203 203
             'hostgroup',
204
-            'match("*' . $name . '*",hostgroup.name)',
205
-            array('__name','name','display_name')
204
+            'match("*'.$name.'*",hostgroup.name)',
205
+            array('__name', 'name', 'display_name')
206 206
             
207 207
             );
208
-        foreach ( array_keys($hosts) as $key )
208
+        foreach (array_keys($hosts) as $key)
209 209
         {
210
-            $hosts[$key]->id = $hosts[$key]->__name;
210
+            $hosts[$key]->id=$hosts[$key]->__name;
211 211
         }
212 212
         return $hosts;
213 213
     }
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function getHostGroupById($name)
222 222
     {
223
-        $hosts = $this->standardQuery(
223
+        $hosts=$this->standardQuery(
224 224
             'hostgroup',
225
-            'hostgroup.__name=="'. $name .'"',
226
-            array('__name','name','display_name')
225
+            'hostgroup.__name=="'.$name.'"',
226
+            array('__name', 'name', 'display_name')
227 227
             
228 228
             );
229
-        $hosts[0]->id = $hosts[0]->__name;
229
+        $hosts[0]->id=$hosts[0]->__name;
230 230
         return $hosts[0];
231 231
     }
232 232
     
@@ -239,26 +239,26 @@  discard block
 block discarded – undo
239 239
      *  @param bool $passive_svc : if true, return only service accepting passive checks
240 240
      *	@return array  service id
241 241
      */
242
-    public function getServiceIDByName($hostname,$name,bool $active = TRUE, bool $passive_svc = TRUE)
242
+    public function getServiceIDByName($hostname, $name, bool $active=TRUE, bool $passive_svc=TRUE)
243 243
     {
244
-        $filter = 'service.__name=="' . $hostname . '!'. $name .'"';
244
+        $filter='service.__name=="'.$hostname.'!'.$name.'"';
245 245
         if ($active === TRUE)
246 246
         {
247
-            $filter .= ' && service.active==true';
247
+            $filter.=' && service.active==true';
248 248
         }
249 249
         if ($passive_svc === TRUE)
250 250
         {
251
-            $filter .= ' && service.enable_passive_checks==true';
251
+            $filter.=' && service.enable_passive_checks==true';
252 252
         }
253
-        $services =  $this->standardQuery(
253
+        $services=$this->standardQuery(
254 254
             'service',
255 255
             $filter,
256
-            array('__name','name','display_name','active','enable_passive_checks')
256
+            array('__name', 'name', 'display_name', 'active', 'enable_passive_checks')
257 257
             );
258 258
         
259
-        foreach ( array_keys($services) as $key )
259
+        foreach (array_keys($services) as $key)
260 260
         {
261
-            $services[$key]->id = $services[$key]->__name;
261
+            $services[$key]->id=$services[$key]->__name;
262 262
         }
263 263
         
264 264
         return $services;
@@ -271,16 +271,16 @@  discard block
 block discarded – undo
271 271
      */
272 272
     public function getServiceById($name)
273 273
     {
274
-        $filter = 'service.__name=="' .  $name .'"';
275
-        $services =  $this->standardQuery(
274
+        $filter='service.__name=="'.$name.'"';
275
+        $services=$this->standardQuery(
276 276
             'service',
277 277
             $filter,
278
-            array('__name','name','display_name','active','enable_passive_checks')
278
+            array('__name', 'name', 'display_name', 'active', 'enable_passive_checks')
279 279
             );
280 280
         
281
-        foreach ( array_keys($services) as $key )
281
+        foreach (array_keys($services) as $key)
282 282
         {
283
-            $services[$key]->id = $services[$key]->__name;
283
+            $services[$key]->id=$services[$key]->__name;
284 284
         }
285 285
         
286 286
         return $services;
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -84,10 +84,11 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $host = $this->getHostByFilter(
86 86
             'host.__name=="'. $name .'"');
87
-        if (isset($host[0]))
88
-            return $host[0];
89
-        else
90
-            return NULL;
87
+        if (isset($host[0])) {
88
+                    return $host[0];
89
+        } else {
90
+                    return NULL;
91
+        }
91 92
     }
92 93
  
93 94
     /**
@@ -173,8 +174,7 @@  discard block
 block discarded – undo
173 174
                 {
174 175
                     $serviceList[$service->name]=
175 176
                         array('num'=> 1 ,'__name' => $service->__name,'display_name' => $service->display_name);
176
-                }
177
-                else
177
+                } else
178 178
                 {
179 179
                     $serviceList[$service->name]['num']++;
180 180
                 }
Please login to merge, or discard this patch.