Exemplo n.º 1
0
 public function store()
 {
     if ($this->getStatusId() != 0 and $this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") {
         echo "UPDATE NOT IMPLEMENTED NOW (and will possibly never be implemented because it is not needed...";
     } elseif ($this->getCrawlCycleId() != 0 and $this->getRouterId() != 0 and $this->getStatus() != "") {
         //check if there already exists an crawl item in this crawl cycle
         $tmp = new RouterStatus(false, $this->getCrawlCycleId(), $this->getRouterId());
         if (!$tmp->fetch()) {
             try {
                 $stmt = DB::getInstance()->prepare("INSERT INTO crawl_routers (router_id, crawl_cycle_id, crawl_date, status,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   hostname, distname, distversion, chipset,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   cpu, memory_total, memory_caching, memory_buffering,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   memory_free, loadavg, processes, uptime, idletime,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   local_time, batman_advanced_version, fastd_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   kernel_version, configurator_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   nodewatcher_version, firmware_version,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   firmware_revision, openwrt_core_revision,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t   openwrt_feeds_packages_revision, client_count)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES (?, ?, NOW(), ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t?, ?)");
                 $stmt->execute(array($this->getRouterId(), $this->getCrawlCycleId(), $this->getStatus(), $this->getHostname(), $this->getDistname(), $this->getDistversion(), $this->getChipset(), $this->getCpu(), $this->getMemoryTotal(), $this->getMemoryCaching(), $this->getMemoryBuffering(), $this->getMemoryFree(), $this->getLoadavg(), $this->getProcesses(), $this->getUptime(), $this->getIdletime(), $this->getLocaltime(), $this->getBatmanAdvancedVersion(), $this->getFastdVersion(), $this->getKernelVersion(), $this->getConfiguratorVersion(), $this->getNodewatcherVersion(), $this->getFirmwareVersion(), $this->getFirmwareRevision(), $this->getOpenwrtCoreRevision(), $this->getOpenwrtFeedsPackagesRevision(), $this->getClientCount()));
             } catch (PDOException $e) {
                 echo $e->getMessage();
                 echo $e->getTraceAsString();
             }
             //Update RRD-Files for graphs
             RrdTool::updateRouterMemoryHistory($this->getRouterId(), $this->getMemoryFree(), $this->getMemoryCaching(), $this->getMemoryBuffering());
             $processes = explode("/", $this->getProcesses());
             $processes[0] = isset($processes[0]) ? $processes[0] : 0;
             $processes[1] = isset($processes[1]) ? $processes[1] : 1;
             RrdTool::updateRouterProcessHistory($this->getRouterId(), $processes[0], $processes[1]);
             //create events
             $eventlist = new Eventlist();
             $router = new Router($this->getRouterId());
             $router->fetch();
             $last_router_status = new RouterStatus(false, (int) Crawling::getLastEndedCrawlCycle()['id'], $this->getRouterId());
             if ($last_router_status->fetch()) {
                 if ($this->getStatus() and $last_router_status->getStatus() and $this->getStatus() != $last_router_status->getStatus()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "status", array('from' => $last_router_status->getStatus(), 'to' => $this->getStatus(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getUptime() and $last_router_status->getUptime() and $this->getUptime() < $last_router_status->getUptime()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "reboot", array('hostname' => $router->getHostname())));
                 }
                 if ($this->getHostname() and $last_router_status->getHostname() and $this->getHostname() != $last_router_status->getHostname()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "hostname", array('from' => $last_router_status->getHostname(), 'to' => $this->getHostname(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getChipset() and $last_router_status->getChipset() and $this->getChipset() != $last_router_status->getChipset()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "chipset", array('from' => $last_router_status->getChipset(), 'to' => $this->getChipset(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getNodewatcherVersion() and $last_router_status->getNodewatcherVersion() and $this->getNodewatcherVersion() != $last_router_status->getNodewatcherVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "nodewatcher_version", array('from' => $last_router_status->getNodewatcherVersion(), 'to' => $this->getNodewatcherVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getFirmwareVersion() and $last_router_status->getFirmwareVersion() and $this->getFirmwareVersion() != $last_router_status->getFirmwareVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "firmware_version", array('from' => $last_router_status->getFirmwareVersion(), 'to' => $this->getFirmwareVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getBatmanAdvancedVersion() and $last_router_status->getBatmanAdvancedVersion() and $this->getBatmanAdvancedVersion() != $last_router_status->getBatmanAdvancedVersion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "batman_advanced_version", array('from' => $last_router_status->getBatmanAdvancedVersion(), 'to' => $this->getBatmanAdvancedVersion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getDistversion() and $last_router_status->getDistversion() and $this->getDistversion() != $last_router_status->getDistversion()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distversion", array('from' => $last_router_status->getDistversion(), 'to' => $this->getDistversion(), 'hostname' => $router->getHostname())));
                 }
                 if ($this->getDistname() and $last_router_status->getDistname() and $this->getDistname() != $last_router_status->getDistname()) {
                     $eventlist->add(new Event(false, false, "router", $this->getRouterId(), "distname", array('from' => $last_router_status->getDistname(), 'to' => $this->getDistname(), 'hostname' => $router->getHostname())));
                 }
             }
             $eventlist->store();
             //Check if netmon already knows the given chipset and if
             //the router assigned to this status has the right chipset set
             if ($this->getStatus() == "online" and $router->getChipset()->getName() != $this->getChipset()) {
                 $chipset = new Chipset(false, $this->getChipset());
                 if (!$chipset->fetch()) {
                     $chipset->store();
                 }
                 $router->setChipsetId($chipset->getChipsetId());
                 $router->store();
             }
             //Return the ID of the inserted RouterStatus
             return DB::getInstance()->lastInsertId();
         }
     }
     return false;
 }
Exemplo n.º 2
0
require_once 'lib/core/User.class.php';
require_once 'lib/core/routersnotassigned.class.php';
require_once 'lib/core/Eventlist.class.php';
require_once 'lib/core/Service.class.php';
require_once 'lib/core/Servicelist.class.php';
//get messages of the message system
$smarty->assign('message', Message::getMessage());
//get some status variables
$smarty->assign('is_logged_in', Permission::isLoggedIn($_SESSION['user_id']));
//get user data
$user = new User((int) $_GET['user_id']);
$user->fetch();
$smarty->assign('user', $user);
$evenlist = new Eventlist();
$routerlist = new Routerlist(false, (int) $_GET['user_id']);
foreach ($routerlist->getRouterlist() as $router) {
    $tmp_eventlist = new Eventlist();
    $tmp_eventlist->init('router', $router->getRouterId(), false, 0, 6, 'event_id', 'desc');
    $evenlist->add($tmp_eventlist);
}
$evenlist->sort('create_date', 'desc');
$smarty->assign('eventlist', array_slice($evenlist->getEventlist(), 0, 10));
$smarty->assign('routersnotassigned_list', RoutersNotAssigned::getRouters());
$routerlist = new Routerlist(false, (int) $_GET['user_id']);
$smarty->assign('routerlist', $routerlist->getRouterlist());
$servicelist = new Servicelist((int) $_GET['user_id']);
$smarty->assign('servicelist', $servicelist->getServicelist());
//load the temlate
$smarty->display("header.tpl.html");
$smarty->display("user.tpl.html");
$smarty->display("footer.tpl.html");