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
@ -9,59 +9,70 @@ $source = "pfconfig";
|
|||||||
|
|
||||||
$iflist = get_configured_interface_with_descr(true);
|
$iflist = get_configured_interface_with_descr(true);
|
||||||
foreach ($iflist as $ifname => $friendly) {
|
foreach ($iflist as $ifname => $friendly) {
|
||||||
$ifinfo = get_interface_info($ifname);
|
$ifinfo = get_interface_info($ifname);
|
||||||
$ifstatus = $ifinfo['status'];
|
$ifstatus = $ifinfo['status'];
|
||||||
$ifconf = $config['interfaces'][$ifname];
|
$ifconf = $config['interfaces'][$ifname];
|
||||||
$ip4addr = get_interface_ip($ifname);
|
$ip4addr = get_interface_ip($ifname);
|
||||||
$ip4subnet = get_interface_subnet($ifname);
|
$ip4subnet = get_interface_subnet($ifname);
|
||||||
$ip6addr = get_interface_ipv6($ifname);
|
$ip6addr = get_interface_ipv6($ifname);
|
||||||
$ip6subnet = get_interface_subnetv6($ifname);
|
$ip6subnet = get_interface_subnetv6($ifname);
|
||||||
$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";
|
$ifstatus = 1;
|
||||||
}
|
}
|
||||||
if (!isset($ip6addr)){
|
if (strtolower($ifstatus) == "active") {
|
||||||
$ip6addr = "Unassigned";
|
$ifstatus = 1;
|
||||||
}
|
}
|
||||||
if (!isset($ip6subnet)){
|
if (strtolower($ifstatus) == "no carrier") {
|
||||||
$ip6subnet = "Unassigned";
|
$ifstatus = 0;
|
||||||
}
|
}
|
||||||
if (!isset($mac)){
|
if (strtolower($ifstatus) == "down") {
|
||||||
$mac = "Unavailable";
|
$ifstatus = 0;
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "up"){
|
if (!isset($ifstatus)) {
|
||||||
$ifstatus = 1;
|
$ifstatus = 2;
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "active"){
|
if (!isset($ifconf)) {
|
||||||
$ifstatus = 1;
|
$ifconf = "Unassigned";
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "no carrier"){
|
if (!isset($ip4addr)) {
|
||||||
$ifstatus = 0;
|
$ip4addr = "Unassigned";
|
||||||
}
|
}
|
||||||
if (strtolower($ifstatus) == "down"){
|
if (!isset($ip4subnet)) {
|
||||||
$ifstatus = 0;
|
$ip4subnet = "0";
|
||||||
}
|
}
|
||||||
if (!isset($ifstatus)){
|
if (!isset($ip6addr)) {
|
||||||
$ifstatus = 2;
|
$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",
|
|
||||||
$host,
|
printf(
|
||||||
$realif,
|
"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",
|
||||||
$ip4addr,
|
$host,
|
||||||
$ip4subnet,
|
$realif,
|
||||||
$ip6addr,
|
$ip4addr,
|
||||||
$ip6subnet,
|
$ip4subnet,
|
||||||
$mac,
|
$ip6addr,
|
||||||
$friendly,
|
$ip6subnet,
|
||||||
$source,
|
$mac,
|
||||||
$ifstatus
|
$friendly,
|
||||||
);
|
$source,
|
||||||
|
$ifstatus
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$gw_array = return_gateways_array();
|
$gw_array = return_gateways_array();
|
||||||
@ -70,65 +81,92 @@ $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);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($gw_array as $gw => $gateway) {
|
foreach ($gw_array as $gw => $gateway) {
|
||||||
|
|
||||||
//take the name from the $a_gateways list
|
//take the name from the $a_gateways list
|
||||||
$name = $gateway["name"];
|
$name = $gateway["name"];
|
||||||
|
|
||||||
$monitor = $gw_statuses[$gw]["monitorip"];
|
$monitor = $gw_statuses[$gw]["monitorip"];
|
||||||
$source = $gw_statuses[$gw]["srcip"];
|
$source = $gw_statuses[$gw]["srcip"];
|
||||||
$delay = $gw_statuses[$gw]["delay"];
|
$delay = $gw_statuses[$gw]["delay"];
|
||||||
$stddev = $gw_statuses[$gw]["stddev"];
|
$stddev = $gw_statuses[$gw]["stddev"];
|
||||||
$loss = $gw_statuses[$gw]["loss"];
|
$loss = $gw_statuses[$gw]["loss"];
|
||||||
$status = $gw_statuses[$gw]["status"];
|
$status = $gw_statuses[$gw]["status"];
|
||||||
$substatus;
|
$substatus;
|
||||||
|
|
||||||
$interface = $gateway["interface"];
|
$interface = $gateway["interface"];
|
||||||
$friendlyname = $gateway["friendlyiface"]; # This is not the friendly interface name so I'm not using it
|
$friendlyname = $gateway["friendlyiface"]; # This is not the friendly interface name so I'm not using it
|
||||||
$friendlyifdescr = $gateway["friendlyifdescr"];
|
$friendlyifdescr = $gateway["friendlyifdescr"];
|
||||||
$gwdescr = $gateway["descr"];
|
$gwdescr = $gateway["descr"];
|
||||||
$defaultgw = $gateway['isdefaultgw'];
|
$defaultgw = $gateway['isdefaultgw'];
|
||||||
|
|
||||||
if (isset($gateway['isdefaultgw'])) {
|
if (!isset($monitor)) {
|
||||||
$defaultgw = "1";
|
$monitor = "Unavailable";
|
||||||
} else {
|
}
|
||||||
$defaultgw = "0";
|
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 ($gw_statuses[$gw]) {
|
if (isset($gateway['isdefaultgw'])) {
|
||||||
if (isset($gateway['monitor_disable'])) {
|
$defaultgw = "1";
|
||||||
$monitor = "Unmonitored";
|
} else {
|
||||||
$delay = "Pending";
|
$defaultgw = "0";
|
||||||
$stdev = "Pending";
|
}
|
||||||
$loss = "Pending";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some earlier versions of pfSense do not return substatus
|
if (isset($gateway['monitor_disable'])) {
|
||||||
if (isset($gw_statuses[$gw]["substatus"])) {
|
$monitor = "Unmonitored";
|
||||||
$substatus = $gw_statuses[$gw]["substatus"];
|
}
|
||||||
} else {
|
|
||||||
$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",
|
// Some earlier versions of pfSense do not return substatus
|
||||||
$host,
|
if (isset($gw_statuses[$gw]["substatus"])) {
|
||||||
$interface,
|
$substatus = $gw_statuses[$gw]["substatus"];
|
||||||
$name,//name is required as it is possible to have 2 gateways on 1 interface. i.e. WAN_DHCP and WAN_DHCP6
|
} else {
|
||||||
$monitor,
|
$substatus = "N/A";
|
||||||
$source,
|
}
|
||||||
$defaultgw,
|
|
||||||
$gwdescr,
|
printf(
|
||||||
floatval($delay),
|
"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",
|
||||||
floatval($stddev),
|
$host,
|
||||||
floatval($loss),
|
$interface,
|
||||||
$status,
|
$name, //name is required as it is possible to have 2 gateways on 1 interface. i.e. WAN_DHCP and WAN_DHCP6
|
||||||
$substatus
|
$monitor,
|
||||||
);
|
$source,
|
||||||
|
$defaultgw,
|
||||||
|
$gwdescr,
|
||||||
|
floatval($delay),
|
||||||
|
floatval($stddev),
|
||||||
|
floatval($loss),
|
||||||
|
$status,
|
||||||
|
$substatus
|
||||||
|
);
|
||||||
};
|
};
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user