1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22class API { 23 24 /** 25 * API wrapper that all of the calls will go through. 26 * 27 * @var CApiWrapper 28 */ 29 private static $wrapper; 30 31 /** 32 * Factory for creating API services. 33 * 34 * @var CRegistryFactory 35 */ 36 private static $apiServiceFactory; 37 38 /** 39 * Sets the API wrapper. 40 * 41 * @param CApiWrapper $wrapper 42 */ 43 public static function setWrapper(CApiWrapper $wrapper = null) { 44 self::$wrapper = $wrapper; 45 } 46 47 /** 48 * Set the service factory. 49 * 50 * @param CRegistryFactory $factory 51 */ 52 public static function setApiServiceFactory(CRegistryFactory $factory) { 53 self::$apiServiceFactory = $factory; 54 } 55 56 /** 57 * Returns the API wrapper. 58 * 59 * @return CApiWrapper 60 */ 61 public static function getWrapper() { 62 return self::$wrapper; 63 } 64 65 /** 66 * Returns an object that can be used for making API calls. If a wrapper is used, returns a CApiWrapper, 67 * otherwise - returns a CApiService object. 68 * 69 * @param $name 70 * 71 * @return CApiWrapper|CApiService 72 */ 73 public static function getApi($name) { 74 if (self::$wrapper) { 75 self::$wrapper->api = $name; 76 77 return self::$wrapper; 78 } 79 else { 80 return self::getApiService($name); 81 } 82 } 83 84 /** 85 * Returns the CApiInstance object for the requested API. 86 * 87 * NOTE: This method must only be called from other CApiService objects. 88 * 89 * @param string $name 90 * 91 * @return CApiService 92 */ 93 public static function getApiService($name = null) { 94 return self::$apiServiceFactory->getObject($name ? $name : 'api'); 95 } 96 97 /** 98 * @return CAction 99 */ 100 public static function Action() { 101 return self::getApi('action'); 102 } 103 104 /** 105 * @return CAlert 106 */ 107 public static function Alert() { 108 return self::getApi('alert'); 109 } 110 111 /** 112 * @return CAPIInfo 113 */ 114 public static function APIInfo() { 115 return self::getApi('apiinfo'); 116 } 117 118 /** 119 * @return CApplication 120 */ 121 public static function Application() { 122 return self::getApi('application'); 123 } 124 125 /** 126 * @return CAuditLog 127 */ 128 public static function AuditLog() { 129 return self::getApi('auditlog'); 130 } 131 132 /** 133 * @return CAutoregistration 134 */ 135 public static function Autoregistration() { 136 return self::getApi('autoregistration'); 137 } 138 139 /** 140 * @return CConfiguration 141 */ 142 public static function Configuration() { 143 return self::getApi('configuration'); 144 } 145 146 /** 147 * @return CCorrelation 148 */ 149 public static function Correlation() { 150 return self::getApi('correlation'); 151 } 152 153 /** 154 * @return CDashboard 155 */ 156 public static function Dashboard() { 157 return self::getApi('dashboard'); 158 } 159 160 /** 161 * @return CDCheck 162 */ 163 public static function DCheck() { 164 return self::getApi('dcheck'); 165 } 166 167 /** 168 * @return CDHost 169 */ 170 public static function DHost() { 171 return self::getApi('dhost'); 172 } 173 174 /** 175 * @return CDiscoveryRule 176 */ 177 public static function DiscoveryRule() { 178 return self::getApi('discoveryrule'); 179 } 180 181 /** 182 * @return CDRule 183 */ 184 public static function DRule() { 185 return self::getApi('drule'); 186 } 187 188 /** 189 * @return CDService 190 */ 191 public static function DService() { 192 return self::getApi('dservice'); 193 } 194 195 /** 196 * @return CEvent 197 */ 198 public static function Event() { 199 return self::getApi('event'); 200 } 201 202 /** 203 * @return CGraph 204 */ 205 public static function Graph() { 206 return self::getApi('graph'); 207 } 208 209 /** 210 * @return CGraphItem 211 */ 212 public static function GraphItem() { 213 return self::getApi('graphitem'); 214 } 215 216 /** 217 * @return CGraphPrototype 218 */ 219 public static function GraphPrototype() { 220 return self::getApi('graphprototype'); 221 } 222 223 /** 224 * @return CHistory 225 */ 226 public static function History() { 227 return self::getApi('history'); 228 } 229 230 /** 231 * @return CHost 232 */ 233 public static function Host() { 234 return self::getApi('host'); 235 } 236 237 /** 238 * @return CHostPrototype 239 */ 240 public static function HostPrototype() { 241 return self::getApi('hostprototype'); 242 } 243 244 /** 245 * @return CHostGroup 246 */ 247 public static function HostGroup() { 248 return self::getApi('hostgroup'); 249 } 250 251 /** 252 * @return CHostInterface 253 */ 254 public static function HostInterface() { 255 return self::getApi('hostinterface'); 256 } 257 258 /** 259 * @return CImage 260 */ 261 public static function Image() { 262 return self::getApi('image'); 263 } 264 265 /** 266 * @return CIconMap 267 */ 268 public static function IconMap() { 269 return self::getApi('iconmap'); 270 } 271 272 /** 273 * @return CItem 274 */ 275 public static function Item() { 276 return self::getApi('item'); 277 } 278 279 /** 280 * @return CItemPrototype 281 */ 282 public static function ItemPrototype() { 283 return self::getApi('itemprototype'); 284 } 285 286 /** 287 * @return CMaintenance 288 */ 289 public static function Maintenance() { 290 return self::getApi('maintenance'); 291 } 292 293 /** 294 * @return CModule 295 */ 296 public static function Module() { 297 return self::getApi('module'); 298 } 299 300 /** 301 * @return CMap 302 */ 303 public static function Map() { 304 return self::getApi('map'); 305 } 306 307 /** 308 * @return CMediaType 309 */ 310 public static function MediaType() { 311 return self::getApi('mediatype'); 312 } 313 314 /** 315 * @return CProblem 316 */ 317 public static function Problem() { 318 return self::getApi('problem'); 319 } 320 321 /** 322 * @return CProxy 323 */ 324 public static function Proxy() { 325 return self::getApi('proxy'); 326 } 327 328 /** 329 * @return CService 330 */ 331 public static function Service() { 332 return self::getApi('service'); 333 } 334 335 /** 336 * @return CScreen 337 */ 338 public static function Screen() { 339 return self::getApi('screen'); 340 } 341 342 /** 343 * @return CScreenItem 344 */ 345 public static function ScreenItem() { 346 return self::getApi('screenitem'); 347 } 348 349 /** 350 * @return CScript 351 */ 352 public static function Script() { 353 return self::getApi('script'); 354 } 355 356 /** 357 * @return CTask 358 */ 359 public static function Task() { 360 return self::getApi('task'); 361 } 362 363 /** 364 * @return CTemplate 365 */ 366 public static function Template() { 367 return self::getApi('template'); 368 } 369 370 /** 371 * @return CTemplateScreen 372 */ 373 public static function TemplateScreen() { 374 return self::getApi('templatescreen'); 375 } 376 377 /** 378 * @return CTemplateScreenItem 379 */ 380 public static function TemplateScreenItem() { 381 return self::getApi('templatescreenitem'); 382 } 383 384 /** 385 * @return CTrend 386 */ 387 public static function Trend() { 388 return self::getApi('trend'); 389 } 390 391 /** 392 * @return CTrigger 393 */ 394 public static function Trigger() { 395 return self::getApi('trigger'); 396 } 397 398 /** 399 * @return CTriggerPrototype 400 */ 401 public static function TriggerPrototype() { 402 return self::getApi('triggerprototype'); 403 } 404 405 /** 406 * @return CUser 407 */ 408 public static function User() { 409 return self::getApi('user'); 410 } 411 412 /** 413 * @return CUserGroup 414 */ 415 public static function UserGroup() { 416 return self::getApi('usergroup'); 417 } 418 419 /** 420 * @return CUserMacro 421 */ 422 public static function UserMacro() { 423 return self::getApi('usermacro'); 424 } 425 426 /** 427 * @return CValueMap 428 */ 429 public static function ValueMap() { 430 return self::getApi('valuemap'); 431 } 432 433 /** 434 * @return CHttpTest 435 */ 436 public static function HttpTest() { 437 return self::getApi('httptest'); 438 } 439} 440