<?php
include_once('libs/class.grabber.php');
include_once('libs/func.queryi.php');
$mysqli = new mysqli('server','username','password','database');
//Delete records older than 7 days and set the current field to 0.
queryi($mysqli, "CALL outdateRecords()",'insert');
$switches[] = array('cisco', 'switch' => '192.168.1.2', 'password' => 'cisco', 'enablepassword' => 'cisco');
$switches[] = array('powerconnect', 'switch' => '192.168.1.3', 'username' => 'admin', 'password' => 'somepass');
//Set the time we ran this for the database.
$grabdate = time();
foreach($switches as $k => $switch) {
echo "Connecting to {$switch['switch']} using the '{$switch[0]}' engine.\r\n";
$n = new switch_grabber($switch[0],$switch);
//$n->debug(true);
$n->connect();
$n->logon();
$arps = $n->getArpTable();
$macs = $n->getMacPortTable();
$settings = $n->getInterfaceSettings();
$n->disconnect();
foreach($macs as $k => $v) {
$sql = "CALL insertMacInterface('{$v['mac']}', '{$v['vlan']}', '{$switch['switch']}', '', '{$v['interface']}', '{$grabdate}');";
$list = queryi($mysqli, $sql,'insert');
if($list[0] == 'error') { print_r($list); break; }
}
foreach($settings as $k => $v) {
if($v['interface'] == null) { continue; }
preg_match('/([a-zA-Z]*)([0-9](\/[0-9]{1,})|)/i',$v['interface'],$name);
//Create the "short" interface name for cisco.
$interface = ($switch[0]=='cisco')?$name[1][0].$name[1][1].$name[2]:$v['interface'];
$sql = "CALL updateInterfaceSettings('{$switch['switch']}', '{$interface}', '{$v['mode']}', '{$v['vlan']}');";
$list = queryi($mysqli, $sql,'insert');
if($list[0] == 'error') { print_r($list); break; }
}
echo "\tMACs: ".count($macs)."\r\n";
echo "\tARP: ".count($arps)."\r\n";
echo "\tSettings: ".count($settings)."\r\n";
}
?>