Added a bit more logic into the script so systems with no IP or MAC can still be inserted into influx

This commit is contained in:
Victor Robellini 2020-04-04 19:28:54 -04:00
parent ff885cb4d0
commit 2863f95ece

View File

@ -19,17 +19,28 @@ foreach ($iflist as $ifname => $friendly) {
$realif = get_real_interface($ifname);
$mac = get_interface_mac($realif);
if (!isset($ipaddr)){
$ipaddr = 'Unassigned'
}
if (!isset($mac)){
$mac = 'Unavailable'
}
if (strtolower($ifstatus) == "up"){
$ifstatus = 1;
}
if (strtolower($ifstatus) == "active"){
$ifstatus = 1;
}
if (strtolower($ifstatus) == "no carrier"){
$ifstatus = 0;
}
if (strtolower($ifstatus) == "down"){
$ifstatus = 0;
}
if (!isset($ifstatus)){
$ifstatus = "Unknown";
$ifstatus = 2;
}
if (!empty($ipaddr)) {
printf("interface,host=%s,name=%s,ip_address=%s,mac_address=%s,friendlyname=%s,source=%s status=%s\n",
$host,
$realif,
@ -40,5 +51,4 @@ foreach ($iflist as $ifname => $friendly) {
$ifstatus
);
}
}
?>