findOneByInstAddrVal($inst_addr->getValue()); if ($inst == NULL) { // create this instance $inst = new RemoteWatchdog(); $inst->setName($inst_addr); $inst->setInstAddr($inst_addr); $inst->setEvtSpec(new EventSpec(EventSel::FREE_FORM, "watchdog_timeout")); $inst->setMinInt(60); // seconds $inst->setLastPing($rec_date); $inst->setHasAlarm(false); $inst->save(); } else { $inst->setLastPing($rec_date); $inst->save(); } } */ static function triggerXML($req_par) { $inpExtr = new XmlExtractor(); $inpExtr->openInput($req_par); if ($inpExtr->extractElement(InputExtractor::EC_BEG, $elem, $value, $fattrs) != InputExtractor::EC_CTN) throw new Exception("Invalid request"); // extraxt attributes $inst = new RemoteWatchdog(); $extr_ctl = InputExtractor::EC_BEG; while (($extr_ctl = $inpExtr->extractElement($extr_ctl, $elem, $value, $fattrs)) != InputExtractor::EC_END) { switch ($elem) { case "name": $inst->setName($value); break; case "inst_addr": $inst->setInstAddr(new InstAddr($value)); break; case "evt_spec": $inst->setEvtSpec(new EventSpec($value)); break; case "min_int": $inst->setMinInt(new GATime($value)); default: } } $addr_value = $inst->getInstAddrVal(); if ($addr_value == "") throw new Exception("Instance address is mandatory"); $rec_date = time(); // check, if watchdog is in the system $test = RemoteWatchdogQuery::create()->findOneByInstAddrVal($addr_value); if ($test == NULL) { if ($inst->getName() == "") $inst->setName(strval($inst->getInstAddr())); if ($inst->getMinInt() == 0) $inst->setMinInt(60); // seconds if ($inst->getEvtSpecVal() == "") $inst->setEvtSpec(new EventSpec(EventSel::FREE_FORM, "watchdog_timeout")); $inst->setLastPing($rec_date); $inst->setHasAlarm(false); $inst->setInactive(false); $inst->save(); $id = $inst->getId(); } else { // update instance if ($inst->getName() != "") $test->setName($inst->getName()); if ($inst->getMinInt() != 0) $test->setMinInt($inst->getMinInt()); // seconds if ($inst->getEvtSpecVal() != "") $test->setEvtSpec($inst->getEvtSpec()); $test->setLastPing($rec_date); $test->setInactive(false); $test->save(); $id = $test->getId(); } $if = new AlarmInterfaceAdministration(); return $if->getInstance(1, $id); } static function checkRemoteWatchdog() { // build critical time $now = time(); require_once 'AlarmManagement/AlarmManagement.php'; // read watchdogs to alarm $wdogs = RemoteWatchdogQuery::getWatchdogsToAlarm($now); foreach ($wdogs as $wdog) { AlarmManagement::processAlarm( $wdog->getInstAddr(), date('y.m.d h:i:s'), $wdog->getEvtSpec()); $wdog->setHasAlarm(true); $wdog->save(); } // read watchdogs to reset $wdogs = RemoteWatchdogQuery::getWatchdogsToReset($now); foreach ($wdogs as $wdog) { AlarmManagement::processAlarm( $wdog->getInstAddr(), date('y.m.d h:i:s'), $wdog->getEvtSpec(), new ServInfl(ServInfl::SI_INDEP), new AlarmSevty(AlarmSevty::AS_CLEAR)); $wdog->setHasAlarm(false); $wdog->save(); } } static function checkPingWatchdog() { $wdogs = PingWatchdogQuery::create()->find(); foreach ($wdogs as $wdog) { // perform ping // TODO: perform ping if ($success && $wdog->hasAlarm()) { // reset alarm AlarmManagement::processAlarm( $wdog->getInstAddr(), date('y.m.d h:i:s'), $wdog->getEvtSpec(), new ServInfl(ServInfl::SI_INDEP), new AlarmSevty(AlarmSevty::AS_CLEAR)); $wdog->setHasAlarm(false); $wdog->save(); } elseif ((!$success) && (!$wdog->hasAlarm())) { // set alarm AlarmManagement::processAlarm( $wdog->getInstAddr(), date('y.m.d h:i:s'), $wdog->getEvtSpec()); $wdog->setHasAlarm(true); $wdog->save(); } } } }