Пример #1
0
 public function insertCrawlData($data)
 {
     $router_data = Router_old::getRouterInfo($data['router_id']);
     $actual_crawl_cycle = Crawling::getActualCrawlCycle();
     $last_endet_crawl_cycle = Crawling::getLastEndedCrawlCycle();
     /**Insert Router Interfaces*/
     foreach ($data['interface_data'] as $sendet_interface) {
         //Update RRD Graph DB
         $interface_last_endet_crawl = Interfaces::getInterfaceCrawlByCrawlCycleAndRouterIdAndInterfaceName($last_endet_crawl_cycle['id'], $data['router_id'], $sendet_interface['name']);
         $traffic_rx_bps = round(($sendet_interface['traffic_rx'] - $interface_last_endet_crawl['traffic_rx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_rx_bps = $traffic_rx_bps < 0 ? 0 : $traffic_rx_bps;
         $traffic_tx_bps = round(($sendet_interface['traffic_tx'] - $interface_last_endet_crawl['traffic_tx']) / $GLOBALS['crawl_cycle'] / 60);
         $traffic_tx_bps = $traffic_tx_bps < 0 ? 0 : $traffic_tx_bps;
         //Set default indizies to prevent from warnings
         $sendet_interface['wlan_frequency'] = isset($sendet_interface['wlan_frequency']) ? preg_replace("/([A-Za-z])/", "", $sendet_interface['wlan_frequency']) : "";
         $sendet_interface['wlan_mode'] = isset($sendet_interface['wlan_mode']) ? $sendet_interface['wlan_mode'] : "";
         $sendet_interface['wlan_essid'] = isset($sendet_interface['wlan_essid']) ? $sendet_interface['wlan_essid'] : "";
         $sendet_interface['wlan_bssid'] = isset($sendet_interface['wlan_bssid']) ? $sendet_interface['wlan_bssid'] : "";
         $sendet_interface['wlan_tx_power'] = isset($sendet_interface['wlan_tx_power']) ? $sendet_interface['wlan_tx_power'] : 0;
         //check if interface already exists
         $networkinterface_test = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
         //if interface not exist, create new
         if (!$networkinterface_test->fetch()) {
             $networkinterface_new = new Networkinterface(false, (int) $data['router_id'], $sendet_interface['name']);
             $networkinterface_id = $networkinterface_new->store();
         } else {
             $networkinterface_id = $networkinterface_test->getNetworkinterfaceId();
         }
         //save crawl data for interface
         $networkinterface_status = new NetworkinterfaceStatus(false, (int) $actual_crawl_cycle['id'], (int) $networkinterface_id, (int) $data['router_id'], $sendet_interface['name'], $sendet_interface['mac_addr'], (int) $sendet_interface['mtu'], (int) $sendet_interface['traffic_rx'], (int) $traffic_rx_bps, (int) $sendet_interface['traffic_tx'], (int) $traffic_tx_bps, $sendet_interface['wlan_mode'], $sendet_interface['wlan_frequency'], $sendet_interface['wlan_essid'], $sendet_interface['wlan_bssid'], (int) $sendet_interface['wlan_tx_power'], false);
         $networkinterface_status->store();
         //Update RRDDatabase
         $rrd_path_traffic_rx = ROOT_DIR . "/rrdtool/databases/router_{$data['router_id']}_interface_{$sendet_interface['name']}_traffic_rx.rrd";
         if (!file_exists($rrd_path_traffic_rx)) {
             exec("rrdtool create {$rrd_path_traffic_rx} --step 600 --start " . time() . " DS:traffic_rx:GAUGE:700:U:U DS:traffic_tx:GAUGE:900:U:U RRA:AVERAGE:0:1:144 RRA:AVERAGE:0:6:168 RRA:AVERAGE:0:18:240");
         }
         exec("rrdtool update {$rrd_path_traffic_rx} " . time() . ":" . round($traffic_rx_bps / 1000, 2) . ":" . round($traffic_tx_bps / 1000, 2));
         //add unknown ipv6 link local addresses to netmon
         //prepare data
         $ipv6_link_local_addr = explode("/", $sendet_interface['ipv6_link_local_addr']);
         $ipv6_link_local_netmask = isset($ipv6_link_local_addr[1]) ? (int) $ipv6_link_local_addr[1] : 64;
         $ipv6_link_local_addr = Ip::ipv6Expand($ipv6_link_local_addr[0]);
         //first try to determine network of given address
         $ipv6_link_local_network = Ip::ipv6NetworkFromAddr($ipv6_link_local_addr, (int) $ipv6_link_local_netmask);
         $network = new Network(false, false, $ipv6_link_local_network, (int) $ipv6_link_local_netmask, 6);
         if ($network->fetch()) {
             //if network found, then try to add ip address
             $ip = new Ip(false, (int) $networkinterface_id, $network->getNetworkId(), $ipv6_link_local_addr);
             $ip->store();
         }
     }
     RrdTool::updateRouterClientCountHistory($data['router_id'], $data['client_count']);
 }
Пример #2
0
    }
    echo "Close old crawl cycle and create new one\n";
    //Create new crawl cycle and close old crawl cycle
    //Create new crawl cycle
    Crawling::newCrawlCycle();
    //Close old Crawl cycle
    Crawling::closeCrawlCycle($actual_crawl_cycle['id']);
    echo "Create graph statistics\n";
    //Make statistic graphs
    $online = Router_old::countRoutersByCrawlCycleIdAndStatus($actual_crawl_cycle['id'], 'online');
    $offline = Router_old::countRoutersByCrawlCycleIdAndStatus($actual_crawl_cycle['id'], 'offline');
    $unknown = Router_old::countRoutersByCrawlCycleIdAndStatus($actual_crawl_cycle['id'], 'unknown');
    $total = $unknown + $offline + $online;
    RrdTool::updateNetmonHistoryRouterStatus($online, $offline, $unknown, $total);
    $client_count = Router_old::countRoutersByCrawlCycleId($actual_crawl_cycle['id']);
    RrdTool::updateNetmonClientCount($client_count);
} else {
    echo "There is an crawl cycle running actually. Doing nothing.\n";
}
/**
 * Clean database
 */
echo "Clean database\n";
//Delete old Crawls
echo "Remove old crawl data\n";
Crawling::deleteOldCrawlDataExceptLastOnlineCrawl($GLOBALS['hours_to_keep_mysql_crawl_data'] * 60 * 60);
//Remove old events
echo "Remove old events\n";
//Get number of total events in db
$total_count = new Eventlist();
$total_count->init(false, false, false, 0, 0);
                        /**Insert Batman Advanced Originators*/
                        $originator_count = count($data['batman_adv_originators']);
                        RrdTool::updateRouterBatmanAdvOriginatorsCountHistory($data['router_id'], $originator_count);
                        $average_link_quality = 0;
                        if (!empty($data['batman_adv_originators'])) {
                            foreach ($data['batman_adv_originators'] as $originator) {
                                if (ConfigLine::configByName('crawl_direct_originators_only') == 'true' and $originator['originator'] == $originator['nexthop']) {
                                    $originator_status = new OriginatorStatus(false, (int) $actual_crawl_cycle, (int) $data['router_id'], $originator['originator'], (int) $originator['link_quality'], $originator['nexthop'], $originator['outgoing_interface'], $originator['last_seen']);
                                    $originator_status->store();
                                    RrdTool::updateRouterBatmanAdvOriginatorLinkQuality($data['router_id'], $originator['originator'], $originator['link_quality'], time());
                                    $average_link_quality = $average_link_quality + $originator['link_quality'];
                                }
                            }
                        }
                        $average_link_quality = $average_link_quality / $originator_count;
                        RrdTool::updateRouterBatmanAdvOriginatorLinkQuality($data['router_id'], "average", $average_link_quality, time());
                        echo "\t\t\tInserting all other Data into DB\n";
                        Crawl::insertCrawlData($data);
                    } else {
                        echo "\t\t\tRouterStatus could not be inserted into DB\n";
                    }
                    break 2;
                } else {
                    echo "\t\t\tCrawl was not successfull trying to ping next address\n";
                }
            }
        }
    }
}
echo "The process took " . (time() - $starttime) . " seconds\n";
function simplexml2array($xml)
Пример #4
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;
 }
