src.dualinventive.com/mtinfo/dist/webroot/main/scripts/other/tasks/switch3000_check.php

198 lines
7.0 KiB
PHP

<?php
/** \file scripts/other/tasks/switch3000_check.php
* \brief DI webinterface task manager script, Switch 3000 checker
* \author Rob Schalken, Core|Vision
* \version $Revision: 1.5 $
* \date $Date: 2013/04/04 13:42:06 $
*
* Switch 3000 checker
*/
/************************************/
/* SWITCH 3000 checker (batt/sect) */
/************************************/
// Initial values
$switch3000_check = array();
$equipment = array();
// 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);
// Retrieve all device types
$types = db_fetch_system_devices($_PAGE_INFO['i18n']);
if (is_array($types)) {
foreach($types as $type) {
// Right capability?
if (db_check_system_device_capabilities($type['id'], array("kortsluiting schakelen"))) {
// Find all equipment
$equipment_type = db_fetch_all_lances($type['id']);
if (is_array($equipment_type)) {
// Merge arrays
$equipment += $equipment_type;
}
}
}
}
// Check switch status (battery, sections and measurement state)
if (!empty($equipment)) {
foreach ($equipment as $item) {
// Active item?
if ($item['lans_status'] == "actief") {
// Initial values
$detected = array();
// Fetch last log_realtime entry
$status = db_fetch_lance_logrt($item['id']);
// Valid log entry?
if (is_array($status)) {
// Communication OK?
if ($status[0]['sw3000_state'] & 0x20) {
// These could be resolved by retries, please check previous log_realtime (60 - 900 secs ago)
$prev_status = db_fetch_lance_logrt($item['id'], 0, convert_datetime($status[0]['t'] - 900, TRUE), convert_datetime($status[0]['t'] - 60, TRUE));
// Previous log_realtime available
if (is_array($prev_status)) {
// Same error?
if ($prev_status[0]['sw3000_state'] & 0x20) {
array_push($detected, "communication");
}
}
else {
// No previoius state? => Already error state? => Still in error state!
if (in_array($item['id'], $error)) {
array_push($detected, "communication");
}
}
}
else {
// Sections OK?
if ((($status[0]['sw3000_state'] & 0x0F) != 0x0F) && (($status[0]['sw3000_state'] & 0x0F) != 0x00)) {
array_push($detected, "section");
}
// Battery OK?
if (($status[0]['sw3000_state'] & 0x8F00) != 0x8F00) {
// These could be jitter, please check previous log_realtime (60 - 900 secs ago)
$prev_status = db_fetch_lance_logrt($item['id'], 1, convert_datetime($status[0]['t'] - 900, TRUE), convert_datetime($status[0]['t'] - 60, TRUE));
// Previous log_realtime available
if (is_array($prev_status)) {
// Same error?
if (($prev_status[0]['sw3000_state'] & 0x8F00) != 0x8F00) {
array_push($detected, "battery");
}
}
else {
// No previoius state? => Already error state? => Still in error state!
if (in_array($item['id'], $error)) {
array_push($detected, "battery");
}
}
}
// Switch enabled when measurement is disabled
if ((!($status[0]['mcu_state'] & 0x0001)) &&
((($status[0]['sw3000_state'] & 0x06) == 0x06) || (($status[0]['sw3000_state'] & 0x09) == 0x09))){
array_push($detected, "sw_en_meas_dis");
}
// Switch disabled when measurements are enabled (key switch must not be active)
if (($status[0]['mcu_state'] & 0x0001) &&
!((($status[0]['sw3000_state'] & 0x06) == 0x06) || (($status[0]['sw3000_state'] & 0x09) == 0x09)) &&
!($status[0]['rc_state'] & 0x0008)){
array_push($detected, "sw_dis_meas_en");
}
}
// Error detected?
if (empty($detected)) {
if (in_array($item['id'], $error)) {
DBG("switch3000_check: " . $item['id'] . ": ok");
// Remove from zkl_logerror table
db_delete("zkl_logerror", "zkl='" . $item['id'] . "' AND task_id='" . $task['id'] . "'");
}
}
else {
DBG("switch3000_check: " . $item['id'] . ": " . implode(",", $detected) . (in_array($item['id'], $error) ? "; mail sent before" : ""));
if (!in_array($item['id'], $error)) {
// Store in zkl_logerror table
db_store("zkl_logerror", array("zkl","tijd","task_id"), array($item['id'], $now, $task['id']));
array_push($switch3000_check, array(id => $item['id'], 'detected' => $detected));
}
}
}
}
}
}
if (!empty($switch3000_check)) {
foreach($switch3000_check as $item) {
// Fetch equipment info
$item_info = db_fetch_lance($item['id'], "", 1);
// Fetch owner info
$cust_info = db_fetch_customer($item_info['eigenaar'], 1);
// Set owner language (When service email has been selected => else default)
$service_email = "";
if (strlen($cust_info['service_email'])) {
i18n_settext_language($cust_info['i18n'], $_PAGE_INFO['base_path'] . "locale/");
// Set email
$service_email = $cust_info['service_email'];
}
// Define subject
$subject = "MTinfo" . " " . strtolower(_("Error")) . ": " . $item_info['idcode'] . " (" . $cust_info['bedrijfsnaam'] . ")";
// Define content
$content = "<style type=\"text/css\">body { font-family:verdana;font-size:10pt }</style>";
$content .= "<p>";
$content .= _("Dear MTinfo user") . ",<br><br>";
$content .= _("The SWITCH 3000 of the following equipment has errors");
$content .= ": " . $item_info['idcode'] . "<br>";
$content .= "<ul>";
foreach( $item['detected'] as $detected_error ) {
switch($detected_error) {
case "communication":
$content .= "<li>" . _("The communication with the SWITCH 3000 is not operating correct");
break;
case "section":
$content .= "<li>" . _("One of the redundant sections is not operating correct");
break;
case "battery":
$content .= "<li>" . _("The SWITCH 3000 battery status is beneath the required threshold");
break;
case "sw_en_meas_dis":
$content .= "<li>" . _("The SWITCH 3000 is undesirable on");
break;
case "sw_dis_meas_en":
$content .= "<li>" . _("Measurements are undesirable on");
break;
}
}
$content .= "</ul><br>";
$content .= _("Please contact") . " Dual Inventive!<br><br>";
$content .= _("Best regards") . ",<br><br>";
$content .= "MTinfo";
$content .= "</p>";
// Send mail (high priority)
send_mail("", "", $_PAGE_INFO['ini']['comm']['dev_error'], $_PAGE_INFO['ini']['report']['no-reply'], $subject, $content, "", "", 1);
}
}
// Set handled flag
$handled = 1;
?>