File: IcingaApiConnectionLivestatus.php

package info (click to toggle)
icinga 1.0.2-2%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 33,952 kB
  • ctags: 13,294
  • sloc: xml: 154,821; ansic: 99,198; sh: 14,585; sql: 5,852; php: 5,126; perl: 2,838; makefile: 1,268
file content (127 lines) | stat: -rw-r--r-- 3,286 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php

/**
 * 
 * @author Christian Doebler <christian.doebler@netways.de>
 *
 */
class IcingaApiConnectionLivestatus extends IcingaApiConnection {

	/*
	 * VARIABLES
	 */

	

	/*
	 * METHODS
	 */

	/**
	 * class constructor
	 *
	 * @param	void
	 * @return	void
	 * @author	Christian Doebler <christian.doebler@netways.de>
	 */
	public function __construct () {}

	/**
	 * checks whether config is OK
	 *
	 * @param	array		$config				associative array storing configuration
	 * @return	boolean							true if configuration is OK, false on error(s)
	 * @author	Christian Doebler <christian.doebler@netways.de>
	 */
	public function checkConfig (array $config) {
		$configOk = true;

		// check socket type
		if (array_key_exists('type', $config)) {
			if ($config['type'] != 'unix' && $config['type'] != 'tcp') {
				throw new IcingaApiConnectionLivestatusException('Configuration error: unknown livestatus socket type "' . $config['type'] . '" found!');
				$configOk = false;
			}
		} else {
			throw new IcingaApiConnectionLivestatusException('Configuration error: no setting for livestatus socket type found!');
			$configOk = false;
		}

		// check socket
		if ($configOk) {
			switch ($config['type']) {
				case 'unix':
					if (!array_key_exists('path', $config)) {
						throw new IcingaApiConnectionLivestatusException('Configuration error: no setting for livestatus socket path found!');
						$configOk = false;
					}
					break;
				case 'tcp':
					if (!array_key_exists('host', $config)) {
						throw new IcingaApiConnectionLivestatusException('Configuration error: no setting for livestatus socket host found!');
						$configOk = false;
					}
					if (!array_key_exists('port', $config)) {
						throw new IcingaApiConnectionLivestatusException('Configuration error: no setting for livestatus socket port found!');
						$configOk = false;
					}
					break;
			}
		}

		// perform global checks
		$configOkParent = parent::checkConfig($config);
		if (!$configOkParent && $configOk) {
			$configOk = false;
		}

		return $configOk;
	}

	/**
	 * triggers config check and puts config into right place
	 * @param	array		$config				associative array storing configuration
	 * @return	boolean							true on success otherwise false
	 * @author	Christian Doebler <christian.doebler@netways.de>
	 */
	public function setConfig (array $config) {
		if (!$this->checkConfig($config)) {
			return false;
		}
		$this->config = $config;
		return $this;
	}

	/**
	 * right now just a dummy
	 * @param	void
	 * @return	void
	 * @author	Christian Doebler <christian.doebler@netways.de>
	 */
	public function connect () {
		return $this;
	}

	/**
	 * calls initialization method for new search
	 *
	 * @param	void
	 * @return	IcingaApiSearchFile				search object
	 * @author	Christian Doebler <christian.doebler@netways.de>
	 */
	public function createSearch () {
		$class = 'IcingaApiSearch' . $this->icingaType;
		$searchObject = new $class;
		$searchObject->setDebug($this->debug);
		$searchObject->setConfig($this->config);
		$searchObject->loadInterfaceClass($this->icingaType, 'socket');
//		$searchObject->loadColumns($this->icingaType);
		return $searchObject;
	}

}

// extend exceptions
class IcingaApiConnectionLivestatusException extends IcingaApiConnectionException {}

?>