alexpmorris / pfsense-status-gateways-json

Module retrieves pfSense 2.x Dashboard Gateway Status and Network Traffic Graphs data in JSON format
MIT License
39 stars 18 forks source link

Lost "wan" interface in the JSON output. #4

Closed Snille closed 7 years ago

Snille commented 7 years ago

Hi, I updated to latest version of pfSense 2.3.4-RELEASE (amd64) Then I lost my "wan" interface in the JSON output.

If I print the "$a_gateways" I get this:

Array ( [VPN_VPNV4] => Array ( [interface] => bge1 [gateway] => dynamic [name] => VPN_VPNV4 [weight] => 1 [ipprotocol] => inet [interval] => [descr] => Interface VPN_VPNV4 Gateway [dynamic] => 1 [monitor] => dynamic [friendlyiface] => lan [attribute] => 0 ) [WAN_DHCP] => Array ( [interface] => bge0 [gateway] => 81.233.82.1 [name] => WAN_DHCP [weight] => 1 [ipprotocol] => inet [interval] => [descr] => Interface WAN_DHCP Gateway [defaultgw] => 1 [dynamic] => 1 [monitor] => 81.233.82.1 [friendlyiface] => wan [attribute] => 1 ) )

But the JSON output is: {"lan":{"inKbps":3864.2620418484,"outKbps":5268.2221868671,"interface":"bge1"}}

Not sure why this happens... Any ideas? :)

Best regards Snille

Snille commented 7 years ago

Looks like the "$gateways_status" variable is just an empty array. Maybe that's why it does not work?

alexpmorris commented 7 years ago

It's possible it's something with a newer version of PHP they're using. I haven't upgraded to the latest pfSense yet so can't check myself right now. But from looking at the latest code, they seem to initialize the variable with array() before calling return_gateways_status():

$gateways_status = array(); $gateways_status = return_gateways_status(true);

Try adding that first line and see if it works for you. If so, I'll update the repo. Thanks!

Reference: https://github.com/pfsense/pfsense/blob/7cdb1ff98361bd352134d78732fb519957803728/src/usr/local/www/status_gateways.php

Snille commented 7 years ago

Nope, still only get the "lan" interface in the json. :(

alexpmorris commented 7 years ago

from their code, really the only other line from pfsense's "status_gateways.php" there is require_once("guiconfig.inc");. Perhaps they changed something that requires that first. Maybe try dropping the following php file into that directory to see if that gives you anything.

testgateways.php:

require_once("guiconfig.inc");
//define('COLOR', true);
$a_gateways = return_gateways_array();
$gateways_status = array();
$gateways_status = return_gateways_status(true);
print_r($gateways_status);
Snille commented 7 years ago

Nope, just an empty array... :( Array ( )

alexpmorris commented 7 years ago

That's really strange then, possible something else is going on then with your setup, because that's the exact code from the pfsense interface! how about when you visit your router's "Status: Gateways" page. Does that show the information, or is it blank too? http://routerip/status_gateways.php

Snille commented 7 years ago

Oh, that gave a hint! :) First I got this when entering the URL: image Then I wounder, is that really right.... So I "restarted" the gateways? (clicked the circle arrow at the top right corner) and then I got this: image And now it works! :)

Sorry for all your troubles... I actually did not know you could restart the "gateways". :)

alexpmorris commented 7 years ago

ok great, glad you finally solved it! hopefully this thread will at least help others who also run into the same issue! 👍