glpi / src / plugins / vigilo / Vigilo / VigiloTest.php @ b58488b5
History | View | Annotate | Download (3.73 KB)
1 | 166be9d2 | Francois POIROTTE | <?php
|
---|---|---|---|
2 | |||
3 | class VigiloTest extends VigiloXml implements ArrayAccess |
||
4 | { |
||
5 | protected $name; |
||
6 | protected $args; |
||
7 | |||
8 | public function __construct($name, array $args = array()) |
||
9 | { |
||
10 | $this->name = $name; |
||
11 | $this->args = array(); |
||
12 | |||
13 | cdde5484 | Francois POIROTTE | foreach ($args as $arg => $value) { |
14 | $this[$arg] = $value; |
||
15 | 166be9d2 | Francois POIROTTE | } |
16 | } |
||
17 | 92b19eed | Francois POIROTTE | |
18 | public function getNagiosNames() |
||
19 | { |
||
20 | $res = array(); |
||
21 | 8d255750 | Francois POIROTTE | switch ($this->name) { |
22 | case 'Interface': |
||
23 | // Pour une interface réseau, le service est construit
|
||
24 | // à partir du label donné.
|
||
25 | $label = $this->args['label']->getValue(); |
||
26 | $res[] = "Interface $label"; |
||
27 | |||
28 | // On regarde si des seuils ont été définis ou non.
|
||
29 | // Si c'est le cas, cela génère des services supplémentaires.
|
||
30 | $warn = isset($this->args['warn']) ? $this->args['warn'] : array(); |
||
31 | $crit = isset($this->args['crit']) ? $this->args['crit'] : array(); |
||
32 | $tests = array( |
||
33 | "Traffic in",
|
||
34 | "Traffic out",
|
||
35 | "Discards in",
|
||
36 | "Discards out",
|
||
37 | "Errors in",
|
||
38 | "Errors out",
|
||
39 | ); |
||
40 | if (is_array($warn) && is_array($crit)) { |
||
41 | foreach ($tests as $i => $test) { |
||
42 | if (isset($warn[$i], $crit[$i])) { |
||
43 | $res[] = "$test $label"; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | break;
|
||
48 | |||
49 | case 'Partition': |
||
50 | // Le label est utilisé pour construire le nom du service.
|
||
51 | $label = $this->args['label']->getValue(); |
||
52 | $res[] = "Partition $label"; |
||
53 | break;
|
||
54 | |||
55 | case 'Ping': |
||
56 | $res[] = 'Ping'; |
||
57 | break;
|
||
58 | |||
59 | case 'Process': |
||
60 | $label = $this['label']; |
||
61 | if (null === $label) { |
||
62 | $label = $this->args['processname']; |
||
63 | } |
||
64 | $label = $label->getValue(); |
||
65 | $res[] = "Process $label"; |
||
66 | break;
|
||
67 | |||
68 | case 'Service': |
||
69 | $label = $this['label']; |
||
70 | if (null === $label) { |
||
71 | $label = $this->args['svcname']; |
||
72 | } |
||
73 | $res[] = $label->getValue(); |
||
74 | break;
|
||
75 | |||
76 | case 'TCP': |
||
77 | $label = $this['label']; |
||
78 | if (null === $label) { |
||
79 | $label = 'TCP ' . $this->args['port']->getValue(); |
||
80 | } else {
|
||
81 | $label = $label->getValue(); |
||
82 | } |
||
83 | $res[] = $label; |
||
84 | break;
|
||
85 | } |
||
86 | 92b19eed | Francois POIROTTE | |
87 | return $res; |
||
88 | } |
||
89 | 166be9d2 | Francois POIROTTE | |
90 | public function offsetExists($offset) |
||
91 | { |
||
92 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
93 | return isset($this->args[$name]); |
||
94 | } |
||
95 | |||
96 | public function offsetGet($offset) |
||
97 | { |
||
98 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
99 | return isset($this->args[$name]) ? $this->args[$name] : null; |
||
100 | } |
||
101 | |||
102 | public function offsetSet($offset, $value) |
||
103 | { |
||
104 | if (is_string($offset)) { |
||
105 | $value = new VigiloArg($offset, $value); |
||
106 | } |
||
107 | |||
108 | if (!is_a($value, 'VigiloArg')) { |
||
109 | throw new \RuntimeException(); |
||
110 | } |
||
111 | |||
112 | return $this->args[$value->getName()] = $value; |
||
113 | } |
||
114 | |||
115 | public function offsetUnset($offset) |
||
116 | { |
||
117 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
118 | unset($this->args[$name]); |
||
119 | } |
||
120 | |||
121 | public function __toString() |
||
122 | { |
||
123 | return self::sprintf( |
||
124 | '<test name="%s">%s</test>',
|
||
125 | $this->name,
|
||
126 | $this->args
|
||
127 | ); |
||
128 | } |
||
129 | } |