forked from VictorRobellini/pfSense-Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelegraf_pfifgw.php
executable file
·180 lines (161 loc) · 4.24 KB
/
telegraf_pfifgw.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/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($ifinfo)) {
$ifinfo = "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;
}
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",
$host,
$realif,
$ip4addr,
$ip4subnet,
$ip6addr,
$ip6subnet,
$mac,
$friendly,
$source,
$ifstatus
);
}
$gw_array = return_gateways_array();
//$gw_statuses is not guarranteed to contain the same number of gateways as $gw_array
$gw_statuses = return_gateways_status(true);
$debug = false;
if($debug){
print_r($gw_array);
print_r($gw_statuses);
}
foreach ($gw_array as $gw => $gateway) {
//take the name from the $a_gateways list
$name = $gateway["name"];
$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($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";
$status_code = "2";
} elseif ($status == "online") {
$status_code = "0";
} elseif ($status == "down") {
$status_code = "1";
}
if (!isset($interface)) {
$interface = "Unassigned";
}
if (!isset($friendlyname)) {
$friendlyname = "Unassigned";
}
if (!isset($friendlyifdescr)) {
$friendlyifdescr = "Unassigned";
}
if (!isset($gwdescr)) {
$gwdescr = "Unassigned";
}
if (isset($gateway['isdefaultgw'])) {
$defaultgw = "1";
} else {
$defaultgw = "0";
}
if (isset($gateway['monitor_disable'])) {
$monitor = "Unmonitored";
}
// 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\",status_code=%d,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,
$status_code,
$substatus
);
};
?>