@@ -10,281 +10,281 @@ |
||
| 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 | } |
@@ -16,9 +16,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -84,10 +84,11 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | /** Get instance of TrapModuleConfig class |
| 52 | - * @return TrapModuleConfig |
|
| 53 | - */ |
|
| 52 | + * @return TrapModuleConfig |
|
| 53 | + */ |
|
| 54 | 54 | public function getModuleConfig() |
| 55 | 55 | { |
| 56 | 56 | if ($this->moduleConfig == Null) |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getTrapHostListTable() |
| 84 | 84 | { |
| 85 | - if ($this->trapTableHostList == Null) |
|
| 85 | + if ($this->trapTableHostList == Null) |
|
| 86 | 86 | { |
| 87 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 88 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 89 | - } |
|
| 90 | - return $this->trapTableHostList; |
|
| 87 | + $this->trapTableHostList = new TrapTableHostList(); |
|
| 88 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 89 | + } |
|
| 90 | + return $this->trapTableHostList; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function getUIDatabase() |
| 110 | 110 | { |
| 111 | - if ($this->UIDatabase == Null) |
|
| 112 | - { |
|
| 113 | - $this->UIDatabase = new UIDatabase($this); |
|
| 111 | + if ($this->UIDatabase == Null) |
|
| 112 | + { |
|
| 113 | + $this->UIDatabase = new UIDatabase($this); |
|
| 114 | 114 | |
| 115 | - } |
|
| 116 | - return $this->UIDatabase; |
|
| 115 | + } |
|
| 116 | + return $this->UIDatabase; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -122,36 +122,36 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function getIdoConn() |
| 124 | 124 | { |
| 125 | - if ($this->icingaAPI === NULL) |
|
| 126 | - { |
|
| 127 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
| 128 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
| 129 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
| 130 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
| 131 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
| 132 | - $this->icingaAPI->setCredentials($user, $pass); |
|
| 133 | - list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
| 134 | - if ($ret === TRUE) // On error, switch to ido DB |
|
| 135 | - { |
|
| 136 | - $this->apiMode = FALSE; |
|
| 137 | - return $this->getUIDatabase(); |
|
| 138 | - } |
|
| 139 | - $this->apiMode = TRUE; |
|
| 125 | + if ($this->icingaAPI === NULL) |
|
| 126 | + { |
|
| 127 | + $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
| 128 | + $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
| 129 | + $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
| 130 | + $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
| 131 | + $this->icingaAPI = new Icinga2API($host,$port); |
|
| 132 | + $this->icingaAPI->setCredentials($user, $pass); |
|
| 133 | + list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
| 134 | + if ($ret === TRUE) // On error, switch to ido DB |
|
| 135 | + { |
|
| 136 | + $this->apiMode = FALSE; |
|
| 137 | + return $this->getUIDatabase(); |
|
| 138 | + } |
|
| 139 | + $this->apiMode = TRUE; |
|
| 140 | 140 | |
| 141 | - } |
|
| 142 | - return $this->icingaAPI; |
|
| 141 | + } |
|
| 142 | + return $this->icingaAPI; |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 147 | - { |
|
| 148 | - $limit = $this->params->get('limit', $limit); |
|
| 149 | - $page = $this->params->get('page', $offset); |
|
| 146 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 147 | + { |
|
| 148 | + $limit = $this->params->get('limit', $limit); |
|
| 149 | + $page = $this->params->get('page', $offset); |
|
| 150 | 150 | |
| 151 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 151 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 152 | 152 | |
| 153 | - return $paginatable; |
|
| 154 | - } |
|
| 153 | + return $paginatable; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | public function displayExitError($source,$message) |
| 157 | 157 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -160,33 +160,33 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | protected function checkReadPermission() |
| 162 | 162 | { |
| 163 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 164 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 165 | - } |
|
| 163 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 164 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | protected function checkConfigPermission() |
| 169 | 169 | { |
| 170 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 171 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 172 | - } |
|
| 170 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 171 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Check if user has write permission |
|
| 177 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 178 | - * @return boolean : user has permission |
|
| 179 | - */ |
|
| 175 | + /** |
|
| 176 | + * Check if user has write permission |
|
| 177 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 178 | + * @return boolean : user has permission |
|
| 179 | + */ |
|
| 180 | 180 | protected function checkModuleConfigPermission($check=0) |
| 181 | 181 | { |
| 182 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 183 | - if ($check == 0) |
|
| 184 | - { |
|
| 185 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 186 | - } |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 189 | - return true; |
|
| 182 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 183 | + if ($check == 0) |
|
| 184 | + { |
|
| 185 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 186 | + } |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | + return true; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /************************* Trap class get **********************/ |
@@ -206,18 +206,18 @@ discard block |
||
| 206 | 206 | /************************** MIB related **************************/ |
| 207 | 207 | |
| 208 | 208 | /** Get MIBLoader class |
| 209 | - * @return MIBLoader class |
|
| 210 | - */ |
|
| 209 | + * @return MIBLoader class |
|
| 210 | + */ |
|
| 211 | 211 | protected function getMIB() |
| 212 | 212 | { |
| 213 | 213 | if ($this->MIBData == null) |
| 214 | 214 | { |
| 215 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 216 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 215 | + $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 216 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 217 | 217 | $this->MIBData=new MIBLoader( |
| 218 | 218 | $this->Config()->get('config', 'snmptranslate'), |
| 219 | 219 | $this->Config()->get('config', 'snmptranslate_dirs'), |
| 220 | - $dbConn, |
|
| 220 | + $dbConn, |
|
| 221 | 221 | $this->getModuleConfig() |
| 222 | 222 | ); |
| 223 | 223 | } |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | /************************** Database queries *******************/ |
| 228 | 228 | |
| 229 | 229 | /** Check if director is installed |
| 230 | - * @return bool true/false |
|
| 231 | - */ |
|
| 230 | + * @return bool true/false |
|
| 231 | + */ |
|
| 232 | 232 | protected function isDirectorInstalled() |
| 233 | 233 | { |
| 234 | - $output=array(); |
|
| 235 | - exec('icingacli module list',$output); |
|
| 236 | - foreach ($output as $line) |
|
| 234 | + $output=array(); |
|
| 235 | + exec('icingacli module list',$output); |
|
| 236 | + foreach ($output as $line) |
|
| 237 | 237 | { |
| 238 | 238 | if (preg_match('/^director .*enabled/',$line)) |
| 239 | 239 | { |
@@ -246,72 +246,72 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | /************************ UI elements **************************/ |
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * get max rows to display before paging. |
|
| 251 | - * @return number |
|
| 252 | - */ |
|
| 249 | + /** |
|
| 250 | + * get max rows to display before paging. |
|
| 251 | + * @return number |
|
| 252 | + */ |
|
| 253 | 253 | public function itemListDisplay() |
| 254 | 254 | { |
| 255 | - return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
| 255 | + return $this->getUIDatabase()->getDBConfigValue('max_rows_in_list'); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | public function setitemListDisplay(int $maxRows) |
| 259 | 259 | { |
| 260 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
| 260 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * get Handlers categories list (index => textvalue). |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 263 | + /** |
|
| 264 | + * get Handlers categories list (index => textvalue). |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | 267 | public function getHandlersCategory() |
| 268 | 268 | { |
| 269 | - //<index>:<name>!<index>:<name> |
|
| 270 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
| 271 | - $catListArray=explode('!',$catList); |
|
| 272 | - $retArray=array(); |
|
| 273 | - foreach ($catListArray as $category) |
|
| 274 | - { |
|
| 275 | - $catArray=explode(':',$category); |
|
| 276 | - $retArray[$catArray[0]] = $catArray[1]; |
|
| 277 | - } |
|
| 278 | - return $retArray; |
|
| 269 | + //<index>:<name>!<index>:<name> |
|
| 270 | + $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
| 271 | + $catListArray=explode('!',$catList); |
|
| 272 | + $retArray=array(); |
|
| 273 | + foreach ($catListArray as $category) |
|
| 274 | + { |
|
| 275 | + $catArray=explode(':',$category); |
|
| 276 | + $retArray[$catArray[0]] = $catArray[1]; |
|
| 277 | + } |
|
| 278 | + return $retArray; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | public function setHandlerCategory(array $catArray) |
| 282 | 282 | { |
| 283 | - $catString=''; |
|
| 284 | - foreach ($catArray as $index => $value) |
|
| 285 | - { |
|
| 286 | - if ($catString != '' ) $catString .= '!'; |
|
| 287 | - $catString .= $index . ':' . $value; |
|
| 288 | - } |
|
| 289 | - $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
| 283 | + $catString=''; |
|
| 284 | + foreach ($catArray as $index => $value) |
|
| 285 | + { |
|
| 286 | + if ($catString != '' ) $catString .= '!'; |
|
| 287 | + $catString .= $index . ':' . $value; |
|
| 288 | + } |
|
| 289 | + $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | public function addHandlersCategory(string $catName) |
| 293 | 293 | { |
| 294 | - $catArray = $this->getHandlersCategory(); |
|
| 295 | - $i=1; |
|
| 296 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
| 297 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
| 298 | - $catArray[$i] = $catName; |
|
| 299 | - $this->setHandlerCategory($catArray); |
|
| 294 | + $catArray = $this->getHandlersCategory(); |
|
| 295 | + $i=1; |
|
| 296 | + while (isset($catArray[$i]) && $i < 100) $i++; |
|
| 297 | + if ($i == 100) throw new ProgrammingError('Category array error'); |
|
| 298 | + $catArray[$i] = $catName; |
|
| 299 | + $this->setHandlerCategory($catArray); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | public function delHandlersCategory(int $catIndex) |
| 303 | 303 | { |
| 304 | - $catArray = $this->getHandlersCategory(); |
|
| 305 | - unset($catArray[$catIndex]); |
|
| 306 | - $this->setHandlerCategory($catArray); |
|
| 307 | - $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
| 304 | + $catArray = $this->getHandlersCategory(); |
|
| 305 | + unset($catArray[$catIndex]); |
|
| 306 | + $this->setHandlerCategory($catArray); |
|
| 307 | + $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | public function renameHandlersCategory(int $catIndex, string $catName) |
| 311 | 311 | { |
| 312 | - $catArray = $this->getHandlersCategory(); |
|
| 313 | - $catArray[$catIndex] = $catName; |
|
| 314 | - $this->setHandlerCategory($catArray); |
|
| 312 | + $catArray = $this->getHandlersCategory(); |
|
| 313 | + $catArray[$catIndex] = $catName; |
|
| 314 | + $this->setHandlerCategory($catArray); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | /** @var UIDatabase $UIDatabase */ |
| 42 | 42 | protected $UIDatabase; |
| 43 | 43 | /** @var Icinga2API $IcingaAPI */ |
| 44 | - protected $icingaAPI = NULL; |
|
| 44 | + protected $icingaAPI=NULL; |
|
| 45 | 45 | /** @var bool $apiMode connection to icinngaDB is by api (true) od ido DB (false) */ |
| 46 | - protected $apiMode = FALSE; |
|
| 46 | + protected $apiMode=FALSE; |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | { |
| 61 | 61 | $this->redirectNow('trapdirector/settings?message=No database prefix'); |
| 62 | 62 | } |
| 63 | - $this->moduleConfig = new TrapModuleConfig($db_prefix); |
|
| 63 | + $this->moduleConfig=new TrapModuleConfig($db_prefix); |
|
| 64 | 64 | } |
| 65 | 65 | return $this->moduleConfig; |
| 66 | 66 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function getTrapListTable() { |
| 73 | 73 | if ($this->trapTableList == Null) { |
| 74 | - $this->trapTableList = new TrapTableList(); |
|
| 74 | + $this->trapTableList=new TrapTableList(); |
|
| 75 | 75 | $this->trapTableList->setConfig($this->getModuleConfig()); |
| 76 | 76 | } |
| 77 | 77 | return $this->trapTableList; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | if ($this->trapTableHostList == Null) |
| 86 | 86 | { |
| 87 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 87 | + $this->trapTableHostList=new TrapTableHostList(); |
|
| 88 | 88 | $this->trapTableHostList->setConfig($this->getModuleConfig()); |
| 89 | 89 | } |
| 90 | 90 | return $this->trapTableHostList; |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | if ($this->handlerTableList == Null) |
| 99 | 99 | { |
| 100 | - $this->handlerTableList = new HandlerTableList(); |
|
| 100 | + $this->handlerTableList=new HandlerTableList(); |
|
| 101 | 101 | $this->handlerTableList->setConfig($this->getModuleConfig()); |
| 102 | 102 | } |
| 103 | 103 | return $this->handlerTableList; |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | if ($this->UIDatabase == Null) |
| 112 | 112 | { |
| 113 | - $this->UIDatabase = new UIDatabase($this); |
|
| 113 | + $this->UIDatabase=new UIDatabase($this); |
|
| 114 | 114 | |
| 115 | 115 | } |
| 116 | 116 | return $this->UIDatabase; |
@@ -124,51 +124,51 @@ discard block |
||
| 124 | 124 | { |
| 125 | 125 | if ($this->icingaAPI === NULL) |
| 126 | 126 | { |
| 127 | - $host = $this->Config()->get('config', 'icingaAPI_host'); |
|
| 128 | - $port = $this->Config()->get('config', 'icingaAPI_port'); |
|
| 129 | - $user = $this->Config()->get('config', 'icingaAPI_user'); |
|
| 130 | - $pass = $this->Config()->get('config', 'icingaAPI_password'); |
|
| 131 | - $this->icingaAPI = new Icinga2API($host,$port); |
|
| 127 | + $host=$this->Config()->get('config', 'icingaAPI_host'); |
|
| 128 | + $port=$this->Config()->get('config', 'icingaAPI_port'); |
|
| 129 | + $user=$this->Config()->get('config', 'icingaAPI_user'); |
|
| 130 | + $pass=$this->Config()->get('config', 'icingaAPI_password'); |
|
| 131 | + $this->icingaAPI=new Icinga2API($host, $port); |
|
| 132 | 132 | $this->icingaAPI->setCredentials($user, $pass); |
| 133 | - list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
| 133 | + list($ret, $message)=$this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
|
| 134 | 134 | if ($ret === TRUE) // On error, switch to ido DB |
| 135 | 135 | { |
| 136 | - $this->apiMode = FALSE; |
|
| 136 | + $this->apiMode=FALSE; |
|
| 137 | 137 | return $this->getUIDatabase(); |
| 138 | 138 | } |
| 139 | - $this->apiMode = TRUE; |
|
| 139 | + $this->apiMode=TRUE; |
|
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | return $this->icingaAPI; |
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 146 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit=25, $offset=null) |
|
| 147 | 147 | { |
| 148 | - $limit = $this->params->get('limit', $limit); |
|
| 149 | - $page = $this->params->get('page', $offset); |
|
| 148 | + $limit=$this->params->get('limit', $limit); |
|
| 149 | + $page=$this->params->get('page', $offset); |
|
| 150 | 150 | |
| 151 | 151 | $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
| 152 | 152 | |
| 153 | 153 | return $paginatable; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - public function displayExitError($source,$message) |
|
| 156 | + public function displayExitError($source, $message) |
|
| 157 | 157 | { // TODO : check better ways to transmit data (with POST ?) |
| 158 | 158 | $this->redirectNow('trapdirector/error?source='.$source.'&message='.$message); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | protected function checkReadPermission() |
| 162 | 162 | { |
| 163 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 164 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 163 | + if (!$this->Auth()->hasPermission('trapdirector/view')) { |
|
| 164 | + $this->displayExitError('Permissions', 'No permission fo view content'); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | protected function checkConfigPermission() |
| 169 | 169 | { |
| 170 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 171 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 170 | + if (!$this->Auth()->hasPermission('trapdirector/config')) { |
|
| 171 | + $this->displayExitError('Permissions', 'No permission fo configure'); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | */ |
| 180 | 180 | protected function checkModuleConfigPermission($check=0) |
| 181 | 181 | { |
| 182 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 182 | + if (!$this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 183 | 183 | if ($check == 0) |
| 184 | 184 | { |
| 185 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 185 | + $this->displayExitError('Permissions', 'No permission fo configure module'); |
|
| 186 | 186 | } |
| 187 | 187 | return false; |
| 188 | 188 | } |
@@ -194,10 +194,10 @@ discard block |
||
| 194 | 194 | { // TODO : try/catch here ? or within caller |
| 195 | 195 | if ($this->trapClass == null) |
| 196 | 196 | { |
| 197 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 197 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 198 | 198 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 199 | 199 | //$debug_level=4; |
| 200 | - $this->trapClass = new Trap($icingaweb2_etc); |
|
| 200 | + $this->trapClass=new Trap($icingaweb2_etc); |
|
| 201 | 201 | //$Trap->setLogging($debug_level,'syslog'); |
| 202 | 202 | } |
| 203 | 203 | return $this->trapClass; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | if ($this->MIBData == null) |
| 214 | 214 | { |
| 215 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 215 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 216 | 216 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 217 | 217 | $this->MIBData=new MIBLoader( |
| 218 | 218 | $this->Config()->get('config', 'snmptranslate'), |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | protected function isDirectorInstalled() |
| 233 | 233 | { |
| 234 | 234 | $output=array(); |
| 235 | - exec('icingacli module list',$output); |
|
| 235 | + exec('icingacli module list', $output); |
|
| 236 | 236 | foreach ($output as $line) |
| 237 | 237 | { |
| 238 | - if (preg_match('/^director .*enabled/',$line)) |
|
| 238 | + if (preg_match('/^director .*enabled/', $line)) |
|
| 239 | 239 | { |
| 240 | 240 | return true; |
| 241 | 241 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | public function setitemListDisplay(int $maxRows) |
| 259 | 259 | { |
| 260 | - return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list',$maxRows); |
|
| 260 | + return $this->getUIDatabase()->setDBConfigValue('max_rows_in_list', $maxRows); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | public function getHandlersCategory() |
| 268 | 268 | { |
| 269 | 269 | //<index>:<name>!<index>:<name> |
| 270 | - $catList = $this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
| 271 | - $catListArray=explode('!',$catList); |
|
| 270 | + $catList=$this->getUIDatabase()->getDBConfigValue('handler_categories'); |
|
| 271 | + $catListArray=explode('!', $catList); |
|
| 272 | 272 | $retArray=array(); |
| 273 | 273 | foreach ($catListArray as $category) |
| 274 | 274 | { |
| 275 | - $catArray=explode(':',$category); |
|
| 276 | - $retArray[$catArray[0]] = $catArray[1]; |
|
| 275 | + $catArray=explode(':', $category); |
|
| 276 | + $retArray[$catArray[0]]=$catArray[1]; |
|
| 277 | 277 | } |
| 278 | 278 | return $retArray; |
| 279 | 279 | } |
@@ -283,25 +283,25 @@ discard block |
||
| 283 | 283 | $catString=''; |
| 284 | 284 | foreach ($catArray as $index => $value) |
| 285 | 285 | { |
| 286 | - if ($catString != '' ) $catString .= '!'; |
|
| 287 | - $catString .= $index . ':' . $value; |
|
| 286 | + if ($catString != '') $catString.='!'; |
|
| 287 | + $catString.=$index.':'.$value; |
|
| 288 | 288 | } |
| 289 | 289 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | public function addHandlersCategory(string $catName) |
| 293 | 293 | { |
| 294 | - $catArray = $this->getHandlersCategory(); |
|
| 294 | + $catArray=$this->getHandlersCategory(); |
|
| 295 | 295 | $i=1; |
| 296 | 296 | while (isset($catArray[$i]) && $i < 100) $i++; |
| 297 | 297 | if ($i == 100) throw new ProgrammingError('Category array error'); |
| 298 | - $catArray[$i] = $catName; |
|
| 298 | + $catArray[$i]=$catName; |
|
| 299 | 299 | $this->setHandlerCategory($catArray); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | public function delHandlersCategory(int $catIndex) |
| 303 | 303 | { |
| 304 | - $catArray = $this->getHandlersCategory(); |
|
| 304 | + $catArray=$this->getHandlersCategory(); |
|
| 305 | 305 | unset($catArray[$catIndex]); |
| 306 | 306 | $this->setHandlerCategory($catArray); |
| 307 | 307 | $this->getUIDatabase()->updateHandlersOnCategoryDelete($catIndex); |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | public function renameHandlersCategory(int $catIndex, string $catName) |
| 311 | 311 | { |
| 312 | - $catArray = $this->getHandlersCategory(); |
|
| 313 | - $catArray[$catIndex] = $catName; |
|
| 312 | + $catArray=$this->getHandlersCategory(); |
|
| 313 | + $catArray[$catIndex]=$catName; |
|
| 314 | 314 | $this->setHandlerCategory($catArray); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -131,9 +131,11 @@ discard block |
||
| 131 | 131 | $this->icingaAPI = new Icinga2API($host,$port); |
| 132 | 132 | $this->icingaAPI->setCredentials($user, $pass); |
| 133 | 133 | list($ret,$message) = $this->icingaAPI->test($this->getModuleConfig()->getapiUserPermissions()); |
| 134 | - if ($ret === TRUE) // On error, switch to ido DB |
|
| 134 | + if ($ret === TRUE) { |
|
| 135 | + // On error, switch to ido DB |
|
| 135 | 136 | { |
| 136 | 137 | $this->apiMode = FALSE; |
| 138 | + } |
|
| 137 | 139 | return $this->getUIDatabase(); |
| 138 | 140 | } |
| 139 | 141 | $this->apiMode = TRUE; |
@@ -213,7 +215,9 @@ discard block |
||
| 213 | 215 | if ($this->MIBData == null) |
| 214 | 216 | { |
| 215 | 217 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 216 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 218 | + if ($dbConn === null) { |
|
| 219 | + throw new \ErrorException('uncatched db error'); |
|
| 220 | + } |
|
| 217 | 221 | $this->MIBData=new MIBLoader( |
| 218 | 222 | $this->Config()->get('config', 'snmptranslate'), |
| 219 | 223 | $this->Config()->get('config', 'snmptranslate_dirs'), |
@@ -283,7 +287,9 @@ discard block |
||
| 283 | 287 | $catString=''; |
| 284 | 288 | foreach ($catArray as $index => $value) |
| 285 | 289 | { |
| 286 | - if ($catString != '' ) $catString .= '!'; |
|
| 290 | + if ($catString != '' ) { |
|
| 291 | + $catString .= '!'; |
|
| 292 | + } |
|
| 287 | 293 | $catString .= $index . ':' . $value; |
| 288 | 294 | } |
| 289 | 295 | $this->getUIDatabase()->setDBConfigValue('handler_categories', $catString); |
@@ -293,8 +299,12 @@ discard block |
||
| 293 | 299 | { |
| 294 | 300 | $catArray = $this->getHandlersCategory(); |
| 295 | 301 | $i=1; |
| 296 | - while (isset($catArray[$i]) && $i < 100) $i++; |
|
| 297 | - if ($i == 100) throw new ProgrammingError('Category array error'); |
|
| 302 | + while (isset($catArray[$i]) && $i < 100) { |
|
| 303 | + $i++; |
|
| 304 | + } |
|
| 305 | + if ($i == 100) { |
|
| 306 | + throw new ProgrammingError('Category array error'); |
|
| 307 | + } |
|
| 298 | 308 | $catArray[$i] = $catName; |
| 299 | 309 | $this->setHandlerCategory($catArray); |
| 300 | 310 | } |
@@ -8,347 +8,347 @@ |
||
| 8 | 8 | |
| 9 | 9 | class IcingaApiBase |
| 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 $queryURL=array( |
|
| 22 | - 'host' => 'objects/hosts', |
|
| 23 | - 'hostgroup' => 'objects/hostgroups', |
|
| 24 | - 'service' => 'objects/services' |
|
| 25 | - ); |
|
| 21 | + protected $queryURL=array( |
|
| 22 | + 'host' => 'objects/hosts', |
|
| 23 | + 'hostgroup' => 'objects/hostgroups', |
|
| 24 | + 'service' => 'objects/services' |
|
| 25 | + ); |
|
| 26 | 26 | |
| 27 | - protected $curl; |
|
| 28 | - // http://php.net/manual/de/function.json-last-error.php#119985 |
|
| 29 | - protected $errorReference = [ |
|
| 30 | - JSON_ERROR_NONE => 'No error has occurred.', |
|
| 31 | - JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
|
| 32 | - JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
|
| 33 | - JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.', |
|
| 34 | - JSON_ERROR_SYNTAX => 'Syntax error.', |
|
| 35 | - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.', |
|
| 36 | - JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.', |
|
| 37 | - JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
|
| 38 | - JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
|
| 39 | - ]; |
|
| 40 | - const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
| 27 | + protected $curl; |
|
| 28 | + // http://php.net/manual/de/function.json-last-error.php#119985 |
|
| 29 | + protected $errorReference = [ |
|
| 30 | + JSON_ERROR_NONE => 'No error has occurred.', |
|
| 31 | + JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
|
| 32 | + JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
|
| 33 | + JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded.', |
|
| 34 | + JSON_ERROR_SYNTAX => 'Syntax error.', |
|
| 35 | + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded.', |
|
| 36 | + JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded.', |
|
| 37 | + JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
|
| 38 | + JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
|
| 39 | + ]; |
|
| 40 | + const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Creates Icinga2API object |
|
| 44 | - * |
|
| 45 | - * @param string $host host name or IP |
|
| 46 | - * @param number $port API port |
|
| 47 | - */ |
|
| 48 | - public function __construct($host, $port = 5665) |
|
| 49 | - { |
|
| 50 | - $this->host=$host; |
|
| 51 | - $this->port=$port; |
|
| 52 | - } |
|
| 53 | - /** |
|
| 54 | - * Set user & pass |
|
| 55 | - * @param string $user |
|
| 56 | - * @param string $pass |
|
| 57 | - */ |
|
| 58 | - public function setCredentials($user,$pass) |
|
| 59 | - { |
|
| 60 | - $this->user=$user; |
|
| 61 | - $this->pass=$pass; |
|
| 62 | - $this->authmethod='pass'; |
|
| 63 | - } |
|
| 42 | + /** |
|
| 43 | + * Creates Icinga2API object |
|
| 44 | + * |
|
| 45 | + * @param string $host host name or IP |
|
| 46 | + * @param number $port API port |
|
| 47 | + */ |
|
| 48 | + public function __construct($host, $port = 5665) |
|
| 49 | + { |
|
| 50 | + $this->host=$host; |
|
| 51 | + $this->port=$port; |
|
| 52 | + } |
|
| 53 | + /** |
|
| 54 | + * Set user & pass |
|
| 55 | + * @param string $user |
|
| 56 | + * @param string $pass |
|
| 57 | + */ |
|
| 58 | + public function setCredentials($user,$pass) |
|
| 59 | + { |
|
| 60 | + $this->user=$user; |
|
| 61 | + $this->pass=$pass; |
|
| 62 | + $this->authmethod='pass'; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException) |
|
| 67 | - * @param string $user |
|
| 68 | - * @param string $usercert |
|
| 69 | - */ |
|
| 70 | - public function setCredentialskey($user,$usercert) |
|
| 71 | - { |
|
| 72 | - $this->user=$user; |
|
| 73 | - $this->usercert=$usercert; |
|
| 74 | - $this->authmethod='cert'; |
|
| 75 | - throw new RuntimeException('Certificate auth not implemented'); |
|
| 76 | - } |
|
| 65 | + /** |
|
| 66 | + * Set user & certificate (NOT IMPLEMENTED @throws RuntimeException) |
|
| 67 | + * @param string $user |
|
| 68 | + * @param string $usercert |
|
| 69 | + */ |
|
| 70 | + public function setCredentialskey($user,$usercert) |
|
| 71 | + { |
|
| 72 | + $this->user=$user; |
|
| 73 | + $this->usercert=$usercert; |
|
| 74 | + $this->authmethod='cert'; |
|
| 75 | + throw new RuntimeException('Certificate auth not implemented'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Test API connection |
|
| 80 | - * @param array $permissions : check permissions if not null or empty |
|
| 81 | - * @return array (bool,string) : bool = false is all OK, else true with message |
|
| 82 | - * */ |
|
| 83 | - public function test(array $permissions) |
|
| 84 | - { |
|
| 85 | - try |
|
| 86 | - { |
|
| 87 | - $result=$this->request('GET', "", NULL, NULL); |
|
| 88 | - } |
|
| 89 | - catch (Exception $e) |
|
| 90 | - { |
|
| 91 | - return array(true, 'Error with API : '.$e->getMessage()); |
|
| 92 | - } |
|
| 93 | - //var_dump($result); |
|
| 94 | - $permOk=1; |
|
| 95 | - $permMissing=''; |
|
| 96 | - if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
|
| 97 | - { |
|
| 98 | - return array(false,'OK'); |
|
| 99 | - } |
|
| 100 | - if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
| 101 | - { |
|
| 78 | + /** |
|
| 79 | + * Test API connection |
|
| 80 | + * @param array $permissions : check permissions if not null or empty |
|
| 81 | + * @return array (bool,string) : bool = false is all OK, else true with message |
|
| 82 | + * */ |
|
| 83 | + public function test(array $permissions) |
|
| 84 | + { |
|
| 85 | + try |
|
| 86 | + { |
|
| 87 | + $result=$this->request('GET', "", NULL, NULL); |
|
| 88 | + } |
|
| 89 | + catch (Exception $e) |
|
| 90 | + { |
|
| 91 | + return array(true, 'Error with API : '.$e->getMessage()); |
|
| 92 | + } |
|
| 93 | + //var_dump($result); |
|
| 94 | + $permOk=1; |
|
| 95 | + $permMissing=''; |
|
| 96 | + if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
|
| 97 | + { |
|
| 98 | + return array(false,'OK'); |
|
| 99 | + } |
|
| 100 | + if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
|
| 101 | + { |
|
| 102 | 102 | |
| 103 | - foreach ( $permissions as $mustPermission) |
|
| 104 | - { |
|
| 105 | - $curPermOK=0; |
|
| 106 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
| 107 | - { |
|
| 108 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
| 109 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
| 110 | - { |
|
| 111 | - $curPermOK=1; |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - if ($curPermOK == 0) |
|
| 116 | - { |
|
| 117 | - $permOk=0; |
|
| 118 | - $permMissing=$mustPermission; |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - if ($permOk == 0) |
|
| 123 | - { |
|
| 124 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
| 125 | - } |
|
| 126 | - return array(false,'API connection OK'); |
|
| 103 | + foreach ( $permissions as $mustPermission) |
|
| 104 | + { |
|
| 105 | + $curPermOK=0; |
|
| 106 | + foreach ( $result->results[0]->permissions as $curPermission) |
|
| 107 | + { |
|
| 108 | + $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
| 109 | + if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
| 110 | + { |
|
| 111 | + $curPermOK=1; |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + if ($curPermOK == 0) |
|
| 116 | + { |
|
| 117 | + $permOk=0; |
|
| 118 | + $permMissing=$mustPermission; |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + if ($permOk == 0) |
|
| 123 | + { |
|
| 124 | + return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
| 125 | + } |
|
| 126 | + return array(false,'API connection OK'); |
|
| 127 | 127 | |
| 128 | - } |
|
| 129 | - return array(true,'API connection OK, but cannot get permissions'); |
|
| 130 | - } |
|
| 128 | + } |
|
| 129 | + return array(true,'API connection OK, but cannot get permissions'); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | |
| 133 | - protected function url($url) { |
|
| 134 | - return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
| 135 | - } |
|
| 133 | + protected function url($url) { |
|
| 134 | + return sprintf('https://%s:%d/%s/%s', $this->host, $this->port, $this->version, $url); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Create or return curl ressource |
|
| 139 | - * @throws Exception |
|
| 140 | - * @return resource |
|
| 141 | - */ |
|
| 142 | - protected function curl() { |
|
| 143 | - if ($this->curl === null) { |
|
| 144 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 145 | - if ($this->curl === false) { |
|
| 146 | - throw new Exception('CURL INIT ERROR'); |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - return $this->curl; |
|
| 150 | - } |
|
| 137 | + /** |
|
| 138 | + * Create or return curl ressource |
|
| 139 | + * @throws Exception |
|
| 140 | + * @return resource |
|
| 141 | + */ |
|
| 142 | + protected function curl() { |
|
| 143 | + if ($this->curl === null) { |
|
| 144 | + $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 145 | + if ($this->curl === false) { |
|
| 146 | + throw new Exception('CURL INIT ERROR'); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + return $this->curl; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Send a passive service check |
|
| 154 | - * @param string $host : host name |
|
| 155 | - * @param string $service : service name |
|
| 156 | - * @param int $state : state of service |
|
| 157 | - * @param string $display : service passive check output |
|
| 158 | - * @param string $perfdata : performance data as string |
|
| 159 | - * @return array (status = true (oK) or false (nok), string message) |
|
| 160 | - */ |
|
| 161 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
| 162 | - { |
|
| 163 | - //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
| 164 | - //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
| 165 | - $url='actions/process-check-result'; |
|
| 166 | - $body=array( |
|
| 167 | - "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
| 168 | - 'type' => 'Service', |
|
| 169 | - "exit_status" => $state, |
|
| 170 | - "plugin_output" => $display, |
|
| 171 | - "performance_data" => $perfdata |
|
| 172 | - ); |
|
| 173 | - try |
|
| 174 | - { |
|
| 175 | - $result=$this->request('POST', $url, null, $body); |
|
| 176 | - } catch (Exception $e) |
|
| 177 | - { |
|
| 178 | - return array(false, $e->getMessage()); |
|
| 179 | - } |
|
| 180 | - if (property_exists($result,'error') ) |
|
| 181 | - { |
|
| 182 | - if (property_exists($result,'status')) |
|
| 183 | - { |
|
| 184 | - $message=$result->status; |
|
| 185 | - } |
|
| 186 | - else |
|
| 187 | - { |
|
| 188 | - $message="Unkown status"; |
|
| 189 | - } |
|
| 190 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
| 191 | - } |
|
| 192 | - if (property_exists($result, 'results')) |
|
| 193 | - { |
|
| 194 | - if (isset($result->results[0])) |
|
| 195 | - { |
|
| 196 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 197 | - } |
|
| 198 | - else |
|
| 199 | - { |
|
| 200 | - return array(false,'Service not found'); |
|
| 201 | - } |
|
| 152 | + /** |
|
| 153 | + * Send a passive service check |
|
| 154 | + * @param string $host : host name |
|
| 155 | + * @param string $service : service name |
|
| 156 | + * @param int $state : state of service |
|
| 157 | + * @param string $display : service passive check output |
|
| 158 | + * @param string $perfdata : performance data as string |
|
| 159 | + * @return array (status = true (oK) or false (nok), string message) |
|
| 160 | + */ |
|
| 161 | + public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
| 162 | + { |
|
| 163 | + //Send a POST request to the URL endpoint /v1/actions/process-check-result |
|
| 164 | + //actions/process-check-result?service=example.localdomain!passive-ping6 |
|
| 165 | + $url='actions/process-check-result'; |
|
| 166 | + $body=array( |
|
| 167 | + "filter" => 'service.name=="'.$service.'" && service.host_name=="'.$host.'"', |
|
| 168 | + 'type' => 'Service', |
|
| 169 | + "exit_status" => $state, |
|
| 170 | + "plugin_output" => $display, |
|
| 171 | + "performance_data" => $perfdata |
|
| 172 | + ); |
|
| 173 | + try |
|
| 174 | + { |
|
| 175 | + $result=$this->request('POST', $url, null, $body); |
|
| 176 | + } catch (Exception $e) |
|
| 177 | + { |
|
| 178 | + return array(false, $e->getMessage()); |
|
| 179 | + } |
|
| 180 | + if (property_exists($result,'error') ) |
|
| 181 | + { |
|
| 182 | + if (property_exists($result,'status')) |
|
| 183 | + { |
|
| 184 | + $message=$result->status; |
|
| 185 | + } |
|
| 186 | + else |
|
| 187 | + { |
|
| 188 | + $message="Unkown status"; |
|
| 189 | + } |
|
| 190 | + return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
| 191 | + } |
|
| 192 | + if (property_exists($result, 'results')) |
|
| 193 | + { |
|
| 194 | + if (isset($result->results[0])) |
|
| 195 | + { |
|
| 196 | + return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 197 | + } |
|
| 198 | + else |
|
| 199 | + { |
|
| 200 | + return array(false,'Service not found'); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - } |
|
| 204 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
| 205 | - } |
|
| 203 | + } |
|
| 204 | + return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Check 'result' exists and check for errors/status |
|
| 209 | - * @param \stdClass $result |
|
| 210 | - * @throws Exception |
|
| 211 | - */ |
|
| 212 | - public function checkResultStatus(\stdClass $result) |
|
| 213 | - { |
|
| 214 | - if (property_exists($result,'error') ) |
|
| 215 | - { |
|
| 216 | - if (property_exists($result,'status')) |
|
| 217 | - { |
|
| 218 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 219 | - } |
|
| 220 | - else |
|
| 221 | - { |
|
| 222 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - if ( ! property_exists($result, 'results')) |
|
| 226 | - { |
|
| 227 | - throw new Exception('Unkown result'); |
|
| 228 | - } |
|
| 229 | - } |
|
| 207 | + /** |
|
| 208 | + * Check 'result' exists and check for errors/status |
|
| 209 | + * @param \stdClass $result |
|
| 210 | + * @throws Exception |
|
| 211 | + */ |
|
| 212 | + public function checkResultStatus(\stdClass $result) |
|
| 213 | + { |
|
| 214 | + if (property_exists($result,'error') ) |
|
| 215 | + { |
|
| 216 | + if (property_exists($result,'status')) |
|
| 217 | + { |
|
| 218 | + throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 219 | + } |
|
| 220 | + else |
|
| 221 | + { |
|
| 222 | + throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + if ( ! property_exists($result, 'results')) |
|
| 226 | + { |
|
| 227 | + throw new Exception('Unkown result'); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - /** |
|
| 232 | - * Send request to API |
|
| 233 | - * @param string $method get/post/... |
|
| 234 | - * @param string $url (after /v1/ ) |
|
| 235 | - * @param array $headers |
|
| 236 | - * @param array $body |
|
| 237 | - * @throws Exception |
|
| 238 | - * @return array |
|
| 239 | - */ |
|
| 240 | - public function request($method, $url, $headers, $body) { |
|
| 241 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
| 242 | - $curlHeaders = array("Accept: application/json"); |
|
| 243 | - if ($body !== null) { |
|
| 244 | - $body = json_encode($body); |
|
| 245 | - array_push($curlHeaders, 'Content-Type: application/json'); |
|
| 246 | - //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
| 247 | - } |
|
| 248 | - //var_dump($body); |
|
| 249 | - //var_dump($this->url($url)); |
|
| 250 | - if ($headers !== null) { |
|
| 251 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
| 252 | - } else |
|
| 253 | - { |
|
| 254 | - $curlFinalHeaders=$curlHeaders; |
|
| 255 | - } |
|
| 256 | - $curl = $this->curl(); |
|
| 257 | - $opts = array( |
|
| 258 | - CURLOPT_URL => $this->url($url), |
|
| 259 | - CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
| 260 | - CURLOPT_USERPWD => $auth, |
|
| 261 | - CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
| 262 | - CURLOPT_RETURNTRANSFER => true, |
|
| 263 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
| 264 | - CURLOPT_SSL_VERIFYHOST => false, |
|
| 265 | - CURLOPT_SSL_VERIFYPEER => false, |
|
| 266 | - ); |
|
| 267 | - if ($body !== null) { |
|
| 268 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
| 269 | - } |
|
| 270 | - curl_setopt_array($curl, $opts); |
|
| 271 | - $res = curl_exec($curl); |
|
| 272 | - if ($res === false) { |
|
| 273 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
| 274 | - } |
|
| 275 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 276 | - if ($statusCode === 401) { |
|
| 277 | - throw new Exception('Unable to authenticate, please check your API credentials'); |
|
| 278 | - } |
|
| 279 | - return $this->fromJsonResult($res); |
|
| 280 | - } |
|
| 231 | + /** |
|
| 232 | + * Send request to API |
|
| 233 | + * @param string $method get/post/... |
|
| 234 | + * @param string $url (after /v1/ ) |
|
| 235 | + * @param array $headers |
|
| 236 | + * @param array $body |
|
| 237 | + * @throws Exception |
|
| 238 | + * @return array |
|
| 239 | + */ |
|
| 240 | + public function request($method, $url, $headers, $body) { |
|
| 241 | + $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
| 242 | + $curlHeaders = array("Accept: application/json"); |
|
| 243 | + if ($body !== null) { |
|
| 244 | + $body = json_encode($body); |
|
| 245 | + array_push($curlHeaders, 'Content-Type: application/json'); |
|
| 246 | + //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
|
| 247 | + } |
|
| 248 | + //var_dump($body); |
|
| 249 | + //var_dump($this->url($url)); |
|
| 250 | + if ($headers !== null) { |
|
| 251 | + $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
| 252 | + } else |
|
| 253 | + { |
|
| 254 | + $curlFinalHeaders=$curlHeaders; |
|
| 255 | + } |
|
| 256 | + $curl = $this->curl(); |
|
| 257 | + $opts = array( |
|
| 258 | + CURLOPT_URL => $this->url($url), |
|
| 259 | + CURLOPT_HTTPHEADER => $curlFinalHeaders, |
|
| 260 | + CURLOPT_USERPWD => $auth, |
|
| 261 | + CURLOPT_CUSTOMREQUEST => strtoupper($method), |
|
| 262 | + CURLOPT_RETURNTRANSFER => true, |
|
| 263 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
| 264 | + CURLOPT_SSL_VERIFYHOST => false, |
|
| 265 | + CURLOPT_SSL_VERIFYPEER => false, |
|
| 266 | + ); |
|
| 267 | + if ($body !== null) { |
|
| 268 | + $opts[CURLOPT_POSTFIELDS] = $body; |
|
| 269 | + } |
|
| 270 | + curl_setopt_array($curl, $opts); |
|
| 271 | + $res = curl_exec($curl); |
|
| 272 | + if ($res === false) { |
|
| 273 | + throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
| 274 | + } |
|
| 275 | + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 276 | + if ($statusCode === 401) { |
|
| 277 | + throw new Exception('Unable to authenticate, please check your API credentials'); |
|
| 278 | + } |
|
| 279 | + return $this->fromJsonResult($res); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * |
|
| 284 | - * @param string $json json encoded |
|
| 285 | - * @throws Exception |
|
| 286 | - * @return array json decoded |
|
| 287 | - */ |
|
| 288 | - protected function fromJsonResult($json) { |
|
| 289 | - $result = @json_decode($json); |
|
| 290 | - //var_dump($json); |
|
| 291 | - if ($result === null) { |
|
| 292 | - throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
| 293 | - } |
|
| 294 | - return $result; |
|
| 295 | - } |
|
| 282 | + /** |
|
| 283 | + * |
|
| 284 | + * @param string $json json encoded |
|
| 285 | + * @throws Exception |
|
| 286 | + * @return array json decoded |
|
| 287 | + */ |
|
| 288 | + protected function fromJsonResult($json) { |
|
| 289 | + $result = @json_decode($json); |
|
| 290 | + //var_dump($json); |
|
| 291 | + if ($result === null) { |
|
| 292 | + throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
|
| 293 | + } |
|
| 294 | + return $result; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Return text error no json error |
|
| 299 | - * @param string $errorCode |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - protected function getLastJsonErrorMessage($errorCode) { |
|
| 303 | - if (!array_key_exists($errorCode, $this->errorReference)) { |
|
| 304 | - return self::JSON_UNKNOWN_ERROR; |
|
| 305 | - } |
|
| 306 | - return $this->errorReference[$errorCode]; |
|
| 307 | - } |
|
| 297 | + /** |
|
| 298 | + * Return text error no json error |
|
| 299 | + * @param string $errorCode |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + protected function getLastJsonErrorMessage($errorCode) { |
|
| 303 | + if (!array_key_exists($errorCode, $this->errorReference)) { |
|
| 304 | + return self::JSON_UNKNOWN_ERROR; |
|
| 305 | + } |
|
| 306 | + return $this->errorReference[$errorCode]; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - public function standardQuery(string $urlType , string $filter, array $attributes) |
|
| 310 | - { |
|
| 311 | - /* |
|
| 309 | + public function standardQuery(string $urlType , string $filter, array $attributes) |
|
| 310 | + { |
|
| 311 | + /* |
|
| 312 | 312 | * curl -k -s -u trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' |
| 313 | 313 | * -d '{"filter":"\"test_trap\" in host.groups","attrs": ["address" ,"address6"],"pretty": true}' |
| 314 | 314 | |
| 315 | 315 | {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]} |
| 316 | 316 | */ |
| 317 | 317 | |
| 318 | - if (! isset($this->queryURL[$urlType] )) |
|
| 319 | - { |
|
| 320 | - throw new Exception("Unkown object type"); |
|
| 321 | - } |
|
| 322 | - $url=$this->queryURL[$urlType]; |
|
| 323 | - $body=array(); |
|
| 324 | - if ($filter !== NULL) |
|
| 325 | - { |
|
| 326 | - $body['filter'] = $filter; |
|
| 327 | - } |
|
| 328 | - if (count($attributes) != 0) |
|
| 329 | - { |
|
| 330 | - $body['attrs'] = $attributes; |
|
| 331 | - } |
|
| 318 | + if (! isset($this->queryURL[$urlType] )) |
|
| 319 | + { |
|
| 320 | + throw new Exception("Unkown object type"); |
|
| 321 | + } |
|
| 322 | + $url=$this->queryURL[$urlType]; |
|
| 323 | + $body=array(); |
|
| 324 | + if ($filter !== NULL) |
|
| 325 | + { |
|
| 326 | + $body['filter'] = $filter; |
|
| 327 | + } |
|
| 328 | + if (count($attributes) != 0) |
|
| 329 | + { |
|
| 330 | + $body['attrs'] = $attributes; |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - try |
|
| 334 | - { |
|
| 335 | - $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 336 | - } catch (Exception $e) |
|
| 337 | - { |
|
| 338 | - throw new Exception($e->getMessage()); |
|
| 339 | - } |
|
| 333 | + try |
|
| 334 | + { |
|
| 335 | + $result=$this->request('POST', $url, array('X-HTTP-Method-Override: GET'), $body); |
|
| 336 | + } catch (Exception $e) |
|
| 337 | + { |
|
| 338 | + throw new Exception($e->getMessage()); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $this->checkResultStatus($result); |
|
| 341 | + $this->checkResultStatus($result); |
|
| 342 | 342 | |
| 343 | - $numHost=0; |
|
| 344 | - $hostArray=array(); |
|
| 345 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 346 | - { |
|
| 347 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 348 | - $numHost++; |
|
| 349 | - } |
|
| 350 | - return $hostArray; |
|
| 351 | - } |
|
| 343 | + $numHost=0; |
|
| 344 | + $hostArray=array(); |
|
| 345 | + while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 346 | + { |
|
| 347 | + $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 348 | + $numHost++; |
|
| 349 | + } |
|
| 350 | + return $hostArray; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | 353 | } |
| 354 | 354 | |
@@ -8,15 +8,15 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | class IcingaApiBase |
| 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 | 21 | protected $queryURL=array( |
| 22 | 22 | 'host' => 'objects/hosts', |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | protected $curl; |
| 28 | 28 | // http://php.net/manual/de/function.json-last-error.php#119985 |
| 29 | - protected $errorReference = [ |
|
| 29 | + protected $errorReference=[ |
|
| 30 | 30 | JSON_ERROR_NONE => 'No error has occurred.', |
| 31 | 31 | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
| 32 | 32 | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
| 38 | 38 | JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
| 39 | 39 | ]; |
| 40 | - const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
| 40 | + const JSON_UNKNOWN_ERROR='Unknown error.'; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Creates Icinga2API object |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param string $host host name or IP |
| 46 | 46 | * @param number $port API port |
| 47 | 47 | */ |
| 48 | - public function __construct($host, $port = 5665) |
|
| 48 | + public function __construct($host, $port=5665) |
|
| 49 | 49 | { |
| 50 | 50 | $this->host=$host; |
| 51 | 51 | $this->port=$port; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param string $user |
| 56 | 56 | * @param string $pass |
| 57 | 57 | */ |
| 58 | - public function setCredentials($user,$pass) |
|
| 58 | + public function setCredentials($user, $pass) |
|
| 59 | 59 | { |
| 60 | 60 | $this->user=$user; |
| 61 | 61 | $this->pass=$pass; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param string $user |
| 68 | 68 | * @param string $usercert |
| 69 | 69 | */ |
| 70 | - public function setCredentialskey($user,$usercert) |
|
| 70 | + public function setCredentialskey($user, $usercert) |
|
| 71 | 71 | { |
| 72 | 72 | $this->user=$user; |
| 73 | 73 | $this->usercert=$usercert; |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | $permMissing=''; |
| 96 | 96 | if ($permissions === NULL || count($permissions) == 0) // If no permission check return OK after connexion |
| 97 | 97 | { |
| 98 | - return array(false,'OK'); |
|
| 98 | + return array(false, 'OK'); |
|
| 99 | 99 | } |
| 100 | 100 | if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
| 101 | 101 | { |
| 102 | 102 | |
| 103 | - foreach ( $permissions as $mustPermission) |
|
| 103 | + foreach ($permissions as $mustPermission) |
|
| 104 | 104 | { |
| 105 | 105 | $curPermOK=0; |
| 106 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
| 106 | + foreach ($result->results[0]->permissions as $curPermission) |
|
| 107 | 107 | { |
| 108 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
| 109 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
| 108 | + $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp |
|
| 109 | + if (preg_match('#'.$curPermission.'#', $mustPermission)) |
|
| 110 | 110 | { |
| 111 | 111 | $curPermOK=1; |
| 112 | 112 | break; |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | if ($permOk == 0) |
| 123 | 123 | { |
| 124 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
| 124 | + return array(true, 'API connection OK, but missing permission : '.$permMissing); |
|
| 125 | 125 | } |
| 126 | - return array(false,'API connection OK'); |
|
| 126 | + return array(false, 'API connection OK'); |
|
| 127 | 127 | |
| 128 | 128 | } |
| 129 | - return array(true,'API connection OK, but cannot get permissions'); |
|
| 129 | + return array(true, 'API connection OK, but cannot get permissions'); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | protected function curl() { |
| 143 | 143 | if ($this->curl === null) { |
| 144 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 144 | + $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
| 145 | 145 | if ($this->curl === false) { |
| 146 | 146 | throw new Exception('CURL INIT ERROR'); |
| 147 | 147 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param string $perfdata : performance data as string |
| 159 | 159 | * @return array (status = true (oK) or false (nok), string message) |
| 160 | 160 | */ |
| 161 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
| 161 | + public function serviceCheckResult($host, $service, $state, $display, $perfdata='') |
|
| 162 | 162 | { |
| 163 | 163 | //Send a POST request to the URL endpoint /v1/actions/process-check-result |
| 164 | 164 | //actions/process-check-result?service=example.localdomain!passive-ping6 |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | { |
| 178 | 178 | return array(false, $e->getMessage()); |
| 179 | 179 | } |
| 180 | - if (property_exists($result,'error') ) |
|
| 180 | + if (property_exists($result, 'error')) |
|
| 181 | 181 | { |
| 182 | - if (property_exists($result,'status')) |
|
| 182 | + if (property_exists($result, 'status')) |
|
| 183 | 183 | { |
| 184 | 184 | $message=$result->status; |
| 185 | 185 | } |
@@ -187,21 +187,21 @@ discard block |
||
| 187 | 187 | { |
| 188 | 188 | $message="Unkown status"; |
| 189 | 189 | } |
| 190 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
| 190 | + return array(false, 'Ret code '.$result->error.' : '.$message); |
|
| 191 | 191 | } |
| 192 | 192 | if (property_exists($result, 'results')) |
| 193 | 193 | { |
| 194 | 194 | if (isset($result->results[0])) |
| 195 | 195 | { |
| 196 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 196 | + return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
| 197 | 197 | } |
| 198 | 198 | else |
| 199 | 199 | { |
| 200 | - return array(false,'Service not found'); |
|
| 200 | + return array(false, 'Service not found'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | } |
| 204 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
| 204 | + return array(false, 'Unkown result, open issue with this : '.print_r($result, true)); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public function checkResultStatus(\stdClass $result) |
| 213 | 213 | { |
| 214 | - if (property_exists($result,'error') ) |
|
| 214 | + if (property_exists($result, 'error')) |
|
| 215 | 215 | { |
| 216 | - if (property_exists($result,'status')) |
|
| 216 | + if (property_exists($result, 'status')) |
|
| 217 | 217 | { |
| 218 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
| 218 | + throw new Exception('Ret code '.$result->error.' : '.$result->status); |
|
| 219 | 219 | } |
| 220 | 220 | else |
| 221 | 221 | { |
| 222 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
| 222 | + throw new Exception('Ret code '.$result->error.' : Unkown status'); |
|
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | - if ( ! property_exists($result, 'results')) |
|
| 225 | + if (!property_exists($result, 'results')) |
|
| 226 | 226 | { |
| 227 | 227 | throw new Exception('Unkown result'); |
| 228 | 228 | } |
@@ -238,23 +238,23 @@ discard block |
||
| 238 | 238 | * @return array |
| 239 | 239 | */ |
| 240 | 240 | public function request($method, $url, $headers, $body) { |
| 241 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
| 242 | - $curlHeaders = array("Accept: application/json"); |
|
| 241 | + $auth=sprintf('%s:%s', $this->user, $this->pass); |
|
| 242 | + $curlHeaders=array("Accept: application/json"); |
|
| 243 | 243 | if ($body !== null) { |
| 244 | - $body = json_encode($body); |
|
| 244 | + $body=json_encode($body); |
|
| 245 | 245 | array_push($curlHeaders, 'Content-Type: application/json'); |
| 246 | 246 | //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
| 247 | 247 | } |
| 248 | 248 | //var_dump($body); |
| 249 | 249 | //var_dump($this->url($url)); |
| 250 | 250 | if ($headers !== null) { |
| 251 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
| 251 | + $curlFinalHeaders=array_merge($curlHeaders, $headers); |
|
| 252 | 252 | } else |
| 253 | 253 | { |
| 254 | 254 | $curlFinalHeaders=$curlHeaders; |
| 255 | 255 | } |
| 256 | - $curl = $this->curl(); |
|
| 257 | - $opts = array( |
|
| 256 | + $curl=$this->curl(); |
|
| 257 | + $opts=array( |
|
| 258 | 258 | CURLOPT_URL => $this->url($url), |
| 259 | 259 | CURLOPT_HTTPHEADER => $curlFinalHeaders, |
| 260 | 260 | CURLOPT_USERPWD => $auth, |
@@ -265,14 +265,14 @@ discard block |
||
| 265 | 265 | CURLOPT_SSL_VERIFYPEER => false, |
| 266 | 266 | ); |
| 267 | 267 | if ($body !== null) { |
| 268 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
| 268 | + $opts[CURLOPT_POSTFIELDS]=$body; |
|
| 269 | 269 | } |
| 270 | 270 | curl_setopt_array($curl, $opts); |
| 271 | - $res = curl_exec($curl); |
|
| 271 | + $res=curl_exec($curl); |
|
| 272 | 272 | if ($res === false) { |
| 273 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
| 273 | + throw new Exception('CURL ERROR: '.curl_error($curl)); |
|
| 274 | 274 | } |
| 275 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 275 | + $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 276 | 276 | if ($statusCode === 401) { |
| 277 | 277 | throw new Exception('Unable to authenticate, please check your API credentials'); |
| 278 | 278 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | * @return array json decoded |
| 287 | 287 | */ |
| 288 | 288 | protected function fromJsonResult($json) { |
| 289 | - $result = @json_decode($json); |
|
| 289 | + $result=@json_decode($json); |
|
| 290 | 290 | //var_dump($json); |
| 291 | 291 | if ($result === null) { |
| 292 | 292 | throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | return $this->errorReference[$errorCode]; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - public function standardQuery(string $urlType , string $filter, array $attributes) |
|
| 309 | + public function standardQuery(string $urlType, string $filter, array $attributes) |
|
| 310 | 310 | { |
| 311 | 311 | /* |
| 312 | 312 | * curl -k -s -u trapdirector:trapdirector -H 'X-HTTP-Method-Override: GET' -X POST 'https://localhost:5665/v1/objects/hosts' |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | {"results":[{"attrs":{"__name":"Icinga host","address":"127.0.0.1","display_name":"Icinga host","name":"Icinga host"},"joins":{},"meta":{},"name":"Icinga host","type":"Host"}]} |
| 316 | 316 | */ |
| 317 | 317 | |
| 318 | - if (! isset($this->queryURL[$urlType] )) |
|
| 318 | + if (!isset($this->queryURL[$urlType])) |
|
| 319 | 319 | { |
| 320 | 320 | throw new Exception("Unkown object type"); |
| 321 | 321 | } |
@@ -323,11 +323,11 @@ discard block |
||
| 323 | 323 | $body=array(); |
| 324 | 324 | if ($filter !== NULL) |
| 325 | 325 | { |
| 326 | - $body['filter'] = $filter; |
|
| 326 | + $body['filter']=$filter; |
|
| 327 | 327 | } |
| 328 | 328 | if (count($attributes) != 0) |
| 329 | 329 | { |
| 330 | - $body['attrs'] = $attributes; |
|
| 330 | + $body['attrs']=$attributes; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | try |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | |
| 343 | 343 | $numHost=0; |
| 344 | 344 | $hostArray=array(); |
| 345 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
| 345 | + while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs')) |
|
| 346 | 346 | { |
| 347 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
| 347 | + $hostArray[$numHost]=$result->results[$numHost]->attrs; |
|
| 348 | 348 | $numHost++; |
| 349 | 349 | } |
| 350 | 350 | return $hostArray; |
@@ -12,13 +12,12 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | //use Icinga\Web\Form as Form; |
| 14 | 14 | /** Rules management |
| 15 | - |
|
| 16 | -*/ |
|
| 15 | + */ |
|
| 17 | 16 | class HandlerController extends TrapsController |
| 18 | 17 | { |
| 19 | 18 | |
| 20 | 19 | /** index : list existing rules |
| 21 | - */ |
|
| 20 | + */ |
|
| 22 | 21 | public function indexAction() |
| 23 | 22 | { |
| 24 | 23 | $this->checkReadPermission(); |
@@ -28,13 +27,13 @@ discard block |
||
| 28 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 29 | 28 | |
| 30 | 29 | $handlerTable = new HandlerTable( |
| 31 | - $this->moduleConfig->getTrapRuleName(), |
|
| 32 | - $this->moduleConfig->getHandlerListTitles(), |
|
| 33 | - $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 34 | - $this->moduleConfig->getHandlerColumns(), |
|
| 35 | - $dbConn->getConnection(), |
|
| 36 | - $this->view, |
|
| 37 | - $this->moduleConfig->urlPath()); |
|
| 30 | + $this->moduleConfig->getTrapRuleName(), |
|
| 31 | + $this->moduleConfig->getHandlerListTitles(), |
|
| 32 | + $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 33 | + $this->moduleConfig->getHandlerColumns(), |
|
| 34 | + $dbConn->getConnection(), |
|
| 35 | + $this->view, |
|
| 36 | + $this->moduleConfig->urlPath()); |
|
| 38 | 37 | |
| 39 | 38 | $handlerTable->setMaxPerPage($this->itemListDisplay()); |
| 40 | 39 | |
@@ -56,7 +55,7 @@ discard block |
||
| 56 | 55 | |
| 57 | 56 | // TODO : Obsolete remove after new table validation. |
| 58 | 57 | |
| 59 | - /** |
|
| 58 | + /** |
|
| 60 | 59 | $this->getHandlerListTable()->setConnection($dbConn); |
| 61 | 60 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
| 62 | 61 | // Apply pagination limits |
@@ -73,22 +72,22 @@ discard block |
||
| 73 | 72 | */ |
| 74 | 73 | public function testruleAction() |
| 75 | 74 | { |
| 76 | - $this->checkReadPermission(); |
|
| 77 | - $this->getTabs()->add('get',array( |
|
| 78 | - 'active' => true, |
|
| 79 | - 'label' => $this->translate('Test Rule'), |
|
| 80 | - 'url' => Url::fromRequest() |
|
| 81 | - )); |
|
| 75 | + $this->checkReadPermission(); |
|
| 76 | + $this->getTabs()->add('get',array( |
|
| 77 | + 'active' => true, |
|
| 78 | + 'label' => $this->translate('Test Rule'), |
|
| 79 | + 'url' => Url::fromRequest() |
|
| 80 | + )); |
|
| 82 | 81 | |
| 83 | 82 | |
| 84 | - if ($this->params->get('rule') !== null) |
|
| 85 | - { |
|
| 86 | - $this->view->rule= $this->params->get('rule'); |
|
| 87 | - } |
|
| 88 | - else |
|
| 89 | - { |
|
| 90 | - $this->view->rule=''; |
|
| 91 | - } |
|
| 83 | + if ($this->params->get('rule') !== null) |
|
| 84 | + { |
|
| 85 | + $this->view->rule= $this->params->get('rule'); |
|
| 86 | + } |
|
| 87 | + else |
|
| 88 | + { |
|
| 89 | + $this->view->rule=''; |
|
| 90 | + } |
|
| 92 | 91 | } |
| 93 | 92 | |
| 94 | 93 | /** |
@@ -96,31 +95,31 @@ discard block |
||
| 96 | 95 | */ |
| 97 | 96 | private function add_setup_vars() |
| 98 | 97 | { |
| 99 | - // variables to send to view |
|
| 100 | - $this->view->hostlist=array(); // host list to input datalist |
|
| 101 | - $this->view->hostname=''; // Host name in input text |
|
| 102 | - $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 103 | - $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 104 | - $this->view->mainoid=''; // Trap OID |
|
| 105 | - $this->view->mib=''; // Trap mib |
|
| 106 | - $this->view->name=''; // Trap name |
|
| 107 | - $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 108 | - $this->view->objectList=array(); // objects sent with trap |
|
| 109 | - $this->view->display=''; // Initial display |
|
| 110 | - $this->view->rule=''; // rule display |
|
| 111 | - $this->view->revertOK=''; // revert OK in seconds |
|
| 112 | - $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 113 | - $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 114 | - $this->view->setToUpdate=false; // set form as update form |
|
| 115 | - $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 116 | - $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 98 | + // variables to send to view |
|
| 99 | + $this->view->hostlist=array(); // host list to input datalist |
|
| 100 | + $this->view->hostname=''; // Host name in input text |
|
| 101 | + $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 102 | + $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 103 | + $this->view->mainoid=''; // Trap OID |
|
| 104 | + $this->view->mib=''; // Trap mib |
|
| 105 | + $this->view->name=''; // Trap name |
|
| 106 | + $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 107 | + $this->view->objectList=array(); // objects sent with trap |
|
| 108 | + $this->view->display=''; // Initial display |
|
| 109 | + $this->view->rule=''; // rule display |
|
| 110 | + $this->view->revertOK=''; // revert OK in seconds |
|
| 111 | + $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 112 | + $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 113 | + $this->view->setToUpdate=false; // set form as update form |
|
| 114 | + $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 115 | + $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 117 | 116 | |
| 118 | - $this->view->selectGroup=false; // Select by group if true |
|
| 119 | - $this->view->hostgroupid=-1; // host group id |
|
| 120 | - $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 117 | + $this->view->selectGroup=false; // Select by group if true |
|
| 118 | + $this->view->hostgroupid=-1; // host group id |
|
| 119 | + $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 121 | 120 | |
| 122 | - $this->view->modifier=null; |
|
| 123 | - $this->view->modified=null; |
|
| 121 | + $this->view->modifier=null; |
|
| 122 | + $this->view->modified=null; |
|
| 124 | 123 | } |
| 125 | 124 | |
| 126 | 125 | /** |
@@ -129,102 +128,102 @@ discard block |
||
| 129 | 128 | */ |
| 130 | 129 | private function add_from_existing($trapid) |
| 131 | 130 | { |
| 132 | - /********** Setup from existing trap ***************/ |
|
| 133 | - // Get the full trap info |
|
| 134 | - $trapDetail=$this->getTrapDetail($trapid); |
|
| 131 | + /********** Setup from existing trap ***************/ |
|
| 132 | + // Get the full trap info |
|
| 133 | + $trapDetail=$this->getTrapDetail($trapid); |
|
| 135 | 134 | |
| 136 | - $hostfilter=$trapDetail->source_ip; |
|
| 135 | + $hostfilter=$trapDetail->source_ip; |
|
| 137 | 136 | |
| 138 | - // Get host |
|
| 139 | - try |
|
| 140 | - { |
|
| 141 | - $hosts=$this->getIdoConn()->getHostByIP($hostfilter); |
|
| 142 | - } |
|
| 143 | - catch (Exception $e) |
|
| 144 | - { |
|
| 145 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 146 | - } |
|
| 137 | + // Get host |
|
| 138 | + try |
|
| 139 | + { |
|
| 140 | + $hosts=$this->getIdoConn()->getHostByIP($hostfilter); |
|
| 141 | + } |
|
| 142 | + catch (Exception $e) |
|
| 143 | + { |
|
| 144 | + $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 145 | + } |
|
| 147 | 146 | |
| 148 | 147 | |
| 149 | - // if one unique host found -> put id text input |
|
| 150 | - if (count($hosts)==1) { |
|
| 151 | - $this->view->hostname=$hosts[0]->name; |
|
| 152 | - //$hostid=$hosts[0]->id; |
|
| 153 | - // Tell JS to get services when page is loaded |
|
| 154 | - $this->view->serviceGet=true; |
|
| 148 | + // if one unique host found -> put id text input |
|
| 149 | + if (count($hosts)==1) { |
|
| 150 | + $this->view->hostname=$hosts[0]->name; |
|
| 151 | + //$hostid=$hosts[0]->id; |
|
| 152 | + // Tell JS to get services when page is loaded |
|
| 153 | + $this->view->serviceGet=true; |
|
| 155 | 154 | |
| 156 | - } |
|
| 157 | - else |
|
| 158 | - { |
|
| 159 | - foreach($hosts as $key=>$val) |
|
| 160 | - { |
|
| 161 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 162 | - } |
|
| 163 | - } |
|
| 155 | + } |
|
| 156 | + else |
|
| 157 | + { |
|
| 158 | + foreach($hosts as $key=>$val) |
|
| 159 | + { |
|
| 160 | + array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 161 | + } |
|
| 162 | + } |
|
| 164 | 163 | |
| 165 | - // set up trap oid and objects received by the trap |
|
| 164 | + // set up trap oid and objects received by the trap |
|
| 166 | 165 | |
| 167 | - $this->view->mainoid=$trapDetail->trap_oid; |
|
| 168 | - if ($trapDetail->trap_name_mib != null) |
|
| 169 | - { |
|
| 170 | - $this->view->mib=$trapDetail->trap_name_mib; |
|
| 171 | - $this->view->name=$trapDetail->trap_name; |
|
| 172 | - $this->view->trapListForMIB=$this->getMIB() |
|
| 173 | - ->getTrapList($trapDetail->trap_name_mib); |
|
| 174 | - } |
|
| 166 | + $this->view->mainoid=$trapDetail->trap_oid; |
|
| 167 | + if ($trapDetail->trap_name_mib != null) |
|
| 168 | + { |
|
| 169 | + $this->view->mib=$trapDetail->trap_name_mib; |
|
| 170 | + $this->view->name=$trapDetail->trap_name; |
|
| 171 | + $this->view->trapListForMIB=$this->getMIB() |
|
| 172 | + ->getTrapList($trapDetail->trap_name_mib); |
|
| 173 | + } |
|
| 175 | 174 | |
| 176 | - // Get all objects that can be in trap from MIB |
|
| 177 | - $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 178 | - // Get all objects in current Trap |
|
| 179 | - $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 180 | - $oid_index=1; |
|
| 181 | - foreach ($currentTrapObjects as $key => $val) |
|
| 182 | - { |
|
| 183 | - $currentObjectType='Unknown'; |
|
| 184 | - $currentObjectTypeEnum='Unknown'; |
|
| 185 | - if (isset($allObjects[$val->oid]['type'])) |
|
| 186 | - { |
|
| 187 | - $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 188 | - $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 189 | - } |
|
| 190 | - $currentObject=array( |
|
| 191 | - $oid_index, |
|
| 192 | - $val->oid, |
|
| 193 | - $val->oid_name_mib, |
|
| 194 | - $val->oid_name, |
|
| 195 | - $val->value, |
|
| 196 | - $currentObjectType, |
|
| 197 | - $currentObjectTypeEnum |
|
| 198 | - ); |
|
| 199 | - $oid_index++; |
|
| 200 | - array_push($this->view->objectList,$currentObject); |
|
| 201 | - // set currrent object to null in allObjects |
|
| 202 | - if (isset($allObjects[$val->oid])) |
|
| 203 | - { |
|
| 204 | - $allObjects[$val->oid]=null; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 208 | - { |
|
| 209 | - foreach ($allObjects as $key => $val) |
|
| 210 | - { |
|
| 211 | - if ($val==null) { continue; } |
|
| 212 | - array_push($this->view->objectList, array( |
|
| 213 | - $oid_index, |
|
| 214 | - $key, |
|
| 215 | - $allObjects[$key]['mib'], |
|
| 216 | - $allObjects[$key]['name'], |
|
| 217 | - '', |
|
| 218 | - $allObjects[$key]['type'], |
|
| 219 | - $allObjects[$key]['type_enum'] |
|
| 220 | - )); |
|
| 221 | - $oid_index++; |
|
| 222 | - } |
|
| 223 | - } |
|
| 175 | + // Get all objects that can be in trap from MIB |
|
| 176 | + $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 177 | + // Get all objects in current Trap |
|
| 178 | + $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 179 | + $oid_index=1; |
|
| 180 | + foreach ($currentTrapObjects as $key => $val) |
|
| 181 | + { |
|
| 182 | + $currentObjectType='Unknown'; |
|
| 183 | + $currentObjectTypeEnum='Unknown'; |
|
| 184 | + if (isset($allObjects[$val->oid]['type'])) |
|
| 185 | + { |
|
| 186 | + $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 187 | + $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 188 | + } |
|
| 189 | + $currentObject=array( |
|
| 190 | + $oid_index, |
|
| 191 | + $val->oid, |
|
| 192 | + $val->oid_name_mib, |
|
| 193 | + $val->oid_name, |
|
| 194 | + $val->value, |
|
| 195 | + $currentObjectType, |
|
| 196 | + $currentObjectTypeEnum |
|
| 197 | + ); |
|
| 198 | + $oid_index++; |
|
| 199 | + array_push($this->view->objectList,$currentObject); |
|
| 200 | + // set currrent object to null in allObjects |
|
| 201 | + if (isset($allObjects[$val->oid])) |
|
| 202 | + { |
|
| 203 | + $allObjects[$val->oid]=null; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 207 | + { |
|
| 208 | + foreach ($allObjects as $key => $val) |
|
| 209 | + { |
|
| 210 | + if ($val==null) { continue; } |
|
| 211 | + array_push($this->view->objectList, array( |
|
| 212 | + $oid_index, |
|
| 213 | + $key, |
|
| 214 | + $allObjects[$key]['mib'], |
|
| 215 | + $allObjects[$key]['name'], |
|
| 216 | + '', |
|
| 217 | + $allObjects[$key]['type'], |
|
| 218 | + $allObjects[$key]['type_enum'] |
|
| 219 | + )); |
|
| 220 | + $oid_index++; |
|
| 221 | + } |
|
| 222 | + } |
|
| 224 | 223 | |
| 225 | - // Add a simple display |
|
| 226 | - $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 227 | - $this->view->create_basic_rule=true; |
|
| 224 | + // Add a simple display |
|
| 225 | + $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 226 | + $this->view->create_basic_rule=true; |
|
| 228 | 227 | } |
| 229 | 228 | |
| 230 | 229 | /** |
@@ -233,29 +232,29 @@ discard block |
||
| 233 | 232 | */ |
| 234 | 233 | private function add_check_host_exists($ruleDetail) |
| 235 | 234 | { |
| 236 | - // Check if hostname still exists |
|
| 237 | - $host_get=$this->getIdoConn()->getHostByName($this->view->hostname); |
|
| 235 | + // Check if hostname still exists |
|
| 236 | + $host_get=$this->getIdoConn()->getHostByName($this->view->hostname); |
|
| 238 | 237 | |
| 239 | - if (count($host_get)==0) |
|
| 240 | - { |
|
| 241 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 242 | - $this->view->serviceGet=false; |
|
| 243 | - } |
|
| 244 | - else |
|
| 245 | - { |
|
| 246 | - // Tell JS to get services when page is loaded |
|
| 247 | - $this->view->serviceGet=true; |
|
| 248 | - // get service id for form to set : |
|
| 249 | - $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 250 | - if (count($serviceID) ==0) |
|
| 251 | - { |
|
| 252 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 253 | - } |
|
| 254 | - else |
|
| 255 | - { |
|
| 256 | - $this->view->serviceSet=$serviceID[0]->id; |
|
| 257 | - } |
|
| 258 | - } |
|
| 238 | + if (count($host_get)==0) |
|
| 239 | + { |
|
| 240 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 241 | + $this->view->serviceGet=false; |
|
| 242 | + } |
|
| 243 | + else |
|
| 244 | + { |
|
| 245 | + // Tell JS to get services when page is loaded |
|
| 246 | + $this->view->serviceGet=true; |
|
| 247 | + // get service id for form to set : |
|
| 248 | + $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 249 | + if (count($serviceID) ==0) |
|
| 250 | + { |
|
| 251 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 252 | + } |
|
| 253 | + else |
|
| 254 | + { |
|
| 255 | + $this->view->serviceSet=$serviceID[0]->id; |
|
| 256 | + } |
|
| 257 | + } |
|
| 259 | 258 | } |
| 260 | 259 | |
| 261 | 260 | /** |
@@ -264,33 +263,33 @@ discard block |
||
| 264 | 263 | */ |
| 265 | 264 | private function add_check_hostgroup_exists($ruleDetail) |
| 266 | 265 | { |
| 267 | - // Check if groupe exists |
|
| 268 | - $group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname); |
|
| 269 | - if (count($group_get)==0) |
|
| 270 | - { |
|
| 271 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 272 | - $this->view->serviceGroupGet=false; |
|
| 273 | - } |
|
| 274 | - else |
|
| 275 | - { |
|
| 276 | - $grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id); |
|
| 277 | - $foundGrpService=0; |
|
| 278 | - foreach ($grpServices as $grpService) |
|
| 279 | - { |
|
| 280 | - if ($grpService[0] == $ruleDetail->service_name) |
|
| 281 | - { |
|
| 282 | - $foundGrpService=1; |
|
| 283 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
| 284 | - } |
|
| 285 | - } |
|
| 266 | + // Check if groupe exists |
|
| 267 | + $group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname); |
|
| 268 | + if (count($group_get)==0) |
|
| 269 | + { |
|
| 270 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 271 | + $this->view->serviceGroupGet=false; |
|
| 272 | + } |
|
| 273 | + else |
|
| 274 | + { |
|
| 275 | + $grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id); |
|
| 276 | + $foundGrpService=0; |
|
| 277 | + foreach ($grpServices as $grpService) |
|
| 278 | + { |
|
| 279 | + if ($grpService[0] == $ruleDetail->service_name) |
|
| 280 | + { |
|
| 281 | + $foundGrpService=1; |
|
| 282 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
| 283 | + } |
|
| 284 | + } |
|
| 286 | 285 | |
| 287 | - // Tell JS to get services when page is loaded |
|
| 288 | - $this->view->serviceGroupGet=true; |
|
| 289 | - if ($foundGrpService==0) |
|
| 290 | - { |
|
| 291 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 292 | - } |
|
| 293 | - } |
|
| 286 | + // Tell JS to get services when page is loaded |
|
| 287 | + $this->view->serviceGroupGet=true; |
|
| 288 | + if ($foundGrpService==0) |
|
| 289 | + { |
|
| 290 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 291 | + } |
|
| 292 | + } |
|
| 294 | 293 | } |
| 295 | 294 | |
| 296 | 295 | /** |
@@ -302,52 +301,52 @@ discard block |
||
| 302 | 301 | */ |
| 303 | 302 | private function add_create_trap_object_list(&$display, &$rule) |
| 304 | 303 | { |
| 305 | - $curObjectList=array(); |
|
| 306 | - $index=1; |
|
| 307 | - // check in display & rule for : OID(<oid>) |
|
| 308 | - $matches=array(); |
|
| 309 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 310 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 311 | - { |
|
| 312 | - $curOid=$matches[1]; |
|
| 304 | + $curObjectList=array(); |
|
| 305 | + $index=1; |
|
| 306 | + // check in display & rule for : OID(<oid>) |
|
| 307 | + $matches=array(); |
|
| 308 | + while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 309 | + preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 310 | + { |
|
| 311 | + $curOid=$matches[1]; |
|
| 313 | 312 | |
| 314 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 315 | - && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 316 | - { |
|
| 317 | - array_push($curObjectList, array( |
|
| 318 | - $index, |
|
| 319 | - $curOid, |
|
| 320 | - $object['mib'], |
|
| 321 | - $object['name'], |
|
| 322 | - '', |
|
| 323 | - $object['type'], |
|
| 324 | - $object['type_enum'] |
|
| 325 | - )); |
|
| 326 | - } |
|
| 327 | - else |
|
| 328 | - { |
|
| 329 | - array_push($curObjectList, array( |
|
| 330 | - $index, |
|
| 331 | - $curOid, |
|
| 332 | - 'not found', |
|
| 333 | - 'not found', |
|
| 334 | - '', |
|
| 335 | - 'not found', |
|
| 336 | - 'not found' |
|
| 337 | - )); |
|
| 338 | - } |
|
| 339 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 340 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 341 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 342 | - $index++; |
|
| 343 | - } |
|
| 344 | - return $curObjectList; |
|
| 313 | + if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 314 | + && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 315 | + { |
|
| 316 | + array_push($curObjectList, array( |
|
| 317 | + $index, |
|
| 318 | + $curOid, |
|
| 319 | + $object['mib'], |
|
| 320 | + $object['name'], |
|
| 321 | + '', |
|
| 322 | + $object['type'], |
|
| 323 | + $object['type_enum'] |
|
| 324 | + )); |
|
| 325 | + } |
|
| 326 | + else |
|
| 327 | + { |
|
| 328 | + array_push($curObjectList, array( |
|
| 329 | + $index, |
|
| 330 | + $curOid, |
|
| 331 | + 'not found', |
|
| 332 | + 'not found', |
|
| 333 | + '', |
|
| 334 | + 'not found', |
|
| 335 | + 'not found' |
|
| 336 | + )); |
|
| 337 | + } |
|
| 338 | + $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 339 | + $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 340 | + $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 341 | + $index++; |
|
| 342 | + } |
|
| 343 | + return $curObjectList; |
|
| 345 | 344 | } |
| 346 | 345 | |
| 347 | 346 | /** Add a handler |
| 348 | - * Get params fromid : setup from existing trap (id of trap table) |
|
| 349 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
| 350 | - */ |
|
| 347 | + * Get params fromid : setup from existing trap (id of trap table) |
|
| 348 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
| 349 | + */ |
|
| 351 | 350 | public function addAction() |
| 352 | 351 | { |
| 353 | 352 | $this->checkConfigPermission(); |
@@ -370,8 +369,8 @@ discard block |
||
| 370 | 369 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 371 | 370 | |
| 372 | 371 | if (($trapid = $this->params->get('fromid')) !== null) { |
| 373 | - /********** Setup from existing trap ***************/ |
|
| 374 | - $this->add_from_existing($trapid); |
|
| 372 | + /********** Setup from existing trap ***************/ |
|
| 373 | + $this->add_from_existing($trapid); |
|
| 375 | 374 | return; |
| 376 | 375 | } |
| 377 | 376 | |
@@ -399,14 +398,14 @@ discard block |
||
| 399 | 398 | $this->view->warning_message=''; |
| 400 | 399 | if ($this->view->hostname != null) |
| 401 | 400 | { |
| 402 | - $this->view->selectGroup=false; |
|
| 403 | - // Check if hostname still exists |
|
| 404 | - $this->add_check_host_exists($ruleDetail); |
|
| 401 | + $this->view->selectGroup=false; |
|
| 402 | + // Check if hostname still exists |
|
| 403 | + $this->add_check_host_exists($ruleDetail); |
|
| 405 | 404 | } |
| 406 | 405 | else |
| 407 | 406 | { |
| 408 | - $this->view->selectGroup=true; |
|
| 409 | - $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 407 | + $this->view->selectGroup=true; |
|
| 408 | + $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 410 | 409 | } |
| 411 | 410 | |
| 412 | 411 | $this->view->mainoid=$ruleDetail->trap_oid; |
@@ -434,9 +433,9 @@ discard block |
||
| 434 | 433 | } |
| 435 | 434 | |
| 436 | 435 | /** Validate form and output message to user |
| 437 | - * @param in postdata |
|
| 438 | - * @return string status : OK / <Message> |
|
| 439 | - **/ |
|
| 436 | + * @param in postdata |
|
| 437 | + * @return string status : OK / <Message> |
|
| 438 | + **/ |
|
| 440 | 439 | protected function handlerformAction() |
| 441 | 440 | { |
| 442 | 441 | $postData=$this->getRequest()->getPost(); |
@@ -451,8 +450,8 @@ discard block |
||
| 451 | 450 | 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
| 452 | 451 | 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
| 453 | 452 | 'service_name' => array('post' => 'serviceName', 'db'=>true), |
| 454 | - 'comment' => array('post' => 'comment', 'val' => '', 'db'=>true), |
|
| 455 | - 'rule_type' => array('post' => 'category', 'val' => 0, 'db'=>true), |
|
| 453 | + 'comment' => array('post' => 'comment', 'val' => '', 'db'=>true), |
|
| 454 | + 'rule_type' => array('post' => 'category', 'val' => 0, 'db'=>true), |
|
| 456 | 455 | 'trap_oid' => array('post' => 'oid', 'db'=>true), |
| 457 | 456 | 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
| 458 | 457 | 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
@@ -461,7 +460,7 @@ discard block |
||
| 461 | 460 | 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
| 462 | 461 | 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
| 463 | 462 | 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
| 464 | - 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 463 | + 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 465 | 464 | ); |
| 466 | 465 | |
| 467 | 466 | if (isset($postData[$params['action_form']['post']]) |
@@ -469,7 +468,7 @@ discard block |
||
| 469 | 468 | { |
| 470 | 469 | try |
| 471 | 470 | { |
| 472 | - $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 471 | + $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 473 | 472 | } |
| 474 | 473 | catch (Exception $e) |
| 475 | 474 | { |
@@ -479,7 +478,7 @@ discard block |
||
| 479 | 478 | //$this->Module()-> |
| 480 | 479 | $this->_helper->json(array( |
| 481 | 480 | 'status'=>'OK', |
| 482 | - 'redirect'=>'trapdirector/handler' |
|
| 481 | + 'redirect'=>'trapdirector/handler' |
|
| 483 | 482 | |
| 484 | 483 | )); |
| 485 | 484 | } |
@@ -506,8 +505,8 @@ discard block |
||
| 506 | 505 | $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
| 507 | 506 | if (! $isHostGroup ) |
| 508 | 507 | { // checks if selection by host |
| 509 | - $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']); |
|
| 510 | - if ($hostAddr === NULL) throw new \Exception("No object found"); |
|
| 508 | + $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']); |
|
| 509 | + if ($hostAddr === NULL) throw new \Exception("No object found"); |
|
| 511 | 510 | $params['ip4']['val']=$hostAddr->ip4; |
| 512 | 511 | $params['ip6']['val']=$hostAddr->ip6; |
| 513 | 512 | $checkHostName=$hostAddr->name; |
@@ -518,49 +517,49 @@ discard block |
||
| 518 | 517 | } |
| 519 | 518 | if ($this->apiMode == TRUE) |
| 520 | 519 | { |
| 521 | - $serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']); |
|
| 522 | - if (count($serviceName) == 0 ) |
|
| 523 | - { |
|
| 524 | - $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name)); |
|
| 525 | - return; |
|
| 526 | - } |
|
| 520 | + $serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']); |
|
| 521 | + if (count($serviceName) == 0 ) |
|
| 522 | + { |
|
| 523 | + $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name)); |
|
| 524 | + return; |
|
| 525 | + } |
|
| 527 | 526 | } |
| 528 | 527 | else |
| 529 | 528 | { |
| 530 | - if (!is_numeric($params['serviceid']['val'])) |
|
| 531 | - { |
|
| 532 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 533 | - return; |
|
| 534 | - } |
|
| 529 | + if (!is_numeric($params['serviceid']['val'])) |
|
| 530 | + { |
|
| 531 | + $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 532 | + return; |
|
| 533 | + } |
|
| 535 | 534 | |
| 536 | - $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
|
| 537 | - if ($params['service_name']['val'] != $serviceName->name2) |
|
| 538 | - { |
|
| 539 | - $this->_helper->json(array('status'=>"Invalid service id : Please re enter service")); |
|
| 540 | - return; |
|
| 541 | - } |
|
| 535 | + $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
|
| 536 | + if ($params['service_name']['val'] != $serviceName->name2) |
|
| 537 | + { |
|
| 538 | + $this->_helper->json(array('status'=>"Invalid service id : Please re enter service")); |
|
| 539 | + return; |
|
| 540 | + } |
|
| 542 | 541 | } |
| 543 | 542 | } |
| 544 | 543 | else |
| 545 | 544 | { |
| 546 | - if ($this->apiMode == TRUE) |
|
| 547 | - { |
|
| 548 | - $object=$this->getIdoConn()->getHostGroupById($params['hostid']['val']); |
|
| 549 | - if (count($object) == 0 || $params['host_name']['val'] != $object->__name) |
|
| 550 | - { |
|
| 551 | - $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
|
| 552 | - return; |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - else |
|
| 556 | - { |
|
| 557 | - $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 558 | - if ($params['host_name']['val'] != $object->name1) |
|
| 559 | - { |
|
| 560 | - $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
|
| 561 | - return; |
|
| 562 | - } |
|
| 563 | - } |
|
| 545 | + if ($this->apiMode == TRUE) |
|
| 546 | + { |
|
| 547 | + $object=$this->getIdoConn()->getHostGroupById($params['hostid']['val']); |
|
| 548 | + if (count($object) == 0 || $params['host_name']['val'] != $object->__name) |
|
| 549 | + { |
|
| 550 | + $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
|
| 551 | + return; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + else |
|
| 555 | + { |
|
| 556 | + $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 557 | + if ($params['host_name']['val'] != $object->name1) |
|
| 558 | + { |
|
| 559 | + $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
|
| 560 | + return; |
|
| 561 | + } |
|
| 562 | + } |
|
| 564 | 563 | // Put param in correct column (group_name) |
| 565 | 564 | $params['host_group_name']['val'] = $params['host_name']['val']; |
| 566 | 565 | $params['host_name']['val']=null; |
@@ -577,17 +576,17 @@ discard block |
||
| 577 | 576 | |
| 578 | 577 | if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') |
| 579 | 578 | { // If no rule number or action is clone, add the handler |
| 580 | - $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 579 | + $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 581 | 580 | } |
| 582 | 581 | else |
| 583 | 582 | { |
| 584 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 583 | + $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 585 | 584 | $ruleID=$params['db_rule']['val']; |
| 586 | 585 | } |
| 587 | 586 | } |
| 588 | 587 | catch (Exception $e) |
| 589 | 588 | { |
| 590 | - $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile())); |
|
| 589 | + $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile())); |
|
| 591 | 590 | return; |
| 592 | 591 | } |
| 593 | 592 | $this->_helper->json(array('status'=>'OK', 'id' => $ruleID)); |
@@ -595,9 +594,9 @@ discard block |
||
| 595 | 594 | } |
| 596 | 595 | |
| 597 | 596 | /** Get trap detail by trapid. |
| 598 | - * @param integer $trapid : id of trap in received table |
|
| 599 | - * @return array (objects) |
|
| 600 | - */ |
|
| 597 | + * @param integer $trapid : id of trap in received table |
|
| 598 | + * @return array (objects) |
|
| 599 | + */ |
|
| 601 | 600 | protected function getTrapDetail($trapid) |
| 602 | 601 | { |
| 603 | 602 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -613,14 +612,14 @@ discard block |
||
| 613 | 612 | } |
| 614 | 613 | try |
| 615 | 614 | { |
| 616 | - $query = $dbConn->select() |
|
| 615 | + $query = $dbConn->select() |
|
| 617 | 616 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
| 618 | 617 | ->where('id=?',$trapid); |
| 619 | 618 | $trapDetail=$dbConn->fetchRow($query); |
| 620 | 619 | if ( $trapDetail == null ) |
| 621 | 620 | { |
| 622 | - $trapDetail = 'NULL'; |
|
| 623 | - throw new Exception('No traps was found with id = '.$trapid); |
|
| 621 | + $trapDetail = 'NULL'; |
|
| 622 | + throw new Exception('No traps was found with id = '.$trapid); |
|
| 624 | 623 | } |
| 625 | 624 | } |
| 626 | 625 | catch (Exception $e) |
@@ -634,9 +633,9 @@ discard block |
||
| 634 | 633 | } |
| 635 | 634 | |
| 636 | 635 | /** Get trap objects |
| 637 | - * @param integer $trapid : trap id |
|
| 638 | - * @return array : full column in db of trap id |
|
| 639 | - */ |
|
| 636 | + * @param integer $trapid : trap id |
|
| 637 | + * @return array : full column in db of trap id |
|
| 638 | + */ |
|
| 640 | 639 | protected function getTrapobjects($trapid) |
| 641 | 640 | { |
| 642 | 641 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -652,7 +651,7 @@ discard block |
||
| 652 | 651 | } |
| 653 | 652 | try |
| 654 | 653 | { |
| 655 | - $query = $dbConn->select() |
|
| 654 | + $query = $dbConn->select() |
|
| 656 | 655 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 657 | 656 | ->where('trap_id=?',$trapid); |
| 658 | 657 | $trapDetail=$dbConn->fetchAll($query); |
@@ -668,10 +667,10 @@ discard block |
||
| 668 | 667 | } |
| 669 | 668 | |
| 670 | 669 | /** Get rule detail by ruleid. |
| 671 | - * @param integer $ruleid int id of rule in rule table |
|
| 672 | - * @return object|array : column objects in db |
|
| 673 | - * |
|
| 674 | - */ |
|
| 670 | + * @param integer $ruleid int id of rule in rule table |
|
| 671 | + * @return object|array : column objects in db |
|
| 672 | + * |
|
| 673 | + */ |
|
| 675 | 674 | protected function getRuleDetail($ruleid) |
| 676 | 675 | { |
| 677 | 676 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -682,7 +681,7 @@ discard block |
||
| 682 | 681 | // *************** Get main data |
| 683 | 682 | try |
| 684 | 683 | { |
| 685 | - $query = $dbConn->select() |
|
| 684 | + $query = $dbConn->select() |
|
| 686 | 685 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 687 | 686 | ->where('id=?',$ruleid); |
| 688 | 687 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -699,7 +698,7 @@ discard block |
||
| 699 | 698 | } |
| 700 | 699 | |
| 701 | 700 | /** Setup tabs for rules |
| 702 | - */ |
|
| 701 | + */ |
|
| 703 | 702 | protected function prepareTabs() |
| 704 | 703 | { |
| 705 | 704 | return $this->getTabs()->add('status', array( |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | $this->checkReadPermission(); |
| 25 | 25 | $this->prepareTabs()->activate('status'); |
| 26 | 26 | |
| 27 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 27 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
| 28 | 28 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 29 | 29 | |
| 30 | - $handlerTable = new HandlerTable( |
|
| 30 | + $handlerTable=new HandlerTable( |
|
| 31 | 31 | $this->moduleConfig->getTrapRuleName(), |
| 32 | 32 | $this->moduleConfig->getHandlerListTitles(), |
| 33 | 33 | $this->moduleConfig->getHandlerListDisplayColumns(), |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $handlerTable->setMibloader($this->getMIB()); |
| 42 | 42 | |
| 43 | - $getVars = $this->getRequest()->getParams(); |
|
| 43 | + $getVars=$this->getRequest()->getParams(); |
|
| 44 | 44 | $handlerTable->getParams($getVars); |
| 45 | 45 | |
| 46 | 46 | if ($handlerTable->isOrderSet() == FALSE) |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $this->view->handlerTable = $handlerTable; |
|
| 54 | + $this->view->handlerTable=$handlerTable; |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // TODO : Obsolete remove after new table validation. |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | public function testruleAction() |
| 75 | 75 | { |
| 76 | 76 | $this->checkReadPermission(); |
| 77 | - $this->getTabs()->add('get',array( |
|
| 77 | + $this->getTabs()->add('get', array( |
|
| 78 | 78 | 'active' => true, |
| 79 | 79 | 'label' => $this->translate('Test Rule'), |
| 80 | 80 | 'url' => Url::fromRequest() |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | if ($this->params->get('rule') !== null) |
| 85 | 85 | { |
| 86 | - $this->view->rule= $this->params->get('rule'); |
|
| 86 | + $this->view->rule=$this->params->get('rule'); |
|
| 87 | 87 | } |
| 88 | 88 | else |
| 89 | 89 | { |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | catch (Exception $e) |
| 144 | 144 | { |
| 145 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 145 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
| 149 | 149 | // if one unique host found -> put id text input |
| 150 | - if (count($hosts)==1) { |
|
| 150 | + if (count($hosts) == 1) { |
|
| 151 | 151 | $this->view->hostname=$hosts[0]->name; |
| 152 | 152 | //$hostid=$hosts[0]->id; |
| 153 | 153 | // Tell JS to get services when page is loaded |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | else |
| 158 | 158 | { |
| 159 | - foreach($hosts as $key=>$val) |
|
| 159 | + foreach ($hosts as $key=>$val) |
|
| 160 | 160 | { |
| 161 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 161 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -197,18 +197,18 @@ discard block |
||
| 197 | 197 | $currentObjectTypeEnum |
| 198 | 198 | ); |
| 199 | 199 | $oid_index++; |
| 200 | - array_push($this->view->objectList,$currentObject); |
|
| 200 | + array_push($this->view->objectList, $currentObject); |
|
| 201 | 201 | // set currrent object to null in allObjects |
| 202 | 202 | if (isset($allObjects[$val->oid])) |
| 203 | 203 | { |
| 204 | 204 | $allObjects[$val->oid]=null; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 207 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
| 208 | 208 | { |
| 209 | 209 | foreach ($allObjects as $key => $val) |
| 210 | 210 | { |
| 211 | - if ($val==null) { continue; } |
|
| 211 | + if ($val == null) { continue; } |
|
| 212 | 212 | array_push($this->view->objectList, array( |
| 213 | 213 | $oid_index, |
| 214 | 214 | $key, |
@@ -236,9 +236,9 @@ discard block |
||
| 236 | 236 | // Check if hostname still exists |
| 237 | 237 | $host_get=$this->getIdoConn()->getHostByName($this->view->hostname); |
| 238 | 238 | |
| 239 | - if (count($host_get)==0) |
|
| 239 | + if (count($host_get) == 0) |
|
| 240 | 240 | { |
| 241 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 241 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
| 242 | 242 | $this->view->serviceGet=false; |
| 243 | 243 | } |
| 244 | 244 | else |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | // Tell JS to get services when page is loaded |
| 247 | 247 | $this->view->serviceGet=true; |
| 248 | 248 | // get service id for form to set : |
| 249 | - $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 250 | - if (count($serviceID) ==0) |
|
| 249 | + $serviceID=$this->getIdoConn()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
| 250 | + if (count($serviceID) == 0) |
|
| 251 | 251 | { |
| 252 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 252 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 253 | 253 | } |
| 254 | 254 | else |
| 255 | 255 | { |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | { |
| 267 | 267 | // Check if groupe exists |
| 268 | 268 | $group_get=$this->getIdoConn()->getHostGroupByName($this->view->hostgroupname); |
| 269 | - if (count($group_get)==0) |
|
| 269 | + if (count($group_get) == 0) |
|
| 270 | 270 | { |
| 271 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 271 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
| 272 | 272 | $this->view->serviceGroupGet=false; |
| 273 | 273 | } |
| 274 | 274 | else |
@@ -286,9 +286,9 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | // Tell JS to get services when page is loaded |
| 288 | 288 | $this->view->serviceGroupGet=true; |
| 289 | - if ($foundGrpService==0) |
|
| 289 | + if ($foundGrpService == 0) |
|
| 290 | 290 | { |
| 291 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 291 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | } |
@@ -306,12 +306,12 @@ discard block |
||
| 306 | 306 | $index=1; |
| 307 | 307 | // check in display & rule for : OID(<oid>) |
| 308 | 308 | $matches=array(); |
| 309 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 310 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 309 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
| 310 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
| 311 | 311 | { |
| 312 | 312 | $curOid=$matches[1]; |
| 313 | 313 | |
| 314 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 314 | + if ((preg_match('/\*/', $curOid) == 0) |
|
| 315 | 315 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
| 316 | 316 | { |
| 317 | 317 | array_push($curObjectList, array( |
@@ -336,9 +336,9 @@ discard block |
||
| 336 | 336 | 'not found' |
| 337 | 337 | )); |
| 338 | 338 | } |
| 339 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 340 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 341 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 339 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
| 340 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
| 341 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
| 342 | 342 | $index++; |
| 343 | 343 | } |
| 344 | 344 | return $curObjectList; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | $this->checkConfigPermission(); |
| 354 | 354 | // set up tab |
| 355 | 355 | $this->prepareTabs(); |
| 356 | - $this->getTabs()->add('get',array( |
|
| 356 | + $this->getTabs()->add('get', array( |
|
| 357 | 357 | 'active' => true, |
| 358 | 358 | 'label' => $this->translate('Add handler'), |
| 359 | 359 | 'url' => Url::fromRequest() |
@@ -365,11 +365,11 @@ discard block |
||
| 365 | 365 | $this->view->mibList=$this->getMIB()->getMIBList(); |
| 366 | 366 | |
| 367 | 367 | // Get categories |
| 368 | - $this->view->categoryList = $this->getHandlersCategory(); |
|
| 368 | + $this->view->categoryList=$this->getHandlersCategory(); |
|
| 369 | 369 | |
| 370 | 370 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 371 | 371 | |
| 372 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
| 372 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
| 373 | 373 | /********** Setup from existing trap ***************/ |
| 374 | 374 | $this->add_from_existing($trapid); |
| 375 | 375 | return; |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | $this->view->setRuleMatch=$ruleDetail->action_match; |
| 390 | 390 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
| 391 | 391 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
| 392 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
| 392 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
| 393 | 393 | $this->view->modifier=$ruleDetail->modifier; |
| 394 | 394 | |
| 395 | - $this->view->comment = $ruleDetail->comment; |
|
| 396 | - $this->view->category = $ruleDetail->category; |
|
| 395 | + $this->view->comment=$ruleDetail->comment; |
|
| 396 | + $this->view->category=$ruleDetail->category; |
|
| 397 | 397 | |
| 398 | 398 | // Warning message if host/service don't exists anymore |
| 399 | 399 | $this->view->warning_message=''; |
@@ -444,28 +444,28 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | $params=array( |
| 446 | 446 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
| 447 | - 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
| 448 | - 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
| 449 | - 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
| 450 | - 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
| 451 | - 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
| 452 | - 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
| 453 | - 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
| 454 | - 'comment' => array('post' => 'comment', 'val' => '', 'db'=>true), |
|
| 455 | - 'rule_type' => array('post' => 'category', 'val' => 0, 'db'=>true), |
|
| 456 | - 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
| 457 | - 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
| 458 | - 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
| 459 | - 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
| 460 | - 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
| 461 | - 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
| 462 | - 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 463 | - 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 464 | - 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 447 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
| 448 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
| 449 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
| 450 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
| 451 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
| 452 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
| 453 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
| 454 | + 'comment' => array('post' => 'comment', 'val' => '', 'db'=>true), |
|
| 455 | + 'rule_type' => array('post' => 'category', 'val' => 0, 'db'=>true), |
|
| 456 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
| 457 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
| 458 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
| 459 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
| 460 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
| 461 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
| 462 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 463 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 464 | + 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 465 | 465 | ); |
| 466 | 466 | |
| 467 | 467 | if (isset($postData[$params['action_form']['post']]) |
| 468 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
| 468 | + && $postData[$params['action_form']['post']] == 'delete') |
|
| 469 | 469 | { |
| 470 | 470 | try |
| 471 | 471 | { |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | } |
| 474 | 474 | catch (Exception $e) |
| 475 | 475 | { |
| 476 | - $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Deleting Rule')); |
|
| 476 | + $this->_helper->json(array('status'=>$e->getMessage(), 'location'=>'Deleting Rule')); |
|
| 477 | 477 | return; |
| 478 | 478 | } |
| 479 | 479 | //$this->Module()-> |
@@ -485,16 +485,16 @@ discard block |
||
| 485 | 485 | } |
| 486 | 486 | foreach (array_keys($params) as $key) |
| 487 | 487 | { |
| 488 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
| 489 | - if (! isset($postData[$params[$key]['post']])) |
|
| 488 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
| 489 | + if (!isset($postData[$params[$key]['post']])) |
|
| 490 | 490 | { |
| 491 | 491 | // should not happen as the js checks data |
| 492 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
| 492 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
| 493 | 493 | } |
| 494 | 494 | else |
| 495 | 495 | { |
| 496 | 496 | $data=$postData[$params[$key]['post']]; |
| 497 | - if ($data!=null && $data !="") |
|
| 497 | + if ($data != null && $data != "") |
|
| 498 | 498 | { |
| 499 | 499 | $params[$key]['val']=$postData[$params[$key]['post']]; |
| 500 | 500 | } |
@@ -503,8 +503,8 @@ discard block |
||
| 503 | 503 | $this->getIdoConn(); //Set apiMode |
| 504 | 504 | try |
| 505 | 505 | { |
| 506 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
| 507 | - if (! $isHostGroup ) |
|
| 506 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
| 507 | + if (!$isHostGroup) |
|
| 508 | 508 | { // checks if selection by host |
| 509 | 509 | $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']); |
| 510 | 510 | if ($hostAddr === NULL) throw new \Exception("No object found"); |
@@ -519,9 +519,9 @@ discard block |
||
| 519 | 519 | if ($this->apiMode == TRUE) |
| 520 | 520 | { |
| 521 | 521 | $serviceName=$this->getIdoConn()->getServiceById($params['serviceid']['val']); |
| 522 | - if (count($serviceName) == 0 ) |
|
| 522 | + if (count($serviceName) == 0) |
|
| 523 | 523 | { |
| 524 | - $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name)); |
|
| 524 | + $this->_helper->json(array('status'=>"Invalid service id : Please re enter service", 'sent'=>$params['serviceid']['val'], 'found'=>$serviceName[0]->__name)); |
|
| 525 | 525 | return; |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | { |
| 530 | 530 | if (!is_numeric($params['serviceid']['val'])) |
| 531 | 531 | { |
| 532 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 532 | + $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val'])); |
|
| 533 | 533 | return; |
| 534 | 534 | } |
| 535 | 535 | |
@@ -562,15 +562,15 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | 564 | // Put param in correct column (group_name) |
| 565 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
| 565 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
| 566 | 566 | $params['host_name']['val']=null; |
| 567 | 567 | } |
| 568 | 568 | $dbparams=array(); |
| 569 | 569 | foreach ($params as $key=>$val) |
| 570 | 570 | { |
| 571 | - if ($val['db']==true ) |
|
| 571 | + if ($val['db'] == true) |
|
| 572 | 572 | { |
| 573 | - $dbparams[$key] = $val['val']; |
|
| 573 | + $dbparams[$key]=$val['val']; |
|
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | } |
| 582 | 582 | else |
| 583 | 583 | { |
| 584 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 584 | + $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
| 585 | 585 | $ruleID=$params['db_rule']['val']; |
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | 588 | catch (Exception $e) |
| 589 | 589 | { |
| 590 | - $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile())); |
|
| 590 | + $this->_helper->json(array('status'=>$e->getMessage(), 'location'=>'Add/update Rule', 'line'=>$e->getLine(), 'file'=>$e->getFile())); |
|
| 591 | 591 | return; |
| 592 | 592 | } |
| 593 | 593 | $this->_helper->json(array('status'=>'OK', 'id' => $ruleID)); |
@@ -600,10 +600,10 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | protected function getTrapDetail($trapid) |
| 602 | 602 | { |
| 603 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 603 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 604 | 604 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 605 | 605 | |
| 606 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 606 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 607 | 607 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 608 | 608 | // *************** Get main data |
| 609 | 609 | // extract columns and titles; |
@@ -613,19 +613,19 @@ discard block |
||
| 613 | 613 | } |
| 614 | 614 | try |
| 615 | 615 | { |
| 616 | - $query = $dbConn->select() |
|
| 617 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
| 618 | - ->where('id=?',$trapid); |
|
| 616 | + $query=$dbConn->select() |
|
| 617 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
| 618 | + ->where('id=?', $trapid); |
|
| 619 | 619 | $trapDetail=$dbConn->fetchRow($query); |
| 620 | - if ( $trapDetail == null ) |
|
| 620 | + if ($trapDetail == null) |
|
| 621 | 621 | { |
| 622 | - $trapDetail = 'NULL'; |
|
| 622 | + $trapDetail='NULL'; |
|
| 623 | 623 | throw new Exception('No traps was found with id = '.$trapid); |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | catch (Exception $e) |
| 627 | 627 | { |
| 628 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
| 628 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
| 629 | 629 | return; |
| 630 | 630 | } |
| 631 | 631 | |
@@ -639,10 +639,10 @@ discard block |
||
| 639 | 639 | */ |
| 640 | 640 | protected function getTrapobjects($trapid) |
| 641 | 641 | { |
| 642 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 642 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 643 | 643 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
| 644 | 644 | |
| 645 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 645 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 646 | 646 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 647 | 647 | // *************** Get object data |
| 648 | 648 | // extract columns and titles; |
@@ -652,15 +652,15 @@ discard block |
||
| 652 | 652 | } |
| 653 | 653 | try |
| 654 | 654 | { |
| 655 | - $query = $dbConn->select() |
|
| 656 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
| 657 | - ->where('trap_id=?',$trapid); |
|
| 655 | + $query=$dbConn->select() |
|
| 656 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
| 657 | + ->where('trap_id=?', $trapid); |
|
| 658 | 658 | $trapDetail=$dbConn->fetchAll($query); |
| 659 | 659 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
| 660 | 660 | } |
| 661 | 661 | catch (Exception $e) |
| 662 | 662 | { |
| 663 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
| 663 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
| 664 | 664 | return array(); |
| 665 | 665 | } |
| 666 | 666 | |
@@ -674,24 +674,24 @@ discard block |
||
| 674 | 674 | */ |
| 675 | 675 | protected function getRuleDetail($ruleid) |
| 676 | 676 | { |
| 677 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
| 677 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
| 678 | 678 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
| 679 | 679 | |
| 680 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 680 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 681 | 681 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 682 | 682 | // *************** Get main data |
| 683 | 683 | try |
| 684 | 684 | { |
| 685 | - $query = $dbConn->select() |
|
| 686 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
| 687 | - ->where('id=?',$ruleid); |
|
| 685 | + $query=$dbConn->select() |
|
| 686 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
| 687 | + ->where('id=?', $ruleid); |
|
| 688 | 688 | $ruleDetail=$dbConn->fetchRow($query); |
| 689 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 689 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 690 | 690 | } |
| 691 | 691 | catch (Exception $e) |
| 692 | 692 | { |
| 693 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
| 694 | - throw new Exception('Error : ' . $e->getMessage()); |
|
| 693 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
| 694 | + throw new Exception('Error : '.$e->getMessage()); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | return $ruleDetail; |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | { |
| 705 | 705 | return $this->getTabs()->add('status', array( |
| 706 | 706 | 'label' => $this->translate('Trap handlers'), |
| 707 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
| 707 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
| 708 | 708 | ); |
| 709 | 709 | } |
| 710 | 710 | |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | $this->prepareTabs()->activate('status'); |
| 26 | 26 | |
| 27 | 27 | $dbConn = $this->getUIDatabase()->getDb(); |
| 28 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 28 | + if ($dbConn === null) { |
|
| 29 | + throw new \ErrorException('uncatched db error'); |
|
| 30 | + } |
|
| 29 | 31 | |
| 30 | 32 | $handlerTable = new HandlerTable( |
| 31 | 33 | $this->moduleConfig->getTrapRuleName(), |
@@ -84,8 +86,7 @@ discard block |
||
| 84 | 86 | if ($this->params->get('rule') !== null) |
| 85 | 87 | { |
| 86 | 88 | $this->view->rule= $this->params->get('rule'); |
| 87 | - } |
|
| 88 | - else |
|
| 89 | + } else |
|
| 89 | 90 | { |
| 90 | 91 | $this->view->rule=''; |
| 91 | 92 | } |
@@ -139,8 +140,7 @@ discard block |
||
| 139 | 140 | try |
| 140 | 141 | { |
| 141 | 142 | $hosts=$this->getIdoConn()->getHostByIP($hostfilter); |
| 142 | - } |
|
| 143 | - catch (Exception $e) |
|
| 143 | + } catch (Exception $e) |
|
| 144 | 144 | { |
| 145 | 145 | $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
| 146 | 146 | } |
@@ -153,8 +153,7 @@ discard block |
||
| 153 | 153 | // Tell JS to get services when page is loaded |
| 154 | 154 | $this->view->serviceGet=true; |
| 155 | 155 | |
| 156 | - } |
|
| 157 | - else |
|
| 156 | + } else |
|
| 158 | 157 | { |
| 159 | 158 | foreach($hosts as $key=>$val) |
| 160 | 159 | { |
@@ -204,11 +203,14 @@ discard block |
||
| 204 | 203 | $allObjects[$val->oid]=null; |
| 205 | 204 | } |
| 206 | 205 | } |
| 207 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 206 | + if ($allObjects!=null) { |
|
| 207 | + // in case trap doesn't have objects or is not resolved |
|
| 208 | 208 | { |
| 209 | 209 | foreach ($allObjects as $key => $val) |
| 210 | 210 | { |
| 211 | - if ($val==null) { continue; } |
|
| 211 | + if ($val==null) { continue; |
|
| 212 | + } |
|
| 213 | + } |
|
| 212 | 214 | array_push($this->view->objectList, array( |
| 213 | 215 | $oid_index, |
| 214 | 216 | $key, |
@@ -240,8 +242,7 @@ discard block |
||
| 240 | 242 | { |
| 241 | 243 | $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
| 242 | 244 | $this->view->serviceGet=false; |
| 243 | - } |
|
| 244 | - else |
|
| 245 | + } else |
|
| 245 | 246 | { |
| 246 | 247 | // Tell JS to get services when page is loaded |
| 247 | 248 | $this->view->serviceGet=true; |
@@ -250,8 +251,7 @@ discard block |
||
| 250 | 251 | if (count($serviceID) ==0) |
| 251 | 252 | { |
| 252 | 253 | $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
| 253 | - } |
|
| 254 | - else |
|
| 254 | + } else |
|
| 255 | 255 | { |
| 256 | 256 | $this->view->serviceSet=$serviceID[0]->id; |
| 257 | 257 | } |
@@ -270,8 +270,7 @@ discard block |
||
| 270 | 270 | { |
| 271 | 271 | $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
| 272 | 272 | $this->view->serviceGroupGet=false; |
| 273 | - } |
|
| 274 | - else |
|
| 273 | + } else |
|
| 275 | 274 | { |
| 276 | 275 | $grpServices=$this->getIdoConn()->getServicesByHostGroupid($group_get[0]->id); |
| 277 | 276 | $foundGrpService=0; |
@@ -323,8 +322,7 @@ discard block |
||
| 323 | 322 | $object['type'], |
| 324 | 323 | $object['type_enum'] |
| 325 | 324 | )); |
| 326 | - } |
|
| 327 | - else |
|
| 325 | + } else |
|
| 328 | 326 | { |
| 329 | 327 | array_push($curObjectList, array( |
| 330 | 328 | $index, |
@@ -402,8 +400,7 @@ discard block |
||
| 402 | 400 | $this->view->selectGroup=false; |
| 403 | 401 | // Check if hostname still exists |
| 404 | 402 | $this->add_check_host_exists($ruleDetail); |
| 405 | - } |
|
| 406 | - else |
|
| 403 | + } else |
|
| 407 | 404 | { |
| 408 | 405 | $this->view->selectGroup=true; |
| 409 | 406 | $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
@@ -411,9 +408,11 @@ discard block |
||
| 411 | 408 | |
| 412 | 409 | $this->view->mainoid=$ruleDetail->trap_oid; |
| 413 | 410 | $oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid); |
| 414 | - if ($oidName != null) // oid is found in mibs |
|
| 411 | + if ($oidName != null) { |
|
| 412 | + // oid is found in mibs |
|
| 415 | 413 | { |
| 416 | - $this->view->mib=$oidName['mib']; |
|
| 414 | + $this->view->mib=$oidName['mib']; |
|
| 415 | + } |
|
| 417 | 416 | $this->view->name=$oidName['name']; |
| 418 | 417 | $this->view->trapListForMIB=$this->getMIB() |
| 419 | 418 | ->getTrapList($oidName['mib']); |
@@ -470,8 +469,7 @@ discard block |
||
| 470 | 469 | try |
| 471 | 470 | { |
| 472 | 471 | $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
| 473 | - } |
|
| 474 | - catch (Exception $e) |
|
| 472 | + } catch (Exception $e) |
|
| 475 | 473 | { |
| 476 | 474 | $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Deleting Rule')); |
| 477 | 475 | return; |
@@ -485,13 +483,15 @@ discard block |
||
| 485 | 483 | } |
| 486 | 484 | foreach (array_keys($params) as $key) |
| 487 | 485 | { |
| 488 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
| 486 | + if ($params[$key]['post']==null) { |
|
| 487 | + continue; |
|
| 488 | + } |
|
| 489 | + // data not sent in post vars |
|
| 489 | 490 | if (! isset($postData[$params[$key]['post']])) |
| 490 | 491 | { |
| 491 | 492 | // should not happen as the js checks data |
| 492 | 493 | $this->_helper->json(array('status'=>'No ' . $key)); |
| 493 | - } |
|
| 494 | - else |
|
| 494 | + } else |
|
| 495 | 495 | { |
| 496 | 496 | $data=$postData[$params[$key]['post']]; |
| 497 | 497 | if ($data!=null && $data !="") |
@@ -507,7 +507,9 @@ discard block |
||
| 507 | 507 | if (! $isHostGroup ) |
| 508 | 508 | { // checks if selection by host |
| 509 | 509 | $hostAddr=$this->getIdoConn()->getHostInfoByID($params['hostid']['val']); |
| 510 | - if ($hostAddr === NULL) throw new \Exception("No object found"); |
|
| 510 | + if ($hostAddr === NULL) { |
|
| 511 | + throw new \Exception("No object found"); |
|
| 512 | + } |
|
| 511 | 513 | $params['ip4']['val']=$hostAddr->ip4; |
| 512 | 514 | $params['ip6']['val']=$hostAddr->ip6; |
| 513 | 515 | $checkHostName=$hostAddr->name; |
@@ -524,8 +526,7 @@ discard block |
||
| 524 | 526 | $this->_helper->json(array('status'=>"Invalid service id : Please re enter service",'sent'=>$params['serviceid']['val'],'found'=>$serviceName[0]->__name)); |
| 525 | 527 | return; |
| 526 | 528 | } |
| 527 | - } |
|
| 528 | - else |
|
| 529 | + } else |
|
| 529 | 530 | { |
| 530 | 531 | if (!is_numeric($params['serviceid']['val'])) |
| 531 | 532 | { |
@@ -540,8 +541,7 @@ discard block |
||
| 540 | 541 | return; |
| 541 | 542 | } |
| 542 | 543 | } |
| 543 | - } |
|
| 544 | - else |
|
| 544 | + } else |
|
| 545 | 545 | { |
| 546 | 546 | if ($this->apiMode == TRUE) |
| 547 | 547 | { |
@@ -551,8 +551,7 @@ discard block |
||
| 551 | 551 | $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
| 552 | 552 | return; |
| 553 | 553 | } |
| 554 | - } |
|
| 555 | - else |
|
| 554 | + } else |
|
| 556 | 555 | { |
| 557 | 556 | $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
| 558 | 557 | if ($params['host_name']['val'] != $object->name1) |
@@ -578,14 +577,12 @@ discard block |
||
| 578 | 577 | if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') |
| 579 | 578 | { // If no rule number or action is clone, add the handler |
| 580 | 579 | $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
| 581 | - } |
|
| 582 | - else |
|
| 580 | + } else |
|
| 583 | 581 | { |
| 584 | 582 | $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
| 585 | 583 | $ruleID=$params['db_rule']['val']; |
| 586 | 584 | } |
| 587 | - } |
|
| 588 | - catch (Exception $e) |
|
| 585 | + } catch (Exception $e) |
|
| 589 | 586 | { |
| 590 | 587 | $this->_helper->json(array('status'=>$e->getMessage(),'location'=>'Add/update Rule','line'=>$e->getLine(),'file'=>$e->getFile())); |
| 591 | 588 | return; |
@@ -604,7 +601,9 @@ discard block |
||
| 604 | 601 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 605 | 602 | |
| 606 | 603 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 607 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 604 | + if ($dbConn === null) { |
|
| 605 | + throw new \ErrorException('uncatched db error'); |
|
| 606 | + } |
|
| 608 | 607 | // *************** Get main data |
| 609 | 608 | // extract columns and titles; |
| 610 | 609 | $elmts=NULL; |
@@ -622,8 +621,7 @@ discard block |
||
| 622 | 621 | $trapDetail = 'NULL'; |
| 623 | 622 | throw new Exception('No traps was found with id = '.$trapid); |
| 624 | 623 | } |
| 625 | - } |
|
| 626 | - catch (Exception $e) |
|
| 624 | + } catch (Exception $e) |
|
| 627 | 625 | { |
| 628 | 626 | $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
| 629 | 627 | return; |
@@ -643,7 +641,9 @@ discard block |
||
| 643 | 641 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
| 644 | 642 | |
| 645 | 643 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 646 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 644 | + if ($dbConn === null) { |
|
| 645 | + throw new \ErrorException('uncatched db error'); |
|
| 646 | + } |
|
| 647 | 647 | // *************** Get object data |
| 648 | 648 | // extract columns and titles; |
| 649 | 649 | $data_elmts=NULL; |
@@ -657,8 +657,7 @@ discard block |
||
| 657 | 657 | ->where('trap_id=?',$trapid); |
| 658 | 658 | $trapDetail=$dbConn->fetchAll($query); |
| 659 | 659 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
| 660 | - } |
|
| 661 | - catch (Exception $e) |
|
| 660 | + } catch (Exception $e) |
|
| 662 | 661 | { |
| 663 | 662 | $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
| 664 | 663 | return array(); |
@@ -678,7 +677,9 @@ discard block |
||
| 678 | 677 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
| 679 | 678 | |
| 680 | 679 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 681 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 680 | + if ($dbConn === null) { |
|
| 681 | + throw new \ErrorException('uncatched db error'); |
|
| 682 | + } |
|
| 682 | 683 | // *************** Get main data |
| 683 | 684 | try |
| 684 | 685 | { |
@@ -686,9 +687,10 @@ discard block |
||
| 686 | 687 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 687 | 688 | ->where('id=?',$ruleid); |
| 688 | 689 | $ruleDetail=$dbConn->fetchRow($query); |
| 689 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 690 | - } |
|
| 691 | - catch (Exception $e) |
|
| 690 | + if ( $ruleDetail == null ) { |
|
| 691 | + throw new Exception('No rule was found with id = '.$ruleid); |
|
| 692 | + } |
|
| 693 | + } catch (Exception $e) |
|
| 692 | 694 | { |
| 693 | 695 | $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
| 694 | 696 | throw new Exception('Error : ' . $e->getMessage()); |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | { |
| 13 | 13 | |
| 14 | 14 | /** Get host list with filter (IP or name) : host=<filter> |
| 15 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 16 | - */ |
|
| 15 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 16 | + */ |
|
| 17 | 17 | public function gethostsAction() |
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | $retHosts=array('status'=>'OK','hosts' => array()); |
| 24 | 24 | $this->getIdoConn(); // set apiMode to correct val |
| 25 | - if ($this->apiMode === TRUE) |
|
| 26 | - { |
|
| 27 | - $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter); |
|
| 28 | - $retHosts['test']=count($hosts); |
|
| 29 | - } |
|
| 30 | - else |
|
| 31 | - { |
|
| 25 | + if ($this->apiMode === TRUE) |
|
| 26 | + { |
|
| 27 | + $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter); |
|
| 28 | + $retHosts['test']=count($hosts); |
|
| 29 | + } |
|
| 30 | + else |
|
| 31 | + { |
|
| 32 | 32 | $hosts=$this->getIdoConn()->getHostByIP($hostFilter); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | foreach ($hosts as $val) |
| 35 | 35 | { |
| 36 | 36 | array_push($retHosts['hosts'],$val->name); |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** Get hostgroup list with filter (name) : hostgroup=<hostFilter> |
| 43 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 44 | - */ |
|
| 43 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 44 | + */ |
|
| 45 | 45 | public function gethostgroupsAction() |
| 46 | 46 | { |
| 47 | 47 | $postData=$this->getRequest()->getPost(); |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** Get service list by host name ( host=<host> ) |
| 63 | - * returns in JSON : |
|
| 64 | - * status=>OK/No services found/More than one host matches |
|
| 65 | - * services=>array of services (name) |
|
| 66 | - * hostid = host object id or -1 if not found. |
|
| 67 | - */ |
|
| 63 | + * returns in JSON : |
|
| 64 | + * status=>OK/No services found/More than one host matches |
|
| 65 | + * services=>array of services (name) |
|
| 66 | + * hostid = host object id or -1 if not found. |
|
| 67 | + */ |
|
| 68 | 68 | public function getservicesAction() |
| 69 | 69 | { |
| 70 | 70 | $postData=$this->getRequest()->getPost(); |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** Get service list by host group ( name=<host> ) |
| 109 | - * returns in JSON : |
|
| 110 | - * status=>OK/No services found/More than one host matches |
|
| 111 | - * services=>array of services (name) |
|
| 112 | - * groupid = group object id or -1 if not found. |
|
| 113 | - */ |
|
| 109 | + * returns in JSON : |
|
| 110 | + * status=>OK/No services found/More than one host matches |
|
| 111 | + * services=>array of services (name) |
|
| 112 | + * groupid = group object id or -1 if not found. |
|
| 113 | + */ |
|
| 114 | 114 | public function gethostgroupservicesAction() |
| 115 | 115 | { |
| 116 | 116 | $postData=$this->getRequest()->getPost(); |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** Get traps from mib : entry : mib=<mib> |
| 143 | - * returns in JSON : |
|
| 144 | - * status=>OK/No mib/Error getting mibs |
|
| 145 | - * traps=>array of array( oid -> name) |
|
| 146 | - */ |
|
| 143 | + * returns in JSON : |
|
| 144 | + * status=>OK/No mib/Error getting mibs |
|
| 145 | + * traps=>array of array( oid -> name) |
|
| 146 | + */ |
|
| 147 | 147 | public function gettrapsAction() |
| 148 | 148 | { |
| 149 | 149 | $postData=$this->getRequest()->getPost(); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** Get trap objects from mib : entry : trap=<oid> |
| 166 | - * returns in JSON : |
|
| 167 | - * status=>OK/no trap/not found |
|
| 168 | - * objects=>array of array( oid -> name, oid->mib) |
|
| 169 | - */ |
|
| 166 | + * returns in JSON : |
|
| 167 | + * status=>OK/no trap/not found |
|
| 168 | + * objects=>array of array( oid -> name, oid->mib) |
|
| 169 | + */ |
|
| 170 | 170 | public function gettrapobjectsAction() |
| 171 | 171 | { |
| 172 | 172 | $postData=$this->getRequest()->getPost(); |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** Get list of all loaded mibs : entry : none |
| 189 | - * return : array of strings. |
|
| 190 | - */ |
|
| 189 | + * return : array of strings. |
|
| 190 | + */ |
|
| 191 | 191 | public function getmiblistAction() |
| 192 | 192 | { |
| 193 | 193 | try |
@@ -202,10 +202,10 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** Get MIB::Name from OID : entry : oid |
| 205 | - * status=>OK/No oid/not found |
|
| 206 | - * mib=>string |
|
| 207 | - * name=>string |
|
| 208 | - */ |
|
| 205 | + * status=>OK/No oid/not found |
|
| 206 | + * mib=>string |
|
| 207 | + * name=>string |
|
| 208 | + */ |
|
| 209 | 209 | public function translateoidAction() |
| 210 | 210 | { |
| 211 | 211 | $postData=$this->getRequest()->getPost(); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | 'name' => $object['name'], |
| 227 | 227 | 'type' => $object['type'], |
| 228 | 228 | 'type_enum' => $object['type_enum'], |
| 229 | - 'description' => $object['description'] |
|
| 229 | + 'description' => $object['description'] |
|
| 230 | 230 | ) |
| 231 | 231 | ); |
| 232 | 232 | } |
@@ -234,10 +234,10 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** Save or execute database purge of <n> days |
| 237 | - * days=>int |
|
| 238 | - * action=>save/execute |
|
| 239 | - * return : status=>OK/Message error |
|
| 240 | - */ |
|
| 237 | + * days=>int |
|
| 238 | + * action=>save/execute |
|
| 239 | + * return : status=>OK/Message error |
|
| 240 | + */ |
|
| 241 | 241 | public function dbmaintenanceAction() |
| 242 | 242 | { |
| 243 | 243 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | { |
| 253 | 253 | try |
| 254 | 254 | { |
| 255 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 255 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 256 | 256 | } |
| 257 | 257 | catch (Exception $e) |
| 258 | 258 | { |
@@ -290,33 +290,33 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | public function snmpconfigAction() |
| 292 | 292 | { |
| 293 | - $postData=$this->getRequest()->getPost(); |
|
| 293 | + $postData=$this->getRequest()->getPost(); |
|
| 294 | 294 | |
| 295 | - $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 295 | + $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 296 | 296 | |
| 297 | - $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 297 | + $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 298 | 298 | |
| 299 | - try |
|
| 300 | - { |
|
| 301 | - $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
| 302 | - $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
| 303 | - } |
|
| 304 | - catch (Exception $e) |
|
| 305 | - { |
|
| 306 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 307 | - return; |
|
| 308 | - } |
|
| 309 | - $this->_helper->json(array('status'=>'OK')); |
|
| 310 | - return; |
|
| 299 | + try |
|
| 300 | + { |
|
| 301 | + $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
| 302 | + $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
| 303 | + } |
|
| 304 | + catch (Exception $e) |
|
| 305 | + { |
|
| 306 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | + $this->_helper->json(array('status'=>'OK')); |
|
| 310 | + return; |
|
| 311 | 311 | |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** Save log output to db |
| 315 | - * destination=>log destination |
|
| 316 | - * file=>file name |
|
| 317 | - * level => int |
|
| 318 | - * return : status=>OK/Message error |
|
| 319 | - */ |
|
| 315 | + * destination=>log destination |
|
| 316 | + * file=>file name |
|
| 317 | + * level => int |
|
| 318 | + * return : status=>OK/Message error |
|
| 319 | + */ |
|
| 320 | 320 | public function logdestinationAction() |
| 321 | 321 | { |
| 322 | 322 | $postData=$this->getRequest()->getPost(); |
@@ -335,8 +335,8 @@ discard block |
||
| 335 | 335 | $fileHandler=@fopen($file,'w'); |
| 336 | 336 | if ($fileHandler == false) |
| 337 | 337 | { // File os note writabe / cannot create |
| 338 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 339 | - return; |
|
| 338 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 339 | + return; |
|
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | else |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | |
| 357 | 357 | try |
| 358 | 358 | { |
| 359 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 360 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 361 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 359 | + $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 360 | + $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 361 | + $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 362 | 362 | } |
| 363 | 363 | catch (Exception $e) |
| 364 | 364 | { |
@@ -378,33 +378,33 @@ discard block |
||
| 378 | 378 | public function testruleAction() |
| 379 | 379 | { |
| 380 | 380 | |
| 381 | - $postData=$this->getRequest()->getPost(); |
|
| 381 | + $postData=$this->getRequest()->getPost(); |
|
| 382 | 382 | |
| 383 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 383 | + $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 384 | 384 | |
| 385 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 385 | + $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 386 | 386 | |
| 387 | - if ($action == 'evaluate') |
|
| 388 | - { |
|
| 389 | - try |
|
| 390 | - { |
|
| 391 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 392 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 393 | - $trap = new Trap($icingaweb2_etc); |
|
| 394 | - // Cleanup spaces before eval |
|
| 395 | - $rule=$trap->ruleClass->eval_cleanup($rule); |
|
| 396 | - // Eval |
|
| 397 | - $item=0; |
|
| 398 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 399 | - } |
|
| 400 | - catch (Exception $e) |
|
| 401 | - { |
|
| 402 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 403 | - return; |
|
| 404 | - } |
|
| 405 | - $return=($rule==true)?'true':'false'; |
|
| 406 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 407 | - } |
|
| 387 | + if ($action == 'evaluate') |
|
| 388 | + { |
|
| 389 | + try |
|
| 390 | + { |
|
| 391 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 392 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 393 | + $trap = new Trap($icingaweb2_etc); |
|
| 394 | + // Cleanup spaces before eval |
|
| 395 | + $rule=$trap->ruleClass->eval_cleanup($rule); |
|
| 396 | + // Eval |
|
| 397 | + $item=0; |
|
| 398 | + $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 399 | + } |
|
| 400 | + catch (Exception $e) |
|
| 401 | + { |
|
| 402 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 403 | + return; |
|
| 404 | + } |
|
| 405 | + $return=($rule==true)?'true':'false'; |
|
| 406 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | } |
| 410 | 410 | |
@@ -415,35 +415,35 @@ discard block |
||
| 415 | 415 | */ |
| 416 | 416 | public function pluginAction() |
| 417 | 417 | { |
| 418 | - $postData=$this->getRequest()->getPost(); |
|
| 418 | + $postData=$this->getRequest()->getPost(); |
|
| 419 | 419 | |
| 420 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 420 | + $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 421 | 421 | |
| 422 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 422 | + $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 423 | 423 | |
| 424 | - try |
|
| 425 | - { |
|
| 426 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 427 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 428 | - $trap = new Trap($icingaweb2_etc); |
|
| 429 | - // Enable plugin. |
|
| 430 | - $action=($action == 'enable') ? true : false; |
|
| 431 | - $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
| 424 | + try |
|
| 425 | + { |
|
| 426 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 427 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 428 | + $trap = new Trap($icingaweb2_etc); |
|
| 429 | + // Enable plugin. |
|
| 430 | + $action=($action == 'enable') ? true : false; |
|
| 431 | + $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
| 432 | 432 | |
| 433 | - } |
|
| 434 | - catch (Exception $e) |
|
| 435 | - { |
|
| 436 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 437 | - return; |
|
| 438 | - } |
|
| 439 | - if ($retVal === true) |
|
| 440 | - { |
|
| 441 | - $this->_helper->json(array('status'=>'OK')); |
|
| 442 | - } |
|
| 443 | - else |
|
| 444 | - { |
|
| 445 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
| 446 | - } |
|
| 433 | + } |
|
| 434 | + catch (Exception $e) |
|
| 435 | + { |
|
| 436 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 437 | + return; |
|
| 438 | + } |
|
| 439 | + if ($retVal === true) |
|
| 440 | + { |
|
| 441 | + $this->_helper->json(array('status'=>'OK')); |
|
| 442 | + } |
|
| 443 | + else |
|
| 444 | + { |
|
| 445 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
| 446 | + } |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | /** Function evaluation |
@@ -453,49 +453,49 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | public function functionAction() |
| 455 | 455 | { |
| 456 | - $postData=$this->getRequest()->getPost(); |
|
| 456 | + $postData=$this->getRequest()->getPost(); |
|
| 457 | 457 | |
| 458 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 458 | + $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 459 | 459 | |
| 460 | - $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 460 | + $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 461 | 461 | |
| 462 | - // Only one action possible for now, no tests on action. |
|
| 463 | - try |
|
| 464 | - { |
|
| 465 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 466 | - $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 467 | - $trap = new Trap($icingaweb2Etc); |
|
| 468 | - // load all plugins in case tested function is not enabled. |
|
| 469 | - $trap->pluginClass->registerAllPlugins(false); |
|
| 470 | - // Clean all spaces |
|
| 471 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 472 | - // Eval functions |
|
| 473 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 474 | - } |
|
| 475 | - catch (Exception $e) |
|
| 476 | - { |
|
| 477 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 478 | - return; |
|
| 479 | - } |
|
| 462 | + // Only one action possible for now, no tests on action. |
|
| 463 | + try |
|
| 464 | + { |
|
| 465 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 466 | + $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 467 | + $trap = new Trap($icingaweb2Etc); |
|
| 468 | + // load all plugins in case tested function is not enabled. |
|
| 469 | + $trap->pluginClass->registerAllPlugins(false); |
|
| 470 | + // Clean all spaces |
|
| 471 | + $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 472 | + // Eval functions |
|
| 473 | + $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 474 | + } |
|
| 475 | + catch (Exception $e) |
|
| 476 | + { |
|
| 477 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 478 | + return; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - $result = ($result === true)?'True':'False'; |
|
| 482 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 481 | + $result = ($result === true)?'True':'False'; |
|
| 482 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - /************** Utilities **********************/ |
|
| 485 | + /************** Utilities **********************/ |
|
| 486 | 486 | |
| 487 | 487 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
| 488 | 488 | { |
| 489 | - if (!isset ($postData[$postVar])) |
|
| 490 | - { |
|
| 491 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
| 495 | - { |
|
| 496 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 497 | - return ''; |
|
| 498 | - } |
|
| 499 | - return $postData[$postVar]; |
|
| 489 | + if (!isset ($postData[$postVar])) |
|
| 490 | + { |
|
| 491 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
| 495 | + { |
|
| 496 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 497 | + return ''; |
|
| 498 | + } |
|
| 499 | + return $postData[$postVar]; |
|
| 500 | 500 | } |
| 501 | 501 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
| 20 | 20 | |
| 21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 22 | 22 | |
| 23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 24 | 24 | $this->getIdoConn(); // set apiMode to correct val |
| 25 | 25 | if ($this->apiMode === TRUE) |
| 26 | 26 | { |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | foreach ($hosts as $val) |
| 35 | 35 | { |
| 36 | - array_push($retHosts['hosts'],$val->name); |
|
| 36 | + array_push($retHosts['hosts'], $val->name); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $this->_helper->json($retHosts); |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $postData=$this->getRequest()->getPost(); |
| 48 | 48 | |
| 49 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 49 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 50 | 50 | |
| 51 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 51 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 52 | 52 | |
| 53 | 53 | $hosts=$this->getIdoConn()->getHostGroupByName($hostFilter); |
| 54 | 54 | foreach ($hosts as $val) |
| 55 | 55 | { |
| 56 | - array_push($retHosts['hosts'],$val->name); |
|
| 56 | + array_push($retHosts['hosts'], $val->name); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $this->_helper->json($retHosts); |
@@ -76,31 +76,31 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | else |
| 78 | 78 | { |
| 79 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
| 79 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
| 80 | 80 | return; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $hostArray=$this->getIdoConn()->getHostByName($host); |
| 84 | 84 | if (count($hostArray) > 1) |
| 85 | 85 | { |
| 86 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
| 86 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | 89 | else if (count($hostArray) == 0) |
| 90 | 90 | { |
| 91 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
| 91 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
| 92 | 92 | return; |
| 93 | 93 | } |
| 94 | 94 | $services=$this->getIdoConn()->getServicesByHostid($hostArray[0]->id); |
| 95 | 95 | if (count($services) < 1) |
| 96 | 96 | { |
| 97 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
| 97 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
| 100 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
| 101 | 101 | foreach ($services as $val) |
| 102 | 102 | { |
| 103 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
| 103 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
| 104 | 104 | } |
| 105 | 105 | $this->_helper->json($retServices); |
| 106 | 106 | } |
@@ -115,26 +115,26 @@ discard block |
||
| 115 | 115 | { |
| 116 | 116 | $postData=$this->getRequest()->getPost(); |
| 117 | 117 | |
| 118 | - $host = $this->checkPostVar($postData, 'host', '.+'); |
|
| 118 | + $host=$this->checkPostVar($postData, 'host', '.+'); |
|
| 119 | 119 | |
| 120 | 120 | $hostArray=$this->getIdoConn()->getHostGroupByName($host); |
| 121 | 121 | if (count($hostArray) > 1) |
| 122 | 122 | { |
| 123 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
| 123 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
| 124 | 124 | return; |
| 125 | 125 | } |
| 126 | 126 | else if (count($hostArray) == 0) |
| 127 | 127 | { |
| 128 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
| 128 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
| 129 | 129 | return; |
| 130 | 130 | } |
| 131 | 131 | $services=$this->getIdoConn()->getServicesByHostGroupid($hostArray[0]->id); |
| 132 | 132 | if (count($services) < 1) |
| 133 | 133 | { |
| 134 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
| 134 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
| 135 | 135 | return; |
| 136 | 136 | } |
| 137 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
| 137 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
| 138 | 138 | |
| 139 | 139 | $this->_helper->json($retServices); |
| 140 | 140 | } |
@@ -148,12 +148,12 @@ discard block |
||
| 148 | 148 | { |
| 149 | 149 | $postData=$this->getRequest()->getPost(); |
| 150 | 150 | |
| 151 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
| 151 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
| 152 | 152 | |
| 153 | 153 | try |
| 154 | 154 | { |
| 155 | 155 | $traplist=$this->getMIB()->getTrapList($mib); |
| 156 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
| 156 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
| 157 | 157 | } |
| 158 | 158 | catch (Exception $e) |
| 159 | 159 | { |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | $postData=$this->getRequest()->getPost(); |
| 173 | 173 | |
| 174 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
| 174 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
| 175 | 175 | |
| 176 | 176 | try |
| 177 | 177 | { |
| 178 | 178 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 179 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
| 179 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
| 180 | 180 | } |
| 181 | 181 | catch (Exception $e) |
| 182 | 182 | { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | { |
| 211 | 211 | $postData=$this->getRequest()->getPost(); |
| 212 | 212 | |
| 213 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
| 213 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
| 214 | 214 | |
| 215 | 215 | // Try to get oid name from snmptranslate |
| 216 | 216 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -243,20 +243,20 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | $postData=$this->getRequest()->getPost(); |
| 245 | 245 | |
| 246 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 246 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 247 | 247 | $days=intval($days); |
| 248 | 248 | |
| 249 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 249 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 250 | 250 | |
| 251 | 251 | if ($action == 'save') |
| 252 | 252 | { |
| 253 | 253 | try |
| 254 | 254 | { |
| 255 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 255 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days); |
|
| 256 | 256 | } |
| 257 | 257 | catch (Exception $e) |
| 258 | 258 | { |
| 259 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 259 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | $this->_helper->json(array('status'=>'OK')); |
@@ -266,16 +266,16 @@ discard block |
||
| 266 | 266 | { |
| 267 | 267 | try |
| 268 | 268 | { |
| 269 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 269 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 270 | 270 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 271 | 271 | $debug_level=4; |
| 272 | - $trap = new Trap($icingaweb2_etc); |
|
| 273 | - $trap->setLogging($debug_level,'syslog'); |
|
| 272 | + $trap=new Trap($icingaweb2_etc); |
|
| 273 | + $trap->setLogging($debug_level, 'syslog'); |
|
| 274 | 274 | $trap->eraseOldTraps($days); |
| 275 | 275 | } |
| 276 | 276 | catch (Exception $e) |
| 277 | 277 | { |
| 278 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
| 278 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
| 279 | 279 | return; |
| 280 | 280 | } |
| 281 | 281 | $this->_helper->json(array('status'=>'OK')); |
@@ -292,18 +292,18 @@ discard block |
||
| 292 | 292 | { |
| 293 | 293 | $postData=$this->getRequest()->getPost(); |
| 294 | 294 | |
| 295 | - $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 295 | + $snmpUse=$this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 296 | 296 | |
| 297 | - $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 297 | + $snmpOID=$this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 298 | 298 | |
| 299 | 299 | try |
| 300 | 300 | { |
| 301 | - $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
| 302 | - $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
| 301 | + $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess', $snmpUse); |
|
| 302 | + $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid', $snmpOID); |
|
| 303 | 303 | } |
| 304 | 304 | catch (Exception $e) |
| 305 | 305 | { |
| 306 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 306 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 307 | 307 | return; |
| 308 | 308 | } |
| 309 | 309 | $this->_helper->json(array('status'=>'OK')); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | { |
| 322 | 322 | $postData=$this->getRequest()->getPost(); |
| 323 | 323 | |
| 324 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
| 324 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
| 325 | 325 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
| 326 | 326 | if (!isset($logDest[$destination])) |
| 327 | 327 | { |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | if (isset($postData['file'])) |
| 333 | 333 | { |
| 334 | 334 | $file=$postData['file']; |
| 335 | - $fileHandler=@fopen($file,'w'); |
|
| 335 | + $fileHandler=@fopen($file, 'w'); |
|
| 336 | 336 | if ($fileHandler == false) |
| 337 | 337 | { // File os note writabe / cannot create |
| 338 | 338 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -352,17 +352,17 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 355 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 356 | 356 | |
| 357 | 357 | try |
| 358 | 358 | { |
| 359 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 360 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 361 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 359 | + $this->getUIDatabase()->setDBConfigValue('log_destination', $destination); |
|
| 360 | + $this->getUIDatabase()->setDBConfigValue('log_file', $file); |
|
| 361 | + $this->getUIDatabase()->setDBConfigValue('log_level', $level); |
|
| 362 | 362 | } |
| 363 | 363 | catch (Exception $e) |
| 364 | 364 | { |
| 365 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 365 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | $this->_helper->json(array('status'=>'OK')); |
@@ -380,29 +380,29 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | $postData=$this->getRequest()->getPost(); |
| 382 | 382 | |
| 383 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 383 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
| 384 | 384 | |
| 385 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 385 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 386 | 386 | |
| 387 | 387 | if ($action == 'evaluate') |
| 388 | 388 | { |
| 389 | 389 | try |
| 390 | 390 | { |
| 391 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 391 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 392 | 392 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 393 | - $trap = new Trap($icingaweb2_etc); |
|
| 393 | + $trap=new Trap($icingaweb2_etc); |
|
| 394 | 394 | // Cleanup spaces before eval |
| 395 | 395 | $rule=$trap->ruleClass->eval_cleanup($rule); |
| 396 | 396 | // Eval |
| 397 | 397 | $item=0; |
| 398 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 398 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
| 399 | 399 | } |
| 400 | 400 | catch (Exception $e) |
| 401 | 401 | { |
| 402 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 402 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
| 403 | 403 | return; |
| 404 | 404 | } |
| 405 | - $return=($rule==true)?'true':'false'; |
|
| 405 | + $return=($rule == true) ? 'true' : 'false'; |
|
| 406 | 406 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
| 407 | 407 | } |
| 408 | 408 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | { |
| 418 | 418 | $postData=$this->getRequest()->getPost(); |
| 419 | 419 | |
| 420 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 420 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
| 421 | 421 | |
| 422 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 422 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 423 | 423 | |
| 424 | 424 | try |
| 425 | 425 | { |
| 426 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 426 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 427 | 427 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 428 | - $trap = new Trap($icingaweb2_etc); |
|
| 428 | + $trap=new Trap($icingaweb2_etc); |
|
| 429 | 429 | // Enable plugin. |
| 430 | 430 | $action=($action == 'enable') ? true : false; |
| 431 | 431 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | catch (Exception $e) |
| 435 | 435 | { |
| 436 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 436 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 437 | 437 | return; |
| 438 | 438 | } |
| 439 | 439 | if ($retVal === true) |
@@ -455,45 +455,45 @@ discard block |
||
| 455 | 455 | { |
| 456 | 456 | $postData=$this->getRequest()->getPost(); |
| 457 | 457 | |
| 458 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 458 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
| 459 | 459 | |
| 460 | 460 | $this->checkPostVar($postData, 'action', 'evaluate'); |
| 461 | 461 | |
| 462 | 462 | // Only one action possible for now, no tests on action. |
| 463 | 463 | try |
| 464 | 464 | { |
| 465 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 465 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 466 | 466 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 467 | - $trap = new Trap($icingaweb2Etc); |
|
| 467 | + $trap=new Trap($icingaweb2Etc); |
|
| 468 | 468 | // load all plugins in case tested function is not enabled. |
| 469 | 469 | $trap->pluginClass->registerAllPlugins(false); |
| 470 | 470 | // Clean all spaces |
| 471 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 471 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
| 472 | 472 | // Eval functions |
| 473 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 473 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
| 474 | 474 | } |
| 475 | 475 | catch (Exception $e) |
| 476 | 476 | { |
| 477 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 477 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 478 | 478 | return; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - $result = ($result === true)?'True':'False'; |
|
| 482 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 481 | + $result=($result === true) ? 'True' : 'False'; |
|
| 482 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /************** Utilities **********************/ |
| 486 | 486 | |
| 487 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
| 487 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
| 488 | 488 | { |
| 489 | 489 | if (!isset ($postData[$postVar])) |
| 490 | 490 | { |
| 491 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 491 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
| 492 | 492 | return ''; |
| 493 | 493 | } |
| 494 | 494 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
| 495 | 495 | { |
| 496 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 496 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
| 497 | 497 | return ''; |
| 498 | 498 | } |
| 499 | 499 | return $postData[$postVar]; |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $hosts=$this->getIdoConn()->getHostByNameOrIP($hostFilter); |
| 28 | 28 | $retHosts['test']=count($hosts); |
| 29 | - } |
|
| 30 | - else |
|
| 29 | + } else |
|
| 31 | 30 | { |
| 32 | 31 | $hosts=$this->getIdoConn()->getHostByIP($hostFilter); |
| 33 | 32 | } |
@@ -73,8 +72,7 @@ discard block |
||
| 73 | 72 | if (isset($postData['host'])) |
| 74 | 73 | { |
| 75 | 74 | $host=$postData['host']; |
| 76 | - } |
|
| 77 | - else |
|
| 75 | + } else |
|
| 78 | 76 | { |
| 79 | 77 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
| 80 | 78 | return; |
@@ -85,8 +83,7 @@ discard block |
||
| 85 | 83 | { |
| 86 | 84 | $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
| 87 | 85 | return; |
| 88 | - } |
|
| 89 | - else if (count($hostArray) == 0) |
|
| 86 | + } else if (count($hostArray) == 0) |
|
| 90 | 87 | { |
| 91 | 88 | $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
| 92 | 89 | return; |
@@ -122,8 +119,7 @@ discard block |
||
| 122 | 119 | { |
| 123 | 120 | $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
| 124 | 121 | return; |
| 125 | - } |
|
| 126 | - else if (count($hostArray) == 0) |
|
| 122 | + } else if (count($hostArray) == 0) |
|
| 127 | 123 | { |
| 128 | 124 | $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
| 129 | 125 | return; |
@@ -154,8 +150,7 @@ discard block |
||
| 154 | 150 | { |
| 155 | 151 | $traplist=$this->getMIB()->getTrapList($mib); |
| 156 | 152 | $retTraps=array('status'=>'OK','traps' => $traplist); |
| 157 | - } |
|
| 158 | - catch (Exception $e) |
|
| 153 | + } catch (Exception $e) |
|
| 159 | 154 | { |
| 160 | 155 | $retTraps=array('status' => 'Error getting mibs'); |
| 161 | 156 | } |
@@ -177,8 +172,7 @@ discard block |
||
| 177 | 172 | { |
| 178 | 173 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 179 | 174 | $retObjects=array('status'=>'OK','objects' => $objectlist); |
| 180 | - } |
|
| 181 | - catch (Exception $e) |
|
| 175 | + } catch (Exception $e) |
|
| 182 | 176 | { |
| 183 | 177 | $retObjects=array('status' => 'not found'); |
| 184 | 178 | } |
@@ -193,8 +187,7 @@ discard block |
||
| 193 | 187 | try |
| 194 | 188 | { |
| 195 | 189 | $miblist=$this->getMIB()->getMIBList(); |
| 196 | - } |
|
| 197 | - catch (Exception $e) |
|
| 190 | + } catch (Exception $e) |
|
| 198 | 191 | { |
| 199 | 192 | $miblist=array('Error getting mibs'); |
| 200 | 193 | } |
@@ -217,8 +210,7 @@ discard block |
||
| 217 | 210 | { |
| 218 | 211 | $this->_helper->json(array('status'=>'Not found')); |
| 219 | 212 | return; |
| 220 | - } |
|
| 221 | - else |
|
| 213 | + } else |
|
| 222 | 214 | { |
| 223 | 215 | $this->_helper->json( |
| 224 | 216 | array('status'=>'OK', |
@@ -253,8 +245,7 @@ discard block |
||
| 253 | 245 | try |
| 254 | 246 | { |
| 255 | 247 | $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
| 256 | - } |
|
| 257 | - catch (Exception $e) |
|
| 248 | + } catch (Exception $e) |
|
| 258 | 249 | { |
| 259 | 250 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 260 | 251 | return; |
@@ -272,8 +263,7 @@ discard block |
||
| 272 | 263 | $trap = new Trap($icingaweb2_etc); |
| 273 | 264 | $trap->setLogging($debug_level,'syslog'); |
| 274 | 265 | $trap->eraseOldTraps($days); |
| 275 | - } |
|
| 276 | - catch (Exception $e) |
|
| 266 | + } catch (Exception $e) |
|
| 277 | 267 | { |
| 278 | 268 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
| 279 | 269 | return; |
@@ -300,8 +290,7 @@ discard block |
||
| 300 | 290 | { |
| 301 | 291 | $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
| 302 | 292 | $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
| 303 | - } |
|
| 304 | - catch (Exception $e) |
|
| 293 | + } catch (Exception $e) |
|
| 305 | 294 | { |
| 306 | 295 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 307 | 296 | return; |
@@ -338,14 +327,12 @@ discard block |
||
| 338 | 327 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
| 339 | 328 | return; |
| 340 | 329 | } |
| 341 | - } |
|
| 342 | - else |
|
| 330 | + } else |
|
| 343 | 331 | { |
| 344 | 332 | if ($destination != 'file') |
| 345 | 333 | { |
| 346 | 334 | $file=null; |
| 347 | - } |
|
| 348 | - else |
|
| 335 | + } else |
|
| 349 | 336 | { |
| 350 | 337 | $this->_helper->json(array('status'=>'No file')); |
| 351 | 338 | return; |
@@ -359,8 +346,7 @@ discard block |
||
| 359 | 346 | $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
| 360 | 347 | $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
| 361 | 348 | $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
| 362 | - } |
|
| 363 | - catch (Exception $e) |
|
| 349 | + } catch (Exception $e) |
|
| 364 | 350 | { |
| 365 | 351 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
| 366 | 352 | return; |
@@ -396,8 +382,7 @@ discard block |
||
| 396 | 382 | // Eval |
| 397 | 383 | $item=0; |
| 398 | 384 | $rule=$trap->ruleClass->evaluation($rule,$item); |
| 399 | - } |
|
| 400 | - catch (Exception $e) |
|
| 385 | + } catch (Exception $e) |
|
| 401 | 386 | { |
| 402 | 387 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
| 403 | 388 | return; |
@@ -430,8 +415,7 @@ discard block |
||
| 430 | 415 | $action=($action == 'enable') ? true : false; |
| 431 | 416 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
| 432 | 417 | |
| 433 | - } |
|
| 434 | - catch (Exception $e) |
|
| 418 | + } catch (Exception $e) |
|
| 435 | 419 | { |
| 436 | 420 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 437 | 421 | return; |
@@ -439,8 +423,7 @@ discard block |
||
| 439 | 423 | if ($retVal === true) |
| 440 | 424 | { |
| 441 | 425 | $this->_helper->json(array('status'=>'OK')); |
| 442 | - } |
|
| 443 | - else |
|
| 426 | + } else |
|
| 444 | 427 | { |
| 445 | 428 | $this->_helper->json(array('status'=>'Error, see logs')); |
| 446 | 429 | } |
@@ -471,8 +454,7 @@ discard block |
||
| 471 | 454 | $functionString = $trap->ruleClass->eval_cleanup($functionString); |
| 472 | 455 | // Eval functions |
| 473 | 456 | $result = $trap->pluginClass->evaluateFunctionString($functionString); |
| 474 | - } |
|
| 475 | - catch (Exception $e) |
|
| 457 | + } catch (Exception $e) |
|
| 476 | 458 | { |
| 477 | 459 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
| 478 | 460 | return; |