Ejemplo n.º 1
0
 public function delete()
 {
     if ($this->getRouterId() != 0) {
         //delete all interfaces
         $networkinterfacelist = new Networkinterfacelist(false, $this->getRouterId());
         $networkinterfacelist->delete();
         //delete originator statusses
         $originator_status_list = new OriginatorStatusList($this->getRouterId());
         $originator_status_list->delete();
         //delete batman advanced interfaces
         try {
             $stmt = DB::getInstance()->prepare("DELETE FROM crawl_batman_advanced_interfaces WHERE router_id=?");
             $stmt->execute(array($this->getRouterId()));
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
         //delete router statusses
         $router_status_list = new RouterStatusList($this->getRouterId());
         $router_status_list->delete();
         //delete event notifications (we need to delete all notifications that users created for this router
         //thats why we need a list here)
         $event_notification_list = new EventNotificationList(false, "router_offline", $this->getRouterId());
         $event_notification_list->delete();
         //Delete api keys
         $api_key_list = new ApiKeyList($this->getRouterId(), 'router');
         $api_key_list->delete();
         //delete router
         try {
             $stmt = DB::getInstance()->prepare("DELETE FROM routers WHERE id=?");
             $stmt->execute(array($this->getRouterId()));
             return $stmt->rowCount();
         } catch (PDOException $e) {
             echo $e->getMessage();
             echo $e->getTraceAsString();
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 public function notify()
 {
     //check if notification has not already been send
     if ($this->getNotify() == true) {
         //check which event to test
         if ($this->getAction() == 'router_offline') {
             $crawl_cycles = ConfigLine::configByName('event_notification_router_offline_crawl_cycles');
             $router = new Router((int) $this->getObject());
             $router->fetch();
             $statusdata_history = new RouterStatusList($router->getRouterId(), 0, (int) $crawl_cycles, "status_id", "desc");
             if ($statusdata_history->getTotalCount() >= $crawl_cycles) {
                 $statusdata_history = $statusdata_history->getRouterStatuslist();
                 $online = false;
                 foreach ($statusdata_history as $key => $statusdata) {
                     if ($statusdata->getStatus() == 'online') {
                         $online = true;
                         break;
                     }
                 }
                 if (!$online and $this->getNotified() == 0) {
                     //if router is marked as offline in each of the $crawl_cycles last crawl cycles, then
                     //send a notification
                     $user = new User($this->getUserId());
                     if ($user->fetch()) {
                         $this->notifyRouterOffline($user, $router, $statusdata_history[$crawl_cycles - 1]->getCreateDate());
                         //store into database that the router has been notified
                         $this->setNotified(1);
                         $this->setNotificationDate(time());
                         $this->store();
                     }
                 } elseif ($online and $this->getNotified() == 1) {
                     //if the router has been notified but is not offline anymore, then reset notification
                     $this->setNotified(0);
                     $this->store();
                 }
             }
         } elseif ($this->getAction() == 'network_down') {
         }
     }
 }