Пример #5
0
                foreach ($_POST['bat_adv_orig'] as $bat_adv_orig) {
                    try {
                        DB::getInstance()->exec("INSERT INTO crawl_batman_advanced_originators (router_id, crawl_cycle_id, originator, link_quality, nexthop, outgoing_interface, last_seen, crawl_date)\n\t\t\t\t\t\t\t\t\t VALUES ('{$_POST['router_id']}', '{$actual_crawl_cycle['id']}', '{$bat_adv_orig['originator']}', '{$bat_adv_orig['link_quality']}', '{$bat_adv_orig['nexthop']}', '{$bat_adv_orig['outgoing_interface']}', '{$bat_adv_orig['last_seen']}', NOW());");
                    } catch (PDOException $e) {
                        echo $e->getMessage();
                        echo $e->getTraceAsString();
                    }
                    RrdTool::updateRouterBatmanAdvOriginatorLinkQuality($_POST['router_id'], $bat_adv_orig['originator'], $bat_adv_orig['link_quality'], time());
                }
            }
            $originator_count = count($_POST['bat_adv_orig']);
            RrdTool::updateRouterBatmanAdvOriginatorsCountHistory($_POST['router_id'], $originator_count);
            $average_link_quality = 0;
            foreach ($_POST['bat_adv_orig'] as $originator) {
                $average_link_quality = $average_link_quality + $originator['link_quality'];
            }
            $average_link_quality = $average_link_quality / $originator_count;
            RrdTool::updateRouterBatmanAdvOriginatorLinkQuality($_POST['router_id'], "average", $average_link_quality, time());
            RrdTool::updateRouterClientCountHistory($_POST['router_id'], $_POST['client_count']);
        } else {
            echo "Your router with the id {$_POST['router_id']} has already been crawled";
        }
    } else {
        echo "error;";
        echo "You FAILED! to authenticated at netmon api nodewatcher section insert_crawl_interfaces_data\n";
        echo "Your router_id is: " . $_POST['router_id'];
        echo "Your authentificationmethod is: " . $_POST['authentificationmethod'];
        echo "Your netmon router_auto_assign_hash is: " . $router_data['router_auto_assign_hash'];
        echo "Your router_auto_update_hash is: " . $_POST['router_auto_update_hash'];
    }
}