-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_mia_ping_pingloss.php
executable file
·52 lines (41 loc) · 1.57 KB
/
check_mia_ping_pingloss.php
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
#!/usr/local/bin/php5 -q
<?php
require_once('lib/MiaNagiosPluginIndexed.inc.php');
class MiaNagiosPlugin_CheckPingPingloss extends MiaNagiosPluginIndexed{
/**
* (non-PHPdoc)
* @see nagios/plugins/lib/MiaNagiosPlugin#setSpecialProperties()
*/
protected function setSpecialProperties(){
$this->setSpecialProperty('intituleStatus','ping_pingloss');
$this->setSpecialProperty('titre_aide','ping divers');
$this->setSpecialProperty('commentaire_aide','pour la commande -H le séparateur est ,.');
}
protected function setInputs(){
parent::setInputs();
$this-> addInput('hostnames',"/(\-H)\s([^\s]+)\s*/",false);
}
/**
* (non-PHPdoc)
* @see nagios/plugins/lib/MiaNagiosPlugin#setIndicators()
*/
protected function setIndicators(){
$this->addIndicatorIndexed('ping_pingloss');
}
protected function coreFunction(){
trigger_error("start",E_USER_NOTICE);
$hostlist=split(",",$this->getInput('hostnames'));
$nbping=5;
foreach ($hostlist as $case){
exec('ping -c '.$nbping.' -i 0.2 -t 100 '.$case.' | grep loss',$output);
foreach ($output as $line){
preg_match("/.*([0-9]+)%/",$line,$match);
$tab['ping_pingloss'][$case]=$match[1];
}
}
trigger_error("end",E_USER_NOTICE);
return $tab;
}
}
$check=new MiaNagiosPlugin_CheckPingPingloss();
$check->OutputResult();