-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CheckNodeReliability.php
52 lines (51 loc) · 2.06 KB
/
CheckNodeReliability.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
// Setup
// Jeedom configuration/API/Clef API Z-Wave
$apizwave = 'yourZwaveAPIKey';
// the node Id to perform the ping
$nodeId = 2;
// timeout
$timeout = 60;
// End Setup
// time of the testNode command
$send_time = $scenario->getData("ZAPI_NodePingTime");
$scenario->removeData(ZAPI_NodePingTime);
// get node health data
$url = 'http://127.0.0.1:8083/node?node_id=' . $nodeId . '&type=info&info=getHealth&apikey=' . $apizwave;
$contents = utf8_encode(file_get_contents($url));
//$scenario->setLog('Contents :' . $contents);
$results = json_decode($contents);
$success = $results->state;
if ($success != 'ok') {
$scenario->setLog('ZAPI node getHealth return an error: ' . $results["result"]);
} else {
// read the attributes of the last notification
$receiveTime = $results->result->last_notification->receiveTime;
$description = $results->result->last_notification->description;
$scenario->setLog('Receive ' . $description . ' notification at time :' . date("Y-m-j H:i:s", $receiveTime));
// init message to empty
$message = '';
// check if node is presume dead
if ($description == 'Dead') {
$message = 'The Z Wave controller marked the Node Id ' . $nodeId . ' as presumed dead';
} else {
// check the delta
$delta = $receiveTime - $send_time;
$scenario->setLog('Recive a echo in :' . $delta . ' seconds.');
// check if notification has occur more the 1 minute ago
if ($delta > $timeout) {
// use a notification command action to send the warning message
$message = 'No response received after node test after ' . $delta . ' seconds';
}
}
if ($message != '') {
// add log entry
$scenario->setLog($message);
$cmd = cmd::byString('#[Notifications][Telegram Bot][Tous]#');
if (is_object($cmd)) {
$option = array('title' => 'A ZWave node no longer seems to respond', 'message' => $message);
$cmd->execCmd($option);
} else {
$scenario->setLog('Error: the notification command did not exist');
}
}
}