Revision 92b19eed
Génération de HLS par machine
Crée automatiquement les HLS "services:$host" qui dépend de tous les
services de $host et "machine:$host" qui dépend de l'état de $host
et de ses services.
Pour le moment, les HLS construits ont des dépendances +/- vides car il
manque encore la reconnaissance des tests pour déterminer le nom des
services associés (cf. getNagiosNames() dans VigiloTest).
Change-Id: I558f7d96997c5c520f26daef1157c8de0a790f96
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2399
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Makefile | ||
---|---|---|
12 | 12 |
mkdir -p $(DESTDIR)$(DATADIR)/$(NAME)/plugins/ |
13 | 13 |
mkdir -p $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/groups/managed |
14 | 14 |
mkdir -p $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hosts/managed |
15 |
mkdir -p $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hlservices/managed |
|
15 | 16 |
cp -pr src/plugins/vigilo $(DESTDIR)$(DATADIR)/$(NAME)/plugins/ |
16 | 17 |
|
17 | 18 |
install_data: pkg/init pkg/sudoers |
... | ... | |
24 | 25 |
chown root:root $(DESTDIR)$(SYSCONFDIR)/sudoers.d/$(PKGNAME) |
25 | 26 |
chown vigiconf:apache $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/groups/managed |
26 | 27 |
chown vigiconf:apache $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hosts/managed |
28 |
chown vigiconf:apache $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hlservices/managed |
|
27 | 29 |
chmod 0770 $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/groups/managed |
28 | 30 |
chown 0770 $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hosts/managed |
31 |
chown 0770 $(DESTDIR)$(SYSCONFDIR)/vigilo/vigiconf/conf.d/hlservices/managed |
|
29 | 32 |
|
30 | 33 |
clean: clean_common |
31 | 34 |
|
pkg/glpi.redhat.spec | ||
---|---|---|
55 | 55 |
%defattr(644,vigiconf,apache,770) |
56 | 56 |
%dir %{vigiconf_confdir}/groups/managed/ |
57 | 57 |
%dir %{vigiconf_confdir}/hosts/managed/ |
58 |
%dir %{vigiconf_confdir}/hlservices/managed/ |
|
58 | 59 |
%attr(755,root,root) %{_initrddir}/%{name} |
59 | 60 |
|
60 | 61 |
%changelog |
src/plugins/vigilo/Vigilo/VigiloDepends.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class VigiloDepends extends VigiloXml |
|
4 |
{ |
|
5 |
protected $host; |
|
6 |
protected $service; |
|
7 |
|
|
8 |
public function __construct($host = null, $service = null) |
|
9 |
{ |
|
10 |
if (null === $host && null === $service) { |
|
11 |
throw new Exception('Invalid dependency'); |
|
12 |
} |
|
13 |
|
|
14 |
if ('' === $host || '' === $service || !is_string($host) || !is_string($service)) { |
|
15 |
throw new Exception('Invalid dependency'); |
|
16 |
} |
|
17 |
|
|
18 |
$this->host = $host; |
|
19 |
$this->service = $service; |
|
20 |
} |
|
21 |
|
|
22 |
public function __toString() |
|
23 |
{ |
|
24 |
if (null === $this->host) { |
|
25 |
return "<depends service=\"{$this->service}\"/>"; |
|
26 |
} |
|
27 |
|
|
28 |
if (null === $this->service) { |
|
29 |
return "<depends host=\"{$this->host}\"/>"; |
|
30 |
} |
|
31 |
|
|
32 |
return "<depends host=\"{$this->host}\" service=\"{$this->service}\"/>"; |
|
33 |
} |
|
34 |
} |
src/plugins/vigilo/Vigilo/VigiloHlservice.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class VigiloHlservice extends VigiloXml implements ArrayAccess |
|
4 |
{ |
|
5 |
protected $name; |
|
6 |
protected $message; |
|
7 |
protected $priorities; |
|
8 |
protected $dependencies; |
|
9 |
|
|
10 |
const OPERATOR_AND = "and"; |
|
11 |
const OPERATOR_OR = "or"; |
|
12 |
const OPERATOR_PLUS = "plus"; |
|
13 |
|
|
14 |
const STATE_WARNING = 1; |
|
15 |
const STATE_CRITICAL = 2; |
|
16 |
const STATE_UNKNOWN = 3; |
|
17 |
|
|
18 |
public function __construct($name, $operator, $message, $warnThreshold = 0, $critThreshold = 0) |
|
19 |
{ |
|
20 |
if (!in_array($operator, array(self::OP_AND, self::OP_OR, self::OP_PLUS))) { |
|
21 |
throw new Exception('Invalid operator'); |
|
22 |
} |
|
23 |
|
|
24 |
$this->name = $name; |
|
25 |
$this->message = $message; |
|
26 |
$this->operator = $operator; |
|
27 |
$this->warnThreshold = (int) $warnThreshold; |
|
28 |
$this->critThreshold = (int) $critThreshold; |
|
29 |
$this->priorities = array(); |
|
30 |
$this->dependencies = array(); |
|
31 |
} |
|
32 |
|
|
33 |
public function getName() |
|
34 |
{ |
|
35 |
return $this->name; |
|
36 |
} |
|
37 |
|
|
38 |
public function setPriority($state, $priority) |
|
39 |
{ |
|
40 |
if (!in_array($priority, array(self::STATE_WARNING, self::STATE_CRITICAL, self::STATE_UNKNOWN))) { |
|
41 |
throw new Exception('Invalid state'); |
|
42 |
} |
|
43 |
|
|
44 |
$this->priorities[$state] = (int) $priority; |
|
45 |
} |
|
46 |
|
|
47 |
public function setWarningThreshold($threshold) |
|
48 |
{ |
|
49 |
$this->warnThreshold = (int) $threshold; |
|
50 |
} |
|
51 |
|
|
52 |
public function setCriticalThreshold($threshold) |
|
53 |
{ |
|
54 |
$this->critThreshold = (int) $threshold; |
|
55 |
} |
|
56 |
|
|
57 |
public function offsetExists($offset) |
|
58 |
{ |
|
59 |
return isset($this->dependencies[$offset]); |
|
60 |
} |
|
61 |
|
|
62 |
public function offsetGet($offset) |
|
63 |
{ |
|
64 |
return isset($this->dependencies[$offset]) ? $this->dependencies[$offset] : null; |
|
65 |
} |
|
66 |
|
|
67 |
public function offsetSet($offset, $value) |
|
68 |
{ |
|
69 |
if (!is_object($value) || !($value instanceof VigiloDepends)) { |
|
70 |
throw new \RuntimeException("Invalid dependency"); |
|
71 |
} |
|
72 |
$this->dependencies[$offset] = $value; |
|
73 |
} |
|
74 |
|
|
75 |
public function offsetUnset($offset) |
|
76 |
{ |
|
77 |
unset($this->dependencies[$offset]); |
|
78 |
} |
|
79 |
|
|
80 |
public function __toString() |
|
81 |
{ |
|
82 |
$priorities = array(); |
|
83 |
$map = array( |
|
84 |
"unknown" => self::STATE_UNKNOWN, |
|
85 |
"warning" => self::STATE_WARNING, |
|
86 |
"critical" => self::STATE_CRITICAL, |
|
87 |
); |
|
88 |
|
|
89 |
foreach ($map as $name => $id) { |
|
90 |
if (isset($this->priorities[$id])) { |
|
91 |
$value = $this->priorities[$id]; |
|
92 |
$priorities[] = "<${name}_priority>$value</${name}_priority>"; |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
$xml = <<<HLS |
|
97 |
<hlservice> |
|
98 |
<message>%s</message> |
|
99 |
<warning_threshold>%d</warning_threshold> |
|
100 |
<critical_threshold>%d</critical_threshold> |
|
101 |
%s |
|
102 |
<operator>%s</operator> |
|
103 |
%s |
|
104 |
</hlservice> |
|
105 |
HLS; |
|
106 |
return self::sprintf( |
|
107 |
$xml, |
|
108 |
$this->message, |
|
109 |
$this->warnThreshold, |
|
110 |
$this->critThreshold, |
|
111 |
$priorities, |
|
112 |
$this->operator, |
|
113 |
$this->dependencies |
|
114 |
); |
|
115 |
} |
|
116 |
} |
src/plugins/vigilo/Vigilo/VigiloTest.php | ||
---|---|---|
15 | 15 |
} |
16 | 16 |
} |
17 | 17 |
|
18 |
public function getNagiosNames() |
|
19 |
{ |
|
20 |
$res = array(); |
|
21 |
|
|
22 |
return $res; |
|
23 |
} |
|
24 |
|
|
18 | 25 |
public function offsetExists($offset) |
19 | 26 |
{ |
20 | 27 |
$name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
src/plugins/vigilo/inc/abstractmonitoreditem.class.php | ||
---|---|---|
33 | 33 |
return $this->item->getName(); |
34 | 34 |
} |
35 | 35 |
|
36 |
protected function filterTests($value) |
|
37 |
{ |
|
38 |
return is_object($value) && ($value instanceof VigiloTest); |
|
39 |
} |
|
40 |
|
|
41 |
public function getTests() |
|
42 |
{ |
|
43 |
return new CallbackFilterIterator( |
|
44 |
new ArrayIterator($this->children), |
|
45 |
array($this, 'filterTests') |
|
46 |
); |
|
47 |
} |
|
48 |
|
|
36 | 49 |
protected function selectTemplates() |
37 | 50 |
{ |
38 | 51 |
$template = $this->item->fields['vigilo_template']; |
... | ... | |
164 | 177 |
|
165 | 178 |
public function __toString() |
166 | 179 |
{ |
167 |
$outXML = new DOMDocument(); |
|
168 |
$outXML->preserveWhiteSpace = false; |
|
169 |
$outXML->formatOutput = true; |
|
170 |
$outXML->loadXML( |
|
171 |
self::sprintf( |
|
172 |
'<?xml version="1.0"?>' . |
|
173 |
'<host name="%s" address="%s" ventilation="%s">%s</host>', |
|
174 |
$this->item->getName(), |
|
175 |
$this->selectAddress(), |
|
176 |
"Servers", |
|
177 |
$this->children |
|
178 |
) |
|
180 |
return self::sprintf( |
|
181 |
'<?xml version="1.0"?>' . |
|
182 |
'<host name="%s" address="%s" ventilation="%s">%s</host>', |
|
183 |
$this->item->getName(), |
|
184 |
$this->selectAddress(), |
|
185 |
"Servers", |
|
186 |
$this->children |
|
179 | 187 |
); |
180 |
return $outXML->saveXML(); |
|
181 | 188 |
} |
182 | 189 |
} |
src/plugins/vigilo/inc/hls.class.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class PluginVigiloAbstractMonitoredItem extends VigiloXml |
|
4 |
{ |
|
5 |
protected $name; |
|
6 |
protected $hlsHost; |
|
7 |
protected $hlsServices; |
|
8 |
|
|
9 |
const MESSAGE = "%(state)s: %(active_deps)r/%(total_deps)r active deps"; |
|
10 |
|
|
11 |
public function __construct(PluginVigiloAbstractMonitoredItem $host) |
|
12 |
{ |
|
13 |
$name = $host->getName(); |
|
14 |
|
|
15 |
// Création d'un HLS qui dépend de tous les services de l'hôte. |
|
16 |
$this->hlsServices = new VigiloHlservice( |
|
17 |
"services:$name", |
|
18 |
VigiloHlservice::OPERATOR_AND, |
|
19 |
self::MESSAGE |
|
20 |
); |
|
21 |
$nbServices = 0; |
|
22 |
foreach ($host->getTests() as $test) { |
|
23 |
foreach ($test->getNagiosNames() as $service) { |
|
24 |
$this->hlsServices[] = new VigiloDepends($name, $service); |
|
25 |
$nbServices++; |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
// Création d'un HLS qui dépend de l'hôte et du HLS précédent. |
|
30 |
$this->hlsHost = new VigiloHlservice( |
|
31 |
"machine:$name", |
|
32 |
VigiloHlservice::OPERATOR_AND, |
|
33 |
self::MESSAGE |
|
34 |
); |
|
35 |
$this->hlsHost[] = new VigiloDepends($host); |
|
36 |
$this->hlsHost[] = new VigiloDepends(null, "services:$name"); |
|
37 |
$this->name = $name; |
|
38 |
} |
|
39 |
|
|
40 |
public function getName() |
|
41 |
{ |
|
42 |
return $this->name; |
|
43 |
} |
|
44 |
|
|
45 |
public function __toString() |
|
46 |
{ |
|
47 |
return "<?xml version="1.0"?><hlservices>{$this->hlsHost}{$this->hlsServices}</hlservices>"; |
|
48 |
} |
|
49 |
} |
src/plugins/vigilo/vigilo_hooks.php | ||
---|---|---|
84 | 84 |
mkdir($confdir, 0770, true); |
85 | 85 |
} |
86 | 86 |
|
87 |
$res = file_put_contents($file, $obj, LOCK_EX); |
|
87 |
$outXML = new DOMDocument(); |
|
88 |
$outXML->preserveWhiteSpace = false; |
|
89 |
$outXML->formatOutput = true; |
|
90 |
$outXML->loadXML((string) $obj); |
|
91 |
$res = file_put_contents($file, $outXML->saveXML(), LOCK_EX); |
|
88 | 92 |
if (false !== $res) { |
89 | 93 |
@chgrp($file, "vigiconf"); |
90 | 94 |
@chmod($file, 0660); |
... | ... | |
127 | 131 |
$cls = "PluginVigiloMonitored" . $item->getType(); |
128 | 132 |
if (class_exists($cls, true)) { |
129 | 133 |
$obj = new $cls($item); |
134 |
|
|
135 |
// Ecriture du fichier de configuration principal (host). |
|
130 | 136 |
$this->writeVigiloConfig($obj, "hosts"); |
137 |
|
|
138 |
// Création d'un service de haut niveau "services:<nom>" |
|
139 |
// qui affichera le pire état des services de la machine "<nom>", |
|
140 |
// et d'un service "machine:<nom>" qui affichera le pire état |
|
141 |
// entre l'état de la machine "<nom>" et de ses services. |
|
142 |
$hls = new PluginVigiloHls($obj); |
|
143 |
$this->writeVigiloConfig($hls, "hlservices"); |
|
131 | 144 |
} |
132 | 145 |
} |
133 | 146 |
|
Also available in: Unified diff