I added a bunch of checks to make sure no null values get passed to telegraf.
I'm sure there is a better way to do this, but I am not a php developer and it's Sunday. Issue: https://github.com/VictorRobellini/pfSense-Dashboard/issues/39 Reporter: https://github.com/xppx99 Thanks for the heads up xppx99
This commit is contained in:
parent
2433e41eb5
commit
a6fa2eca05
@ -19,38 +19,49 @@ foreach ($iflist as $ifname => $friendly) {
|
|||||||
$realif = get_real_interface($ifname);
|
$realif = get_real_interface($ifname);
|
||||||
$mac = get_interface_mac($realif);
|
$mac = get_interface_mac($realif);
|
||||||
|
|
||||||
if (!isset($ip4addr)){
|
if (!isset($ifinfo)) {
|
||||||
$ip4addr = "Unassigned";
|
$ifinfo = "Unavailable";
|
||||||
}
|
}
|
||||||
if (!isset($ip4subnet)){
|
if (strtolower($ifstatus) == "up") {
|
||||||
$ip4subnet = "Unassigned";
|
|
||||||
}
|
|
||||||
if (!isset($ip6addr)){
|
|
||||||
$ip6addr = "Unassigned";
|
|
||||||
}
|
|
||||||
if (!isset($ip6subnet)){
|
|
||||||
$ip6subnet = "Unassigned";
|
|
||||||
}
|
|
||||||
if (!isset($mac)){
|
|
||||||
$mac = "Unavailable";
|
|
||||||
}
|
|
||||||
if (strtolower($ifstatus) == "up"){
|
|
||||||
$ifstatus = 1;
|
$ifstatus = 1;
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "active"){
|
if (strtolower($ifstatus) == "active") {
|
||||||
$ifstatus = 1;
|
$ifstatus = 1;
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "no carrier"){
|
if (strtolower($ifstatus) == "no carrier") {
|
||||||
$ifstatus = 0;
|
$ifstatus = 0;
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "down"){
|
if (strtolower($ifstatus) == "down") {
|
||||||
$ifstatus = 0;
|
$ifstatus = 0;
|
||||||
}
|
}
|
||||||
if (!isset($ifstatus)){
|
if (!isset($ifstatus)) {
|
||||||
$ifstatus = 2;
|
$ifstatus = 2;
|
||||||
}
|
}
|
||||||
|
if (!isset($ifconf)) {
|
||||||
|
$ifconf = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($ip4addr)) {
|
||||||
|
$ip4addr = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($ip4subnet)) {
|
||||||
|
$ip4subnet = "0";
|
||||||
|
}
|
||||||
|
if (!isset($ip6addr)) {
|
||||||
|
$ip6addr = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($ip6subnet)) {
|
||||||
|
$ip6subnet = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($realif)) {
|
||||||
|
$realif = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($mac)) {
|
||||||
|
$mac = "Unavailable";
|
||||||
|
}
|
||||||
|
|
||||||
printf("interface,host=%s,name=%s,ip4_address=%s,ip4_subnet=%s,ip6_address=%s,ip6_subnet=%s,mac_address=%s,friendlyname=%s,source=%s status=%s\n",
|
|
||||||
|
printf(
|
||||||
|
"interface,host=%s,name=%s,ip4_address=%s,ip4_subnet=%s,ip6_address=%s,ip6_subnet=%s,mac_address=%s,friendlyname=%s,source=%s status=%s\n",
|
||||||
$host,
|
$host,
|
||||||
$realif,
|
$realif,
|
||||||
$ip4addr,
|
$ip4addr,
|
||||||
@ -70,7 +81,7 @@ $gw_statuses = return_gateways_status(true);
|
|||||||
|
|
||||||
$debug = false;
|
$debug = false;
|
||||||
|
|
||||||
if($debug){
|
if ($debug) {
|
||||||
print_r($gw_array);
|
print_r($gw_array);
|
||||||
print_r($gw_statuses);
|
print_r($gw_statuses);
|
||||||
}
|
}
|
||||||
@ -94,19 +105,45 @@ foreach ($gw_array as $gw => $gateway) {
|
|||||||
$gwdescr = $gateway["descr"];
|
$gwdescr = $gateway["descr"];
|
||||||
$defaultgw = $gateway['isdefaultgw'];
|
$defaultgw = $gateway['isdefaultgw'];
|
||||||
|
|
||||||
|
if (!isset($monitor)) {
|
||||||
|
$monitor = "Unavailable";
|
||||||
|
}
|
||||||
|
if (!isset($source)) {
|
||||||
|
$source = "Unavailable";
|
||||||
|
}
|
||||||
|
if (!isset($delay)) {
|
||||||
|
$delay = "0";
|
||||||
|
}
|
||||||
|
if (!isset($stddev)) {
|
||||||
|
$stddev = "0";
|
||||||
|
}
|
||||||
|
if (!isset($loss)) {
|
||||||
|
$loss = "0";
|
||||||
|
}
|
||||||
|
if (!isset($status)) {
|
||||||
|
$status = "Unavailable";
|
||||||
|
}
|
||||||
|
if (!isset($interface)) {
|
||||||
|
$interface = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($friendlyname)) {
|
||||||
|
$friendlyname = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($friendlyifdescr)) {
|
||||||
|
$friendlyifdescr = "Unassigned";
|
||||||
|
}
|
||||||
|
if (!isset($gwdescr)) {
|
||||||
|
$gwdescr = "Unassigned";
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($gateway['isdefaultgw'])) {
|
if (isset($gateway['isdefaultgw'])) {
|
||||||
$defaultgw = "1";
|
$defaultgw = "1";
|
||||||
} else {
|
} else {
|
||||||
$defaultgw = "0";
|
$defaultgw = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gw_statuses[$gw]) {
|
|
||||||
if (isset($gateway['monitor_disable'])) {
|
if (isset($gateway['monitor_disable'])) {
|
||||||
$monitor = "Unmonitored";
|
$monitor = "Unmonitored";
|
||||||
$delay = "Pending";
|
|
||||||
$stdev = "Pending";
|
|
||||||
$loss = "Pending";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some earlier versions of pfSense do not return substatus
|
// Some earlier versions of pfSense do not return substatus
|
||||||
@ -116,10 +153,11 @@ foreach ($gw_array as $gw => $gateway) {
|
|||||||
$substatus = "N/A";
|
$substatus = "N/A";
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("gateways,host=%s,interface=%s,gateway_name=%s monitor=\"%s\",source=\"%s\",defaultgw=%s,gwdescr=\"%s\",delay=%s,stddev=%s,loss=%s,status=\"%s\",substatus=\"%s\"\n",
|
printf(
|
||||||
|
"gateways,host=%s,interface=%s,gateway_name=%s monitor=\"%s\",source=\"%s\",defaultgw=%s,gwdescr=\"%s\",delay=%s,stddev=%s,loss=%s,status=\"%s\",substatus=\"%s\"\n",
|
||||||
$host,
|
$host,
|
||||||
$interface,
|
$interface,
|
||||||
$name,//name is required as it is possible to have 2 gateways on 1 interface. i.e. WAN_DHCP and WAN_DHCP6
|
$name, //name is required as it is possible to have 2 gateways on 1 interface. i.e. WAN_DHCP and WAN_DHCP6
|
||||||
$monitor,
|
$monitor,
|
||||||
$source,
|
$source,
|
||||||
$defaultgw,
|
$defaultgw,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user