112 lines
3.7 KiB
PHP
112 lines
3.7 KiB
PHP
<?php
|
|
/** \file scripts/other/tasks/zombie_check.php
|
|
* \brief DI webinterface task manager script, zombie device check
|
|
* \author Rob Schalken, Core|Vision
|
|
* \version $Revision: 1.2 $
|
|
* \date $Date: 2013/03/13 17:11:35 $
|
|
*
|
|
* Zombie check; checks for devices that no longer send updates
|
|
*/
|
|
|
|
/************************************/
|
|
/* Zombie check */
|
|
/************************************/
|
|
|
|
// Acquire mutex
|
|
if (db_mutex_acquire(RemoveExtension(basename(__FILE__)) . "_" . $params['task_id'], 0)) {
|
|
// Default skin
|
|
$_PAGE_INFO['skin'] = "dualinventive";
|
|
|
|
// Get settings from ini file
|
|
$ini_file = get_all_files($_PAGE_INFO['base_path'] . SKIN_DIR . $_PAGE_INFO['skin'] . "/", array("ini"));
|
|
$_PAGE_INFO['ini'] = parse_ini_file($ini_file[0], true);
|
|
|
|
// Find all equipment
|
|
$equipment = db_fetch_all_lances();
|
|
|
|
// Check tcp_log for connection
|
|
if (is_array($equipment)) {
|
|
foreach ($equipment as $item) {
|
|
// Initial values
|
|
$changed = FALSE;
|
|
$connect = FALSE;
|
|
|
|
// Get last entry from log_tcp
|
|
$log_tcp_entry = db_fetch_lance_tcp_status($item['id'], $now, FALSE);
|
|
|
|
// Connected for at least one hour?
|
|
if ((strtoupper($log_tcp_entry['event']) == "CONNECT") && ($log_tcp_entry['t'] <= (convert_datetime($now_hour_before)))) {
|
|
// Set connected flag
|
|
$connect = TRUE;
|
|
|
|
// Battery voltage or temperatures changed the last hour?
|
|
$log_rt = db_fetch_lance_logrt($item['id'], 0, $now_hour_before, $now);
|
|
|
|
if ((is_array($log_rt)) && (!empty($log_rt))) {
|
|
// Firmware version not to old?
|
|
$version = zkl_get_fw_version($item['wcpu_versie']);
|
|
|
|
if ($version['datecode'] > 0x20110301) {
|
|
foreach($log_rt as $log_rt_item) {
|
|
$changed = ($log_rt_item['changes'] & 0x3300) ? TRUE : $changed;
|
|
}
|
|
}
|
|
else {
|
|
// Version to old! => Force skip
|
|
$changed = TRUE;
|
|
}
|
|
}
|
|
else {
|
|
// Something else went wrong
|
|
$connect = FALSE;
|
|
}
|
|
}
|
|
|
|
// Changed or not connected for last hour => Clear
|
|
if ($changed || !$connect) {
|
|
if (in_array($item['id'], $error)) {
|
|
// Remove from zkl_logerror table
|
|
db_delete("zkl_logerror", "zkl='" . $item['id'] . "' AND task_id='" . $task['id'] . "'");
|
|
}
|
|
}
|
|
else {
|
|
if (!in_array($item['id'], $error)) {
|
|
// Get item
|
|
$item_name = ($item['idcode'] != $item['serienr']) ? $item['idcode'] . " - " . $item['serienr'] : $item['idcode'];
|
|
|
|
// Define subject
|
|
$subject = _("MTinfo periodic zombie search") . " " . strtolower(_("Error")) . ": " . $item_name;
|
|
|
|
// Define content
|
|
$content = "<p style=\"font-family:verdana;font-size:10pt\">";
|
|
$content .= _("Dear MTinfo user") . ",<br><br>";
|
|
$content .= _("The follow equipment is probably in zombie state") . ": " . $item_name . ".<br><br>";
|
|
$content .= _("Best regards") . ",<br><br>";
|
|
$content .= "MTinfo";
|
|
$content .= "</p>";
|
|
|
|
// Store in zkl_logerror table
|
|
db_store("zkl_logerror", array("zkl","tijd","task_id"), array($item['id'], $now, $task['id']));
|
|
|
|
// Send mail
|
|
send_mail($_PAGE_INFO['ini']['comm']['debug'], "", "","error@dualinventive.com", $subject, $content, "", "", 1);
|
|
|
|
// Debug info
|
|
DBG("Zombie searcher: " . $item['idcode'] . " (" . $item['id'] .") probably in zombie state");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Release mutex
|
|
db_mutex_release(RemoveExtension(basename(__FILE__)) . "_" . $params['task_id']);
|
|
|
|
// Set handled flag
|
|
$handled = 1;
|
|
}
|
|
else {
|
|
// Debug info
|
|
DBG("Mutex not released: " . $params['task_id']);
|
|
}
|
|
|
|
?>
|