I only changed the gateway variable to: SHOW TAG VALUES FROM "gateways" WITH KEY = "gateway_name" WHERE "host" =~ /^$Host$/ Changed group by on Gateway RTT and Gateway Loss charts to gateway_name Added gateway_name to Gateway Summary. Added interface to this list so both gateway_name and interface can be seen. telegraf --test --config /usr/local/etc/telegraf.conf before: > gateways,host=fw.anson.lan,interface=igb0 defaultgw=1,delay=0,gwdescr="Interface WAN_DHCP Gateway",loss=100,monitor="192.168.0.1",source="192.168.0.30",status="down",stddev=0,substatus="highloss" 1620242074000000000 > gateways,host=fw.anson.lan,interface=igb0 defaultgw=0,delay=0,gwdescr="Interface WAN_DHCP6 Gateway",loss=0,monitor="",source="",status="",stddev=0,substatus="N/A" 1620242074000000000 The changes to the telegraf output can be seen below: telegraf --test --config /usr/local/etc/telegraf.conf after: > gateways,gateway_name=WAN_DHCP,host=fw.anson.lan,interface=igb0 defaultgw=1,delay=0,gwdescr="Interface WAN_DHCP Gateway",loss=100,monitor="192.168.0.1",source="192.168.0.30",status="down",stddev=0,substatus="highloss" 1620242589000000000 > gateways,gateway_name=WAN_DHCP6,host=fw.anson.lan,interface=igb0 defaultgw=0,delay=0,gwdescr="Interface WAN_DHCP6 Gateway",loss=0,monitor="",source="",status="",stddev=0,substatus="N/A" 1620242589000000000
136 lines
3.2 KiB
PHP
Executable File
136 lines
3.2 KiB
PHP
Executable File
#!/usr/local/bin/php-cgi -f
|
|
<?php
|
|
require_once("config.inc");
|
|
require_once("gwlb.inc");
|
|
require_once("interfaces.inc");
|
|
|
|
$host = gethostname();
|
|
$source = "pfconfig";
|
|
|
|
$iflist = get_configured_interface_with_descr(true);
|
|
foreach ($iflist as $ifname => $friendly) {
|
|
$ifinfo = get_interface_info($ifname);
|
|
$ifstatus = $ifinfo['status'];
|
|
$ifconf = $config['interfaces'][$ifname];
|
|
$ip4addr = get_interface_ip($ifname);
|
|
$ip4subnet = get_interface_subnet($ifname);
|
|
$ip6addr = get_interface_ipv6($ifname);
|
|
$ip6subnet = get_interface_subnetv6($ifname);
|
|
$realif = get_real_interface($ifname);
|
|
$mac = get_interface_mac($realif);
|
|
|
|
if (!isset($ip4addr)){
|
|
$ip4addr = "Unassigned";
|
|
}
|
|
if (!isset($ip4subnet)){
|
|
$ip4subnet = "Unassigned";
|
|
}
|
|
if (!isset($ip6addr)){
|
|
$ip6addr = "Unassigned";
|
|
}
|
|
if (!isset($ip6subnet)){
|
|
$ip6subnet = "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 = 2;
|
|
}
|
|
|
|
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,
|
|
$realif,
|
|
$ip4addr,
|
|
$ip4subnet,
|
|
$ip6addr,
|
|
$ip6subnet,
|
|
$mac,
|
|
$friendly,
|
|
$source,
|
|
$ifstatus
|
|
);
|
|
}
|
|
|
|
$gw_array = return_gateways_array();
|
|
$gw_statuses = return_gateways_status(true);
|
|
|
|
$debug = false;
|
|
|
|
if($debug){
|
|
print_r($a_gateways);
|
|
print_r($gateways_status);
|
|
}
|
|
|
|
foreach ($gw_array as $gw => $gateway) {
|
|
|
|
//take the name from the $a_gateways list
|
|
$name = $gateway["name"];
|
|
|
|
//$gateways_status is not guarranteed to contain the same number of gateways as $a_gateways
|
|
|
|
$monitor = $gw_statuses[$gw]["monitorip"];
|
|
$source = $gw_statuses[$gw]["srcip"];
|
|
$delay = $gw_statuses[$gw]["delay"];
|
|
$stddev = $gw_statuses[$gw]["stddev"];
|
|
$loss = $gw_statuses[$gw]["loss"];
|
|
$status = $gw_statuses[$gw]["status"];
|
|
$substatus;
|
|
|
|
$interface = $gateway["interface"];
|
|
$friendlyname = $gateway["friendlyiface"]; # This is not the friendly interface name so I'm not using it
|
|
$friendlyifdescr = $gateway["friendlyifdescr"];
|
|
$gwdescr = $gateway["descr"];
|
|
$defaultgw = $gateway['isdefaultgw'];
|
|
|
|
if (isset($gateway['isdefaultgw'])) {
|
|
$defaultgw = "1";
|
|
} else {
|
|
$defaultgw = "0";
|
|
}
|
|
|
|
if ($gw_statuses[$gw]) {
|
|
if (isset($gateway['monitor_disable'])) {
|
|
$monitor = "Unmonitored";
|
|
$delay = "Pending";
|
|
$stdev = "Pending";
|
|
$loss = "Pending";
|
|
}
|
|
}
|
|
|
|
// Some earlier versions of pfSense do not return substatus
|
|
if (isset($gw_statuses[$gw]["substatus"])) {
|
|
$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",
|
|
$host,
|
|
$interface,
|
|
$name,//name is required as it is possible to have 2 gateways on 1 interface. i.e. WAN_DHCP and WAN_DHCP6
|
|
$monitor,
|
|
$source,
|
|
$defaultgw,
|
|
$gwdescr,
|
|
floatval($delay),
|
|
floatval($stddev),
|
|
floatval($loss),
|
|
$status,
|
|
$substatus
|
|
);
|
|
};
|
|
?>
|