@@ -19,207 +19,207 @@ |
||
19 | 19 | trait TrapDBQuery |
20 | 20 | { |
21 | 21 | |
22 | - /** @return TrapsController */ |
|
23 | - abstract protected function getTrapCtrl(); |
|
22 | + /** @return TrapsController */ |
|
23 | + abstract protected function getTrapCtrl(); |
|
24 | 24 | |
25 | - /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
26 | - abstract public function getDbConn(); |
|
25 | + /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
26 | + abstract public function getDbConn(); |
|
27 | 27 | |
28 | - /** Add handler rule in traps DB |
|
29 | - * @param array $params : array(<db item>=><value>) |
|
30 | - * @return int inserted id |
|
31 | - */ |
|
32 | - public function addHandlerRule($params) |
|
33 | - { |
|
34 | - // TODO Check for rule consistency |
|
28 | + /** Add handler rule in traps DB |
|
29 | + * @param array $params : array(<db item>=><value>) |
|
30 | + * @return int inserted id |
|
31 | + */ |
|
32 | + public function addHandlerRule($params) |
|
33 | + { |
|
34 | + // TODO Check for rule consistency |
|
35 | 35 | |
36 | - $dbConn = $this->getDbConn(); |
|
37 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
38 | - // Add last modified date = creation date and username |
|
39 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
40 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
41 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
36 | + $dbConn = $this->getDbConn(); |
|
37 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
38 | + // Add last modified date = creation date and username |
|
39 | + $params['created'] = new Zend_Db_Expr('NOW()'); |
|
40 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
41 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
42 | 42 | |
43 | - $query=$dbConn->insert( |
|
44 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
45 | - $params |
|
46 | - ); |
|
47 | - if($query==false) |
|
48 | - { |
|
49 | - return null; |
|
50 | - } |
|
51 | - return $dbConn->lastInsertId(); |
|
52 | - } |
|
43 | + $query=$dbConn->insert( |
|
44 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
45 | + $params |
|
46 | + ); |
|
47 | + if($query==false) |
|
48 | + { |
|
49 | + return null; |
|
50 | + } |
|
51 | + return $dbConn->lastInsertId(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** Update handler rule in traps DB |
|
55 | - * @param array $params : (<db item>=><value>) |
|
56 | - * @param integer $ruleID : rule id in db |
|
57 | - * @return array affected rows |
|
58 | - */ |
|
59 | - public function updateHandlerRule($params,$ruleID) |
|
60 | - { |
|
61 | - // TODO Check for rule consistency |
|
62 | - $dbConn = $this->getDbConn(); |
|
63 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
64 | - // Add last modified date = creation date and username |
|
65 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
66 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
54 | + /** Update handler rule in traps DB |
|
55 | + * @param array $params : (<db item>=><value>) |
|
56 | + * @param integer $ruleID : rule id in db |
|
57 | + * @return array affected rows |
|
58 | + */ |
|
59 | + public function updateHandlerRule($params,$ruleID) |
|
60 | + { |
|
61 | + // TODO Check for rule consistency |
|
62 | + $dbConn = $this->getDbConn(); |
|
63 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
64 | + // Add last modified date = creation date and username |
|
65 | + $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
66 | + $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
67 | 67 | |
68 | - $numRows=$dbConn->update( |
|
69 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
70 | - $params, |
|
71 | - 'id='.$ruleID |
|
72 | - ); |
|
73 | - return $numRows; |
|
74 | - } |
|
68 | + $numRows=$dbConn->update( |
|
69 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
70 | + $params, |
|
71 | + 'id='.$ruleID |
|
72 | + ); |
|
73 | + return $numRows; |
|
74 | + } |
|
75 | 75 | |
76 | - /** Delete rule by id |
|
77 | - * @param int $ruleID rule id |
|
78 | - */ |
|
79 | - public function deleteRule($ruleID) |
|
80 | - { |
|
81 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
76 | + /** Delete rule by id |
|
77 | + * @param int $ruleID rule id |
|
78 | + */ |
|
79 | + public function deleteRule($ruleID) |
|
80 | + { |
|
81 | + if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
82 | 82 | |
83 | - $dbConn = $this->getDbConn(); |
|
84 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
83 | + $dbConn = $this->getDbConn(); |
|
84 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
85 | 85 | |
86 | - $query=$dbConn->delete( |
|
87 | - $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
88 | - 'id='.$ruleID |
|
89 | - ); |
|
90 | - return $query; |
|
91 | - } |
|
86 | + $query=$dbConn->delete( |
|
87 | + $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
|
88 | + 'id='.$ruleID |
|
89 | + ); |
|
90 | + return $query; |
|
91 | + } |
|
92 | 92 | |
93 | - /** Delete trap by ip & oid |
|
94 | - * @param $ipAddr string source IP (v4 or v6) |
|
95 | - * @param $oid string oid |
|
96 | - */ |
|
97 | - public function deleteTrap($ipAddr,$oid) |
|
98 | - { |
|
93 | + /** Delete trap by ip & oid |
|
94 | + * @param $ipAddr string source IP (v4 or v6) |
|
95 | + * @param $oid string oid |
|
96 | + */ |
|
97 | + public function deleteTrap($ipAddr,$oid) |
|
98 | + { |
|
99 | 99 | |
100 | - $dbConn = $this->getDbConn(); |
|
101 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
102 | - $condition=null; |
|
103 | - if ($ipAddr != null) |
|
104 | - { |
|
105 | - $condition="source_ip='$ipAddr'"; |
|
106 | - } |
|
107 | - if ($oid != null) |
|
108 | - { |
|
109 | - $condition=($condition===null)?'':$condition.' AND '; |
|
110 | - $condition.="trap_oid='$oid'"; |
|
111 | - } |
|
112 | - if($condition === null) return null; |
|
113 | - $query=$dbConn->delete( |
|
114 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
115 | - $condition |
|
116 | - ); |
|
117 | - // TODO test ret code etc... |
|
118 | - return $query; |
|
119 | - } |
|
100 | + $dbConn = $this->getDbConn(); |
|
101 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
102 | + $condition=null; |
|
103 | + if ($ipAddr != null) |
|
104 | + { |
|
105 | + $condition="source_ip='$ipAddr'"; |
|
106 | + } |
|
107 | + if ($oid != null) |
|
108 | + { |
|
109 | + $condition=($condition===null)?'':$condition.' AND '; |
|
110 | + $condition.="trap_oid='$oid'"; |
|
111 | + } |
|
112 | + if($condition === null) return null; |
|
113 | + $query=$dbConn->delete( |
|
114 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
115 | + $condition |
|
116 | + ); |
|
117 | + // TODO test ret code etc... |
|
118 | + return $query; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** count trap by ip & oid |
|
123 | - * @param $ipAddr string source IP (v4 or v6) |
|
124 | - * @param $oid string oid |
|
125 | - */ |
|
126 | - public function countTrap($ipAddr,$oid) |
|
127 | - { |
|
122 | + /** count trap by ip & oid |
|
123 | + * @param $ipAddr string source IP (v4 or v6) |
|
124 | + * @param $oid string oid |
|
125 | + */ |
|
126 | + public function countTrap($ipAddr,$oid) |
|
127 | + { |
|
128 | 128 | |
129 | - $dbConn = $this->getDbConn(); |
|
130 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
129 | + $dbConn = $this->getDbConn(); |
|
130 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
131 | 131 | |
132 | - $condition=null; |
|
133 | - if ($ipAddr != null) |
|
134 | - { |
|
135 | - $condition="source_ip='$ipAddr'"; |
|
136 | - } |
|
137 | - if ($oid != null) |
|
138 | - { |
|
139 | - $condition=($condition===null)?'':$condition.' AND '; |
|
140 | - $condition.="trap_oid='$oid'"; |
|
141 | - } |
|
142 | - if($condition === null) return 0; |
|
143 | - $query=$dbConn->select() |
|
144 | - ->from( |
|
145 | - $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
146 | - array('num'=>'count(*)')) |
|
147 | - ->where($condition); |
|
148 | - $returnRow=$dbConn->fetchRow($query); |
|
149 | - return $returnRow->num; |
|
150 | - } |
|
132 | + $condition=null; |
|
133 | + if ($ipAddr != null) |
|
134 | + { |
|
135 | + $condition="source_ip='$ipAddr'"; |
|
136 | + } |
|
137 | + if ($oid != null) |
|
138 | + { |
|
139 | + $condition=($condition===null)?'':$condition.' AND '; |
|
140 | + $condition.="trap_oid='$oid'"; |
|
141 | + } |
|
142 | + if($condition === null) return 0; |
|
143 | + $query=$dbConn->select() |
|
144 | + ->from( |
|
145 | + $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
|
146 | + array('num'=>'count(*)')) |
|
147 | + ->where($condition); |
|
148 | + $returnRow=$dbConn->fetchRow($query); |
|
149 | + return $returnRow->num; |
|
150 | + } |
|
151 | 151 | |
152 | - /** get configuration value |
|
153 | - * @param string $element : configuration name in db |
|
154 | - */ |
|
155 | - public function getDBConfigValue($element) |
|
156 | - { |
|
152 | + /** get configuration value |
|
153 | + * @param string $element : configuration name in db |
|
154 | + */ |
|
155 | + public function getDBConfigValue($element) |
|
156 | + { |
|
157 | 157 | |
158 | - $dbConn = $this->getDbConn(); |
|
159 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
158 | + $dbConn = $this->getDbConn(); |
|
159 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
160 | 160 | |
161 | - $query=$dbConn->select() |
|
162 | - ->from( |
|
163 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
164 | - array('value'=>'value')) |
|
165 | - ->where('name=?',$element); |
|
166 | - $returnRow=$dbConn->fetchRow($query); |
|
167 | - if ($returnRow==null) // value does not exists |
|
168 | - { |
|
169 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
170 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
161 | + $query=$dbConn->select() |
|
162 | + ->from( |
|
163 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
164 | + array('value'=>'value')) |
|
165 | + ->where('name=?',$element); |
|
166 | + $returnRow=$dbConn->fetchRow($query); |
|
167 | + if ($returnRow==null) // value does not exists |
|
168 | + { |
|
169 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
170 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
171 | 171 | |
172 | - $this->addDBConfigValue($element,$default[$element]); |
|
173 | - return $default[$element]; |
|
174 | - } |
|
175 | - if ($returnRow->value == null) // value id empty |
|
176 | - { |
|
177 | - $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
178 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
179 | - $this->setDBConfigValue($element,$default[$element]); |
|
180 | - return $default[$element]; |
|
181 | - } |
|
182 | - return $returnRow->value; |
|
183 | - } |
|
172 | + $this->addDBConfigValue($element,$default[$element]); |
|
173 | + return $default[$element]; |
|
174 | + } |
|
175 | + if ($returnRow->value == null) // value id empty |
|
176 | + { |
|
177 | + $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
|
178 | + if ( ! isset($default[$element])) return null; // no default and not value |
|
179 | + $this->setDBConfigValue($element,$default[$element]); |
|
180 | + return $default[$element]; |
|
181 | + } |
|
182 | + return $returnRow->value; |
|
183 | + } |
|
184 | 184 | |
185 | - /** add configuration value |
|
186 | - * @param string $element : name of config element |
|
187 | - * @param string $value : value |
|
188 | - */ |
|
185 | + /** add configuration value |
|
186 | + * @param string $element : name of config element |
|
187 | + * @param string $value : value |
|
188 | + */ |
|
189 | 189 | |
190 | - public function addDBConfigValue($element,$value) |
|
191 | - { |
|
190 | + public function addDBConfigValue($element,$value) |
|
191 | + { |
|
192 | 192 | |
193 | - $dbConn = $this->getDbConn(); |
|
194 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
193 | + $dbConn = $this->getDbConn(); |
|
194 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
195 | 195 | |
196 | - $query=$dbConn->insert( |
|
197 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
198 | - array( |
|
199 | - 'name' => $element, |
|
200 | - 'value'=>$value |
|
201 | - ) |
|
202 | - ); |
|
203 | - return $query; |
|
204 | - } |
|
196 | + $query=$dbConn->insert( |
|
197 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
198 | + array( |
|
199 | + 'name' => $element, |
|
200 | + 'value'=>$value |
|
201 | + ) |
|
202 | + ); |
|
203 | + return $query; |
|
204 | + } |
|
205 | 205 | |
206 | - /** set configuration value |
|
207 | - * @param string $element : name of config element |
|
208 | - * @param string $value : value |
|
209 | - */ |
|
210 | - public function setDBConfigValue($element,$value) |
|
211 | - { |
|
206 | + /** set configuration value |
|
207 | + * @param string $element : name of config element |
|
208 | + * @param string $value : value |
|
209 | + */ |
|
210 | + public function setDBConfigValue($element,$value) |
|
211 | + { |
|
212 | 212 | |
213 | - $dbConn = $this->getDbConn(); |
|
214 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
213 | + $dbConn = $this->getDbConn(); |
|
214 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
215 | 215 | |
216 | - $query=$dbConn->update( |
|
217 | - $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
218 | - array('value'=>$value), |
|
219 | - 'name=\''.$element.'\'' |
|
220 | - ); |
|
221 | - return $query; |
|
222 | - } |
|
216 | + $query=$dbConn->update( |
|
217 | + $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
|
218 | + array('value'=>$value), |
|
219 | + 'name=\''.$element.'\'' |
|
220 | + ); |
|
221 | + return $query; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | 225 | } |
226 | 226 | \ No newline at end of file |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | { |
34 | 34 | // TODO Check for rule consistency |
35 | 35 | |
36 | - $dbConn = $this->getDbConn(); |
|
36 | + $dbConn=$this->getDbConn(); |
|
37 | 37 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
38 | 38 | // Add last modified date = creation date and username |
39 | - $params['created'] = new Zend_Db_Expr('NOW()'); |
|
40 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
41 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
39 | + $params['created']=new Zend_Db_Expr('NOW()'); |
|
40 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
41 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
42 | 42 | |
43 | 43 | $query=$dbConn->insert( |
44 | 44 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
45 | 45 | $params |
46 | 46 | ); |
47 | - if($query==false) |
|
47 | + if ($query == false) |
|
48 | 48 | { |
49 | 49 | return null; |
50 | 50 | } |
@@ -56,14 +56,14 @@ discard block |
||
56 | 56 | * @param integer $ruleID : rule id in db |
57 | 57 | * @return array affected rows |
58 | 58 | */ |
59 | - public function updateHandlerRule($params,$ruleID) |
|
59 | + public function updateHandlerRule($params, $ruleID) |
|
60 | 60 | { |
61 | 61 | // TODO Check for rule consistency |
62 | - $dbConn = $this->getDbConn(); |
|
62 | + $dbConn=$this->getDbConn(); |
|
63 | 63 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
64 | 64 | // Add last modified date = creation date and username |
65 | - $params['modified'] = new Zend_Db_Expr('NOW()'); |
|
66 | - $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
65 | + $params['modified']=new Zend_Db_Expr('NOW()'); |
|
66 | + $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername(); |
|
67 | 67 | |
68 | 68 | $numRows=$dbConn->update( |
69 | 69 | $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(), |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function deleteRule($ruleID) |
80 | 80 | { |
81 | - if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
|
81 | + if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); } |
|
82 | 82 | |
83 | - $dbConn = $this->getDbConn(); |
|
83 | + $dbConn=$this->getDbConn(); |
|
84 | 84 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
85 | 85 | |
86 | 86 | $query=$dbConn->delete( |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | * @param $ipAddr string source IP (v4 or v6) |
95 | 95 | * @param $oid string oid |
96 | 96 | */ |
97 | - public function deleteTrap($ipAddr,$oid) |
|
97 | + public function deleteTrap($ipAddr, $oid) |
|
98 | 98 | { |
99 | 99 | |
100 | - $dbConn = $this->getDbConn(); |
|
100 | + $dbConn=$this->getDbConn(); |
|
101 | 101 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
102 | 102 | $condition=null; |
103 | 103 | if ($ipAddr != null) |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | } |
107 | 107 | if ($oid != null) |
108 | 108 | { |
109 | - $condition=($condition===null)?'':$condition.' AND '; |
|
109 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
110 | 110 | $condition.="trap_oid='$oid'"; |
111 | 111 | } |
112 | - if($condition === null) return null; |
|
112 | + if ($condition === null) return null; |
|
113 | 113 | $query=$dbConn->delete( |
114 | 114 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
115 | 115 | $condition |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | * @param $ipAddr string source IP (v4 or v6) |
124 | 124 | * @param $oid string oid |
125 | 125 | */ |
126 | - public function countTrap($ipAddr,$oid) |
|
126 | + public function countTrap($ipAddr, $oid) |
|
127 | 127 | { |
128 | 128 | |
129 | - $dbConn = $this->getDbConn(); |
|
129 | + $dbConn=$this->getDbConn(); |
|
130 | 130 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
131 | 131 | |
132 | 132 | $condition=null; |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | } |
137 | 137 | if ($oid != null) |
138 | 138 | { |
139 | - $condition=($condition===null)?'':$condition.' AND '; |
|
139 | + $condition=($condition === null) ? '' : $condition.' AND '; |
|
140 | 140 | $condition.="trap_oid='$oid'"; |
141 | 141 | } |
142 | - if($condition === null) return 0; |
|
142 | + if ($condition === null) return 0; |
|
143 | 143 | $query=$dbConn->select() |
144 | 144 | ->from( |
145 | 145 | $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(), |
@@ -155,28 +155,28 @@ discard block |
||
155 | 155 | public function getDBConfigValue($element) |
156 | 156 | { |
157 | 157 | |
158 | - $dbConn = $this->getDbConn(); |
|
158 | + $dbConn=$this->getDbConn(); |
|
159 | 159 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
160 | 160 | |
161 | 161 | $query=$dbConn->select() |
162 | 162 | ->from( |
163 | 163 | $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(), |
164 | 164 | array('value'=>'value')) |
165 | - ->where('name=?',$element); |
|
165 | + ->where('name=?', $element); |
|
166 | 166 | $returnRow=$dbConn->fetchRow($query); |
167 | - if ($returnRow==null) // value does not exists |
|
167 | + if ($returnRow == null) // value does not exists |
|
168 | 168 | { |
169 | 169 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
170 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
170 | + if (!isset($default[$element])) return null; // no default and not value |
|
171 | 171 | |
172 | - $this->addDBConfigValue($element,$default[$element]); |
|
172 | + $this->addDBConfigValue($element, $default[$element]); |
|
173 | 173 | return $default[$element]; |
174 | 174 | } |
175 | 175 | if ($returnRow->value == null) // value id empty |
176 | 176 | { |
177 | 177 | $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults(); |
178 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
179 | - $this->setDBConfigValue($element,$default[$element]); |
|
178 | + if (!isset($default[$element])) return null; // no default and not value |
|
179 | + $this->setDBConfigValue($element, $default[$element]); |
|
180 | 180 | return $default[$element]; |
181 | 181 | } |
182 | 182 | return $returnRow->value; |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | * @param string $value : value |
188 | 188 | */ |
189 | 189 | |
190 | - public function addDBConfigValue($element,$value) |
|
190 | + public function addDBConfigValue($element, $value) |
|
191 | 191 | { |
192 | 192 | |
193 | - $dbConn = $this->getDbConn(); |
|
193 | + $dbConn=$this->getDbConn(); |
|
194 | 194 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
195 | 195 | |
196 | 196 | $query=$dbConn->insert( |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | * @param string $element : name of config element |
208 | 208 | * @param string $value : value |
209 | 209 | */ |
210 | - public function setDBConfigValue($element,$value) |
|
210 | + public function setDBConfigValue($element, $value) |
|
211 | 211 | { |
212 | 212 | |
213 | - $dbConn = $this->getDbConn(); |
|
213 | + $dbConn=$this->getDbConn(); |
|
214 | 214 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
215 | 215 | |
216 | 216 | $query=$dbConn->update( |
@@ -19,30 +19,30 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class DBException extends Exception |
21 | 21 | { |
22 | - /** @var array $returnArray */ |
|
23 | - private $returnArray; |
|
22 | + /** @var array $returnArray */ |
|
23 | + private $returnArray; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Buil DBException |
|
27 | - * @param array $retarray |
|
28 | - * @param string $message |
|
29 | - * @param int $code |
|
30 | - * @param Exception $previous |
|
31 | - */ |
|
32 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
33 | - { |
|
34 | - parent::__construct($message,$code,$previous); |
|
35 | - $this->returnArray = $retarray; |
|
36 | - } |
|
25 | + /** |
|
26 | + * Buil DBException |
|
27 | + * @param array $retarray |
|
28 | + * @param string $message |
|
29 | + * @param int $code |
|
30 | + * @param Exception $previous |
|
31 | + */ |
|
32 | + public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
33 | + { |
|
34 | + parent::__construct($message,$code,$previous); |
|
35 | + $this->returnArray = $retarray; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get exception array |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function getArray() |
|
43 | - { |
|
44 | - return $this->returnArray; |
|
45 | - } |
|
38 | + /** |
|
39 | + * Get exception array |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function getArray() |
|
43 | + { |
|
44 | + return $this->returnArray; |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -56,278 +56,278 @@ discard block |
||
56 | 56 | */ |
57 | 57 | class UIDatabase //extends TrapDBQuery |
58 | 58 | { |
59 | - use TrapDBQuery,IdoDBQuery; |
|
59 | + use TrapDBQuery,IdoDBQuery; |
|
60 | 60 | |
61 | - /** @var TrapsController $trapController TrapController 'parent' class */ |
|
62 | - protected $trapController=null; |
|
61 | + /** @var TrapsController $trapController TrapController 'parent' class */ |
|
62 | + protected $trapController=null; |
|
63 | 63 | |
64 | - /** @var Selectable $trapDB Trap Database*/ |
|
65 | - protected $trapDB=null; |
|
64 | + /** @var Selectable $trapDB Trap Database*/ |
|
65 | + protected $trapDB=null; |
|
66 | 66 | |
67 | - /** @var Selectable $trapDB Icinga IDO database*/ |
|
68 | - protected $idoDB=null; |
|
67 | + /** @var Selectable $trapDB Icinga IDO database*/ |
|
68 | + protected $idoDB=null; |
|
69 | 69 | |
70 | - /** @var array $testResult */ |
|
71 | - protected $testResult; |
|
70 | + /** @var array $testResult */ |
|
71 | + protected $testResult; |
|
72 | 72 | |
73 | - /** |
|
74 | - * |
|
75 | - * @param TrapsController $trapCtrl |
|
76 | - */ |
|
77 | - function __construct(TrapsController $trapCtrl) |
|
78 | - { |
|
79 | - $this->trapController=$trapCtrl; |
|
80 | - } |
|
73 | + /** |
|
74 | + * |
|
75 | + * @param TrapsController $trapCtrl |
|
76 | + */ |
|
77 | + function __construct(TrapsController $trapCtrl) |
|
78 | + { |
|
79 | + $this->trapController=$trapCtrl; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get TrapsController instance |
|
84 | - * @return TrapsController |
|
85 | - */ |
|
86 | - protected function getTrapCtrl() |
|
87 | - { |
|
88 | - return $this->trapController; |
|
89 | - } |
|
82 | + /** |
|
83 | + * Get TrapsController instance |
|
84 | + * @return TrapsController |
|
85 | + */ |
|
86 | + protected function getTrapCtrl() |
|
87 | + { |
|
88 | + return $this->trapController; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Test if database version >= min database version |
|
93 | - * |
|
94 | - * @param \Zend_Db_Adapter_Abstract $dbConn |
|
95 | - * @param int $min Minimum version |
|
96 | - * @param bool $test Test mode |
|
97 | - * @param string $DBname Name of DB |
|
98 | - * @return bool true if OK, false if version < min version |
|
99 | - * @throws Exception if error and test = true |
|
100 | - */ |
|
101 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
102 | - { |
|
103 | - try |
|
104 | - { |
|
105 | - $query = $dbAdapter->select() |
|
106 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
107 | - ->where('name=\'db_version\''); |
|
108 | - $version=$dbAdapter->fetchRow($query); |
|
109 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
110 | - { |
|
111 | - if ($test === true) |
|
112 | - { |
|
113 | - $this->testResult = array(4,$DBname); |
|
114 | - return false; |
|
115 | - } |
|
116 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
117 | - return false; |
|
118 | - } |
|
119 | - if ($version->value < $min) |
|
120 | - { |
|
121 | - if ($test === true) |
|
122 | - { |
|
123 | - $this->testResult = array(5,$version->value,$min); |
|
124 | - return false; |
|
125 | - } |
|
126 | - $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
127 | - return false; |
|
128 | - } |
|
129 | - } |
|
130 | - catch (Exception $e) |
|
131 | - { |
|
132 | - if ($test === true) |
|
133 | - { |
|
134 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
135 | - return false; |
|
136 | - } |
|
137 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
138 | - return false; |
|
139 | - } |
|
140 | - return true; |
|
141 | - } |
|
91 | + /** |
|
92 | + * Test if database version >= min database version |
|
93 | + * |
|
94 | + * @param \Zend_Db_Adapter_Abstract $dbConn |
|
95 | + * @param int $min Minimum version |
|
96 | + * @param bool $test Test mode |
|
97 | + * @param string $DBname Name of DB |
|
98 | + * @return bool true if OK, false if version < min version |
|
99 | + * @throws Exception if error and test = true |
|
100 | + */ |
|
101 | + protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
102 | + { |
|
103 | + try |
|
104 | + { |
|
105 | + $query = $dbAdapter->select() |
|
106 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
107 | + ->where('name=\'db_version\''); |
|
108 | + $version=$dbAdapter->fetchRow($query); |
|
109 | + if ( ($version == null) || ! property_exists($version,'value') ) |
|
110 | + { |
|
111 | + if ($test === true) |
|
112 | + { |
|
113 | + $this->testResult = array(4,$DBname); |
|
114 | + return false; |
|
115 | + } |
|
116 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
117 | + return false; |
|
118 | + } |
|
119 | + if ($version->value < $min) |
|
120 | + { |
|
121 | + if ($test === true) |
|
122 | + { |
|
123 | + $this->testResult = array(5,$version->value,$min); |
|
124 | + return false; |
|
125 | + } |
|
126 | + $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
127 | + return false; |
|
128 | + } |
|
129 | + } |
|
130 | + catch (Exception $e) |
|
131 | + { |
|
132 | + if ($test === true) |
|
133 | + { |
|
134 | + $this->testResult = array(3,$DBname,$e->getMessage()); |
|
135 | + return false; |
|
136 | + } |
|
137 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
138 | + return false; |
|
139 | + } |
|
140 | + return true; |
|
141 | + } |
|
142 | 142 | |
143 | - /** Get Database connexion |
|
144 | - * @param $DBname string DB name in resource.ini_ge |
|
145 | - * @param $test bool if set to true, returns error code and not database |
|
146 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
147 | - * @throws DBException if test = true and error |
|
148 | - * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
149 | - */ |
|
150 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
151 | - { |
|
152 | - try |
|
153 | - { |
|
154 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
155 | - } |
|
156 | - catch (Exception $e) |
|
157 | - { |
|
158 | - if ($test === true) |
|
159 | - { |
|
160 | - throw new DBException(array(2,$DBname)); |
|
161 | - } |
|
162 | - $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
163 | - return null; |
|
164 | - } |
|
143 | + /** Get Database connexion |
|
144 | + * @param $DBname string DB name in resource.ini_ge |
|
145 | + * @param $test bool if set to true, returns error code and not database |
|
146 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
147 | + * @throws DBException if test = true and error |
|
148 | + * @return Selectable|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
149 | + */ |
|
150 | + protected function getDbByName($DBname , $test = false , $test_version = true) |
|
151 | + { |
|
152 | + try |
|
153 | + { |
|
154 | + $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
155 | + } |
|
156 | + catch (Exception $e) |
|
157 | + { |
|
158 | + if ($test === true) |
|
159 | + { |
|
160 | + throw new DBException(array(2,$DBname)); |
|
161 | + } |
|
162 | + $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
163 | + return null; |
|
164 | + } |
|
165 | 165 | |
166 | - try |
|
167 | - { |
|
168 | - $dbAdapter=$dbconn->getDbAdapter(); |
|
166 | + try |
|
167 | + { |
|
168 | + $dbAdapter=$dbconn->getDbAdapter(); |
|
169 | 169 | |
170 | - } |
|
171 | - catch (Exception $e) |
|
172 | - { |
|
173 | - if ($test === true) |
|
174 | - { |
|
175 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
176 | - } |
|
177 | - $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
178 | - return null; |
|
179 | - } |
|
170 | + } |
|
171 | + catch (Exception $e) |
|
172 | + { |
|
173 | + if ($test === true) |
|
174 | + { |
|
175 | + throw new DBException(array(3,$DBname,$e->getMessage())); |
|
176 | + } |
|
177 | + $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
178 | + return null; |
|
179 | + } |
|
180 | 180 | |
181 | - if ($test_version == true) { |
|
182 | - $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
183 | - if ($testRet !== true) |
|
184 | - { |
|
185 | - throw new DBException($this->testResult); |
|
186 | - } |
|
187 | - } |
|
181 | + if ($test_version == true) { |
|
182 | + $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
183 | + if ($testRet !== true) |
|
184 | + { |
|
185 | + throw new DBException($this->testResult); |
|
186 | + } |
|
187 | + } |
|
188 | 188 | |
189 | - return $dbconn; |
|
190 | - } |
|
189 | + return $dbconn; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Get Trap database |
|
194 | - * @return Selectable|null : returns DB connexion or null on error. |
|
195 | - */ |
|
196 | - public function getDb() |
|
197 | - { |
|
198 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
192 | + /** |
|
193 | + * Get Trap database |
|
194 | + * @return Selectable|null : returns DB connexion or null on error. |
|
195 | + */ |
|
196 | + public function getDb() |
|
197 | + { |
|
198 | + if ( $this->trapDB != null ) return $this->trapDB; |
|
199 | 199 | |
200 | 200 | |
201 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
201 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
202 | 202 | |
203 | - if ( ! $dbresource ) |
|
204 | - { |
|
205 | - $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
206 | - return null; |
|
207 | - } |
|
203 | + if ( ! $dbresource ) |
|
204 | + { |
|
205 | + $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
206 | + return null; |
|
207 | + } |
|
208 | 208 | |
209 | - try { |
|
210 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
211 | - } catch (DBException $e) { |
|
212 | - return null; // Should not happen as test = false |
|
213 | - } |
|
209 | + try { |
|
210 | + $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
211 | + } catch (DBException $e) { |
|
212 | + return null; // Should not happen as test = false |
|
213 | + } |
|
214 | 214 | |
215 | - //$this->trapDB->getConnection(); |
|
215 | + //$this->trapDB->getConnection(); |
|
216 | 216 | |
217 | - return $this->trapDB; |
|
218 | - } |
|
217 | + return $this->trapDB; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Get Zend adapter of DB. |
|
222 | - * @return \Zend_Db_Adapter_Abstract|null |
|
223 | - */ |
|
224 | - public function getDbConn() |
|
225 | - { |
|
226 | - if ($this->getDb() == null) return null; |
|
227 | - return $this->getDb()->getConnection(); |
|
228 | - } |
|
220 | + /** |
|
221 | + * Get Zend adapter of DB. |
|
222 | + * @return \Zend_Db_Adapter_Abstract|null |
|
223 | + */ |
|
224 | + public function getDbConn() |
|
225 | + { |
|
226 | + if ($this->getDb() == null) return null; |
|
227 | + return $this->getDb()->getConnection(); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Test Trap database |
|
232 | - * @param boolean $test |
|
233 | - * @throws DBException on error. |
|
234 | - * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
235 | - */ |
|
236 | - public function testGetDb() |
|
237 | - { |
|
238 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
230 | + /** |
|
231 | + * Test Trap database |
|
232 | + * @param boolean $test |
|
233 | + * @throws DBException on error. |
|
234 | + * @return \Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
235 | + */ |
|
236 | + public function testGetDb() |
|
237 | + { |
|
238 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
239 | 239 | |
240 | - if ( ! $dbresource ) |
|
241 | - { |
|
242 | - throw new DBException(array(1,'')); |
|
243 | - } |
|
240 | + if ( ! $dbresource ) |
|
241 | + { |
|
242 | + throw new DBException(array(1,'')); |
|
243 | + } |
|
244 | 244 | |
245 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
246 | - return; |
|
247 | - } |
|
245 | + $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
246 | + return; |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * Get IDO Database |
|
252 | - * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
253 | - */ |
|
254 | - public function getIdoDb() |
|
255 | - { |
|
256 | - if ( $this->idoDB != null ) return $this->idoDB; |
|
257 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
258 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
250 | + /** |
|
251 | + * Get IDO Database |
|
252 | + * @return \Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
253 | + */ |
|
254 | + public function getIdoDb() |
|
255 | + { |
|
256 | + if ( $this->idoDB != null ) return $this->idoDB; |
|
257 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
258 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
259 | 259 | |
260 | - if ( ! $dbresource ) |
|
261 | - { |
|
262 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
263 | - return null; |
|
264 | - } |
|
260 | + if ( ! $dbresource ) |
|
261 | + { |
|
262 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=1'); |
|
263 | + return null; |
|
264 | + } |
|
265 | 265 | |
266 | - try |
|
267 | - { |
|
268 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
269 | - } |
|
270 | - catch (Exception $e) |
|
271 | - { |
|
272 | - $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
273 | - return null; |
|
274 | - } |
|
266 | + try |
|
267 | + { |
|
268 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
269 | + } |
|
270 | + catch (Exception $e) |
|
271 | + { |
|
272 | + $this->trapController->redirectNow('trapdirector/settings?idodberror=2'); |
|
273 | + return null; |
|
274 | + } |
|
275 | 275 | |
276 | - $this->idoDB = $dbconn; |
|
277 | - return $this->idoDB; |
|
278 | - } |
|
276 | + $this->idoDB = $dbconn; |
|
277 | + return $this->idoDB; |
|
278 | + } |
|
279 | 279 | |
280 | 280 | |
281 | - /** |
|
282 | - * Get Zend adapter of DB. |
|
283 | - * @return \Zend_Db_Adapter_Abstract|null |
|
284 | - */ |
|
285 | - public function getIdoDbConn() |
|
286 | - { |
|
287 | - if ($this->getIdoDb() == null) return null; |
|
288 | - return $this->getIdoDb()->getConnection(); |
|
289 | - } |
|
281 | + /** |
|
282 | + * Get Zend adapter of DB. |
|
283 | + * @return \Zend_Db_Adapter_Abstract|null |
|
284 | + */ |
|
285 | + public function getIdoDbConn() |
|
286 | + { |
|
287 | + if ($this->getIdoDb() == null) return null; |
|
288 | + return $this->getIdoDb()->getConnection(); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Get IDO Database |
|
293 | - * @param boolean $test |
|
294 | - * @throws DBException on error |
|
295 | - */ |
|
296 | - public function testGetIdoDb() |
|
297 | - { |
|
298 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
299 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
291 | + /** |
|
292 | + * Get IDO Database |
|
293 | + * @param boolean $test |
|
294 | + * @throws DBException on error |
|
295 | + */ |
|
296 | + public function testGetIdoDb() |
|
297 | + { |
|
298 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
299 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
300 | 300 | |
301 | - if ( ! $dbresource ) |
|
302 | - { |
|
303 | - throw new DBException(array(1,'No database in config.ini')); |
|
304 | - } |
|
301 | + if ( ! $dbresource ) |
|
302 | + { |
|
303 | + throw new DBException(array(1,'No database in config.ini')); |
|
304 | + } |
|
305 | 305 | |
306 | - try |
|
307 | - { |
|
308 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
309 | - } |
|
310 | - catch (Exception $e) |
|
311 | - { |
|
312 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
313 | - } |
|
306 | + try |
|
307 | + { |
|
308 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
309 | + } |
|
310 | + catch (Exception $e) |
|
311 | + { |
|
312 | + throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
313 | + } |
|
314 | 314 | |
315 | - try |
|
316 | - { |
|
317 | - $query = $dbconn->select() |
|
318 | - ->from('icinga_dbversion',array('version')); |
|
319 | - $version=$dbconn->fetchRow($query); |
|
320 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
321 | - { |
|
322 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
323 | - } |
|
324 | - } |
|
325 | - catch (Exception $e) |
|
326 | - { |
|
327 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
328 | - } |
|
315 | + try |
|
316 | + { |
|
317 | + $query = $dbconn->select() |
|
318 | + ->from('icinga_dbversion',array('version')); |
|
319 | + $version=$dbconn->fetchRow($query); |
|
320 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
321 | + { |
|
322 | + throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
323 | + } |
|
324 | + } |
|
325 | + catch (Exception $e) |
|
326 | + { |
|
327 | + throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
328 | + } |
|
329 | 329 | |
330 | - return; |
|
331 | - } |
|
330 | + return; |
|
331 | + } |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | \ No newline at end of file |
@@ -18,247 +18,247 @@ |
||
18 | 18 | trait IdoDBQuery |
19 | 19 | { |
20 | 20 | |
21 | - /** @return TrapsController */ |
|
22 | - abstract protected function getTrapCtrl(); |
|
21 | + /** @return TrapsController */ |
|
22 | + abstract protected function getTrapCtrl(); |
|
23 | 23 | |
24 | - /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
25 | - abstract public function getIdoDbConn(); |
|
24 | + /** @return Zend_Db_Adapter_Abstract : returns DB connexion or null on error */ |
|
25 | + abstract public function getIdoDbConn(); |
|
26 | 26 | |
27 | - /** Get host(s) by IP (v4 or v6) or by name in IDO database |
|
28 | - * does not catch exceptions |
|
29 | - * @return array of objects ( name, id (object_id), display_name) |
|
30 | - */ |
|
31 | - public function getHostByIP($ip) |
|
32 | - { |
|
33 | - // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
34 | - $dbConn = $this->getIdoDbConn(); |
|
35 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
27 | + /** Get host(s) by IP (v4 or v6) or by name in IDO database |
|
28 | + * does not catch exceptions |
|
29 | + * @return array of objects ( name, id (object_id), display_name) |
|
30 | + */ |
|
31 | + public function getHostByIP($ip) |
|
32 | + { |
|
33 | + // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
34 | + $dbConn = $this->getIdoDbConn(); |
|
35 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
36 | 36 | |
37 | - // TODO : check for SQL injections |
|
38 | - $query=$dbConn->select() |
|
39 | - ->from( |
|
40 | - array('a' => 'icinga_objects'), |
|
41 | - array('name' => 'a.name1','id' => 'object_id')) |
|
42 | - ->join( |
|
43 | - array('b' => 'icinga_hosts'), |
|
44 | - 'b.host_object_id=a.object_id', |
|
45 | - array('display_name' => 'b.display_name')) |
|
46 | - ->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1"); |
|
47 | - return $dbConn->fetchAll($query); |
|
48 | - } |
|
37 | + // TODO : check for SQL injections |
|
38 | + $query=$dbConn->select() |
|
39 | + ->from( |
|
40 | + array('a' => 'icinga_objects'), |
|
41 | + array('name' => 'a.name1','id' => 'object_id')) |
|
42 | + ->join( |
|
43 | + array('b' => 'icinga_hosts'), |
|
44 | + 'b.host_object_id=a.object_id', |
|
45 | + array('display_name' => 'b.display_name')) |
|
46 | + ->where("(b.address LIKE '%".$ip."%' OR b.address6 LIKE '%".$ip."%' OR a.name1 LIKE '%".$ip."%' OR b.display_name LIKE '%".$ip."%') and a.is_active = 1"); |
|
47 | + return $dbConn->fetchAll($query); |
|
48 | + } |
|
49 | 49 | |
50 | - /** Get host(s) by name in IDO database |
|
51 | - * does not catch exceptions |
|
52 | - * @return array of objects ( name, id (object_id), display_name) |
|
53 | - */ |
|
54 | - public function getHostByName($name) |
|
55 | - { |
|
56 | - // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
57 | - $dbConn = $this->getIdoDbConn(); |
|
58 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
50 | + /** Get host(s) by name in IDO database |
|
51 | + * does not catch exceptions |
|
52 | + * @return array of objects ( name, id (object_id), display_name) |
|
53 | + */ |
|
54 | + public function getHostByName($name) |
|
55 | + { |
|
56 | + // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
57 | + $dbConn = $this->getIdoDbConn(); |
|
58 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
59 | 59 | |
60 | - // TODO : check for SQL injections |
|
61 | - $query=$dbConn->select() |
|
62 | - ->from( |
|
63 | - array('a' => 'icinga_objects'), |
|
64 | - array('name' => 'a.name1','id' => 'object_id')) |
|
65 | - ->join( |
|
66 | - array('b' => 'icinga_hosts'), |
|
67 | - 'b.host_object_id=a.object_id', |
|
68 | - array('display_name' => 'b.display_name')) |
|
69 | - ->where("a.name1 = '$name'"); |
|
70 | - return $dbConn->fetchAll($query); |
|
71 | - } |
|
60 | + // TODO : check for SQL injections |
|
61 | + $query=$dbConn->select() |
|
62 | + ->from( |
|
63 | + array('a' => 'icinga_objects'), |
|
64 | + array('name' => 'a.name1','id' => 'object_id')) |
|
65 | + ->join( |
|
66 | + array('b' => 'icinga_hosts'), |
|
67 | + 'b.host_object_id=a.object_id', |
|
68 | + array('display_name' => 'b.display_name')) |
|
69 | + ->where("a.name1 = '$name'"); |
|
70 | + return $dbConn->fetchAll($query); |
|
71 | + } |
|
72 | 72 | |
73 | - /** Get host groups by name in IDO database |
|
74 | - * does not catch exceptions |
|
75 | - * @return array of objects ( name, id (object_id), display_name) |
|
76 | - */ |
|
77 | - public function getHostGroupByName($ip) |
|
78 | - { |
|
79 | - // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
80 | - $dbConn = $this->getIdoDbConn(); |
|
81 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
82 | - // TODO : check for SQL injections |
|
83 | - $query=$dbConn->select() |
|
84 | - ->from( |
|
85 | - array('a' => 'icinga_objects'), |
|
86 | - array('name' => 'a.name1','id' => 'object_id')) |
|
87 | - ->join( |
|
88 | - array('b' => 'icinga_hostgroups'), |
|
89 | - 'b.hostgroup_object_id=a.object_id', |
|
90 | - array('display_name' => 'b.alias')) |
|
91 | - ->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1"); |
|
92 | - return $dbConn->fetchAll($query); |
|
93 | - } |
|
73 | + /** Get host groups by name in IDO database |
|
74 | + * does not catch exceptions |
|
75 | + * @return array of objects ( name, id (object_id), display_name) |
|
76 | + */ |
|
77 | + public function getHostGroupByName($ip) |
|
78 | + { |
|
79 | + // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
80 | + $dbConn = $this->getIdoDbConn(); |
|
81 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
82 | + // TODO : check for SQL injections |
|
83 | + $query=$dbConn->select() |
|
84 | + ->from( |
|
85 | + array('a' => 'icinga_objects'), |
|
86 | + array('name' => 'a.name1','id' => 'object_id')) |
|
87 | + ->join( |
|
88 | + array('b' => 'icinga_hostgroups'), |
|
89 | + 'b.hostgroup_object_id=a.object_id', |
|
90 | + array('display_name' => 'b.alias')) |
|
91 | + ->where("(a.name1 LIKE '%".$ip."%' OR b.alias LIKE '%".$ip."%') and a.is_active = 1"); |
|
92 | + return $dbConn->fetchAll($query); |
|
93 | + } |
|
94 | 94 | |
95 | - /** Get host IP (v4 and v6) by name in IDO database |
|
96 | - * does not catch exceptions |
|
97 | - * @return array ( name, display_name, ip4, ip6) |
|
98 | - */ |
|
99 | - public function getHostInfoByID($id) |
|
100 | - { |
|
101 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
102 | - $dbConn = $this->getIdoDbConn(); |
|
103 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
104 | - $query=$dbConn->select() |
|
105 | - ->from( |
|
106 | - array('a' => 'icinga_objects'), |
|
107 | - array('name' => 'a.name1')) |
|
108 | - ->join( |
|
109 | - array('b' => 'icinga_hosts'), |
|
110 | - 'b.host_object_id=a.object_id', |
|
111 | - array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name')) |
|
112 | - ->where("a.object_id = '".$id."'"); |
|
113 | - return $dbConn->fetchRow($query); |
|
114 | - } |
|
95 | + /** Get host IP (v4 and v6) by name in IDO database |
|
96 | + * does not catch exceptions |
|
97 | + * @return array ( name, display_name, ip4, ip6) |
|
98 | + */ |
|
99 | + public function getHostInfoByID($id) |
|
100 | + { |
|
101 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
102 | + $dbConn = $this->getIdoDbConn(); |
|
103 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
104 | + $query=$dbConn->select() |
|
105 | + ->from( |
|
106 | + array('a' => 'icinga_objects'), |
|
107 | + array('name' => 'a.name1')) |
|
108 | + ->join( |
|
109 | + array('b' => 'icinga_hosts'), |
|
110 | + 'b.host_object_id=a.object_id', |
|
111 | + array('ip4' => 'b.address', 'ip6' => 'b.address6', 'display_name' => 'b.display_name')) |
|
112 | + ->where("a.object_id = '".$id."'"); |
|
113 | + return $dbConn->fetchRow($query); |
|
114 | + } |
|
115 | 115 | |
116 | - /** Get host by objectid in IDO database |
|
117 | - * does not catch exceptions |
|
118 | - * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
119 | - */ |
|
120 | - public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
|
121 | - { |
|
122 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
123 | - $dbConn = $this->getIdoDbConn(); |
|
124 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
125 | - $query=$dbConn->select() |
|
126 | - ->from( |
|
127 | - array('a' => 'icinga_objects'), |
|
128 | - array('name' => 'a.name1','id' => 'a.object_id')) |
|
129 | - ->join( |
|
130 | - array('b' => 'icinga_hosts'), |
|
131 | - 'b.host_object_id=a.object_id', |
|
132 | - array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
133 | - ->where('a.object_id = ?',$id); |
|
134 | - return $dbConn->fetchRow($query); |
|
135 | - } |
|
116 | + /** Get host by objectid in IDO database |
|
117 | + * does not catch exceptions |
|
118 | + * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
119 | + */ |
|
120 | + public function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
|
121 | + { |
|
122 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
123 | + $dbConn = $this->getIdoDbConn(); |
|
124 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
125 | + $query=$dbConn->select() |
|
126 | + ->from( |
|
127 | + array('a' => 'icinga_objects'), |
|
128 | + array('name' => 'a.name1','id' => 'a.object_id')) |
|
129 | + ->join( |
|
130 | + array('b' => 'icinga_hosts'), |
|
131 | + 'b.host_object_id=a.object_id', |
|
132 | + array('display_name' => 'b.display_name' , 'ip' => 'b.address', 'ip6' => 'b.address6')) |
|
133 | + ->where('a.object_id = ?',$id); |
|
134 | + return $dbConn->fetchRow($query); |
|
135 | + } |
|
136 | 136 | |
137 | - /** Get services from object ( host_object_id) in IDO database |
|
138 | - * does not catch exceptions |
|
139 | - * @param $id int object_id |
|
140 | - * @return array display_name (of service), service_object_id |
|
141 | - */ |
|
142 | - public function getServicesByHostid($id) |
|
143 | - { |
|
144 | - // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
145 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
146 | - $dbConn = $this->getIdoDbConn(); |
|
147 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
148 | - $query=$dbConn->select() |
|
149 | - ->from( |
|
150 | - array('s' => 'icinga_services'), |
|
151 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
152 | - ->join( |
|
153 | - array('a' => 'icinga_objects'), |
|
154 | - 's.service_object_id=a.object_id', |
|
155 | - array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
156 | - ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
|
157 | - return $dbConn->fetchAll($query); |
|
158 | - } |
|
137 | + /** Get services from object ( host_object_id) in IDO database |
|
138 | + * does not catch exceptions |
|
139 | + * @param $id int object_id |
|
140 | + * @return array display_name (of service), service_object_id |
|
141 | + */ |
|
142 | + public function getServicesByHostid($id) |
|
143 | + { |
|
144 | + // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
145 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
146 | + $dbConn = $this->getIdoDbConn(); |
|
147 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
148 | + $query=$dbConn->select() |
|
149 | + ->from( |
|
150 | + array('s' => 'icinga_services'), |
|
151 | + array('name' => 's.display_name','id' => 's.service_object_id')) |
|
152 | + ->join( |
|
153 | + array('a' => 'icinga_objects'), |
|
154 | + 's.service_object_id=a.object_id', |
|
155 | + array('is_active'=>'a.is_active','name2'=>'a.name2')) |
|
156 | + ->where('s.host_object_id='.$id.' AND a.is_active = 1'); |
|
157 | + return $dbConn->fetchAll($query); |
|
158 | + } |
|
159 | 159 | |
160 | - /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
|
161 | - * gets all hosts in hostgroup and return common services |
|
162 | - * does not catch exceptions |
|
163 | - * @param $id int object_id |
|
164 | - * @return array display_name (of service), service_object_id |
|
165 | - */ |
|
166 | - public function getServicesByHostGroupid($id) |
|
167 | - { |
|
168 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
169 | - $dbConn = $this->getIdoDbConn(); |
|
170 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
171 | - $query=$dbConn->select() |
|
172 | - ->from( |
|
173 | - array('s' => 'icinga_hostgroup_members'), |
|
174 | - array('host_object_id' => 's.host_object_id')) |
|
175 | - ->join( |
|
176 | - array('a' => 'icinga_hostgroups'), |
|
177 | - 's.hostgroup_id=a.hostgroup_id', |
|
178 | - 'hostgroup_object_id') |
|
179 | - ->where('a.hostgroup_object_id='.$id); |
|
180 | - $hosts=$dbConn->fetchAll($query); |
|
181 | - $common_services=array(); |
|
182 | - $num_hosts=count($hosts); |
|
183 | - foreach ($hosts as $key => $host) |
|
184 | - { // For each host, get all services and add in common_services if not found or add counter |
|
185 | - $host_services=$this->getServicesByHostid($host->host_object_id); |
|
186 | - foreach($host_services as $service) |
|
187 | - { |
|
188 | - if (isset($common_services[$service->name2]['num'])) |
|
189 | - { |
|
190 | - $common_services[$service->name2]['num'] +=1; |
|
191 | - } |
|
192 | - else |
|
193 | - { |
|
194 | - $common_services[$service->name2]['num']=1; |
|
195 | - $common_services[$service->name2]['name']=$service->name; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - $result=array(); |
|
160 | + /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
|
161 | + * gets all hosts in hostgroup and return common services |
|
162 | + * does not catch exceptions |
|
163 | + * @param $id int object_id |
|
164 | + * @return array display_name (of service), service_object_id |
|
165 | + */ |
|
166 | + public function getServicesByHostGroupid($id) |
|
167 | + { |
|
168 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
169 | + $dbConn = $this->getIdoDbConn(); |
|
170 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
171 | + $query=$dbConn->select() |
|
172 | + ->from( |
|
173 | + array('s' => 'icinga_hostgroup_members'), |
|
174 | + array('host_object_id' => 's.host_object_id')) |
|
175 | + ->join( |
|
176 | + array('a' => 'icinga_hostgroups'), |
|
177 | + 's.hostgroup_id=a.hostgroup_id', |
|
178 | + 'hostgroup_object_id') |
|
179 | + ->where('a.hostgroup_object_id='.$id); |
|
180 | + $hosts=$dbConn->fetchAll($query); |
|
181 | + $common_services=array(); |
|
182 | + $num_hosts=count($hosts); |
|
183 | + foreach ($hosts as $key => $host) |
|
184 | + { // For each host, get all services and add in common_services if not found or add counter |
|
185 | + $host_services=$this->getServicesByHostid($host->host_object_id); |
|
186 | + foreach($host_services as $service) |
|
187 | + { |
|
188 | + if (isset($common_services[$service->name2]['num'])) |
|
189 | + { |
|
190 | + $common_services[$service->name2]['num'] +=1; |
|
191 | + } |
|
192 | + else |
|
193 | + { |
|
194 | + $common_services[$service->name2]['num']=1; |
|
195 | + $common_services[$service->name2]['name']=$service->name; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + $result=array(); |
|
200 | 200 | |
201 | - //print_r($common_services); |
|
202 | - foreach (array_keys($common_services) as $key) |
|
203 | - { |
|
204 | - if ($common_services[$key]['num'] == $num_hosts) |
|
205 | - { |
|
206 | - array_push($result,array($key,$common_services[$key]['name'])); |
|
207 | - } |
|
208 | - } |
|
201 | + //print_r($common_services); |
|
202 | + foreach (array_keys($common_services) as $key) |
|
203 | + { |
|
204 | + if ($common_services[$key]['num'] == $num_hosts) |
|
205 | + { |
|
206 | + array_push($result,array($key,$common_services[$key]['name'])); |
|
207 | + } |
|
208 | + } |
|
209 | 209 | |
210 | - return $result; |
|
211 | - } |
|
210 | + return $result; |
|
211 | + } |
|
212 | 212 | |
213 | - /** Get services object id by host name / service name in IDO database |
|
214 | - * does not catch exceptions |
|
215 | - * @param $hostname string host name |
|
216 | - * @param $name string service name |
|
217 | - * @return array service id |
|
218 | - */ |
|
219 | - public function getServiceIDByName($hostname,$name) |
|
220 | - { |
|
221 | - $dbConn = $this->getIdoDbConn(); |
|
222 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
213 | + /** Get services object id by host name / service name in IDO database |
|
214 | + * does not catch exceptions |
|
215 | + * @param $hostname string host name |
|
216 | + * @param $name string service name |
|
217 | + * @return array service id |
|
218 | + */ |
|
219 | + public function getServiceIDByName($hostname,$name) |
|
220 | + { |
|
221 | + $dbConn = $this->getIdoDbConn(); |
|
222 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
223 | 223 | |
224 | - if ($name == null) |
|
225 | - { |
|
226 | - return array(); |
|
227 | - } |
|
224 | + if ($name == null) |
|
225 | + { |
|
226 | + return array(); |
|
227 | + } |
|
228 | 228 | |
229 | - $query=$dbConn->select() |
|
230 | - ->from( |
|
231 | - array('s' => 'icinga_services'), |
|
232 | - array('name' => 's.display_name','id' => 's.service_object_id')) |
|
233 | - ->join( |
|
234 | - array('a' => 'icinga_objects'), |
|
235 | - 's.service_object_id=a.object_id', |
|
236 | - 'is_active') |
|
237 | - ->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1'); |
|
229 | + $query=$dbConn->select() |
|
230 | + ->from( |
|
231 | + array('s' => 'icinga_services'), |
|
232 | + array('name' => 's.display_name','id' => 's.service_object_id')) |
|
233 | + ->join( |
|
234 | + array('a' => 'icinga_objects'), |
|
235 | + 's.service_object_id=a.object_id', |
|
236 | + 'is_active') |
|
237 | + ->where('a.name2=\''.$name.'\' AND a.name1=\''.$hostname.'\' AND a.is_active = 1'); |
|
238 | 238 | |
239 | - return $dbConn->fetchAll($query); |
|
240 | - } |
|
239 | + return $dbConn->fetchAll($query); |
|
240 | + } |
|
241 | 241 | |
242 | - /** Get object name from object_id in IDO database |
|
243 | - * does not catch exceptions |
|
244 | - * @param int $id object_id (default to null, used first if not null) |
|
245 | - * @return array name1 (host) name2 (service) |
|
246 | - */ |
|
247 | - public function getObjectNameByid($id) |
|
248 | - { |
|
249 | - // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
250 | - if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
251 | - $dbConn = $this->getIdoDbConn(); |
|
252 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
242 | + /** Get object name from object_id in IDO database |
|
243 | + * does not catch exceptions |
|
244 | + * @param int $id object_id (default to null, used first if not null) |
|
245 | + * @return array name1 (host) name2 (service) |
|
246 | + */ |
|
247 | + public function getObjectNameByid($id) |
|
248 | + { |
|
249 | + // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
|
250 | + if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
|
251 | + $dbConn = $this->getIdoDbConn(); |
|
252 | + if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
253 | 253 | |
254 | - $query=$dbConn->select() |
|
255 | - ->from( |
|
256 | - array('a' => 'icinga_objects'), |
|
257 | - array('name1' => 'a.name1','name2' => 'a.name2')) |
|
258 | - ->where('a.object_id='.$id.' AND a.is_active = 1'); |
|
254 | + $query=$dbConn->select() |
|
255 | + ->from( |
|
256 | + array('a' => 'icinga_objects'), |
|
257 | + array('name1' => 'a.name1','name2' => 'a.name2')) |
|
258 | + ->where('a.object_id='.$id.' AND a.is_active = 1'); |
|
259 | 259 | |
260 | - return $dbConn->fetchRow($query); |
|
261 | - } |
|
260 | + return $dbConn->fetchRow($query); |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | 264 | } |
265 | 265 | \ No newline at end of file |