Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAN Interface missing in JSON array... #3

Closed
Snille opened this issue Mar 10, 2017 · 8 comments
Closed

WAN Interface missing in JSON array... #3

Snille opened this issue Mar 10, 2017 · 8 comments

Comments

@Snille
Copy link

Snille commented Mar 10, 2017

Hi! Thank you for this little script.
I'm going to use it on my "MagicMirror" to display the current in/outgoing data rates on my "WAN" interface. However my "WAN" interface does not show up in the json array.
I looks like this (I removed the IP:s):

{
	"lan": {
		"inKbps":867.51528375484,
		"outKbps":7658.2181335538
	},
	"wan_dhcp":{
		"inKbps":0,
		"outKbps":0,
		"name":"wan_dhcp",
		"status":"okay",
		"monitorip":"XXX.XXX.XXX.XXX",
		"sourceip":"XXX.XXX.XXX.XXX",
		"delay":"64.972ms",
		"loss":"4%"
	}
}

Any idea whats going on? :)

Best regards Erik

@alexpmorris
Copy link
Owner

Are you saying that you have a second WAN interface (besides "wan_dhcp") that's not showing? If so, make sure it has a name (not even sure it can't, but just in case). All the script is doing is calling pfsense's return_gateways_status($byname = true). So whatever shows up there should appear in the json:

https://github.com/pfsense/pfsense/blob/master/src/etc/inc/gwlb.inc

The only other thing I can think of is that the script removes the "gw_" header (if there is one), which goes back to the original idea. If there is no name, $pfgateways[$iface]['name'] = $iface; will likely fail and not add to the array.

if (substr($iface,0,3) == "gw_") $iface = substr($iface,3);

@Snille
Copy link
Author

Snille commented Mar 11, 2017

Hi again, no, I don't have another WAN. But the one showing is not showing any traffic. When in fact traffic is both coming in and being sent. :)

PS: In between these posts I had a complete crash of my PfSense box, reinstalled it restored the settings and added the php file again... But same result as above. No traffic on the WAN...

Am I missing something? :)

@alexpmorris
Copy link
Owner

It seems one reason I had removed my "gw_" header is that interface statistics are not returned with it. I believe the "gw_" can be changed, and perhaps your version of "gw_" is "wan_". See if removing that from your interface name solves the problem.

if (substr($iface,0,4) == "wan_") $iface = substr($iface,4);

@Snille
Copy link
Author

Snille commented Mar 12, 2017

Hmm... If I add under the foreach statement the following...

foreach ($gateways_status as $a_gateway) {
  print_r($a_gateway);

This is the (only) array I get:
Is there

Array (
    [monitorip] => 81.233.82.1
    [srcip] => 81.233.82.162
    [name] => WAN_DHCP
    [delay] => 69.481ms
    [stddev] => 43.64ms
    [loss] => 12%
    [status] => loss
)

So, then I added a new line under if ($_GET['rates'] == 1) {:

  if ($_GET['rates'] == 1) {
    $iface = "wan";

Forcing the interface name, and tada! It works. :)
This is the result...

{
  "lan":{
    "inKbps":813.62255664651,
    "outKbps":159.44097443015},
  "wan":{
    "inKbps":247.99436511482,
	"outKbps":47.978611709496,
	"name":"wan",
	"status":"okay",
	"monitorip":"X.X.X.X",
	"sourceip":"X.X.X.X",
	"delay":"51.083ms",
	"loss":"0.0%"
  }
}

Update:
Instead of above, I change the if substr line to this:

  if (substr($iface,3,7) == "_dhcp") $iface = substr($iface,0,3);

It's of course basically the same as "forcing" it to "wan". :)

@Snille Snille closed this as completed Mar 12, 2017
@alexpmorris
Copy link
Owner

Glad you got it working! If you want to try it, to make things simpler I also changed the code slightly to ignore the names altogether and just iterate directly through the "real" interface names em0, em1, etc.

0997338

@Snille
Copy link
Author

Snille commented Mar 12, 2017

Oh, well. That is not the name of my devices actually... :)
I guess that really depends on the hardware you are using.
Mine are called "bge0" (wan) and "bge1" (lan). :)

@alexpmorris
Copy link
Owner

I gave it one last try. I think this version should hopefully solve the problem for good! Seems em is used for intel, and bge for broadcom chipsets. But with this new version, none of it should matter since I should be accessing the correct names directly. It also shows you all the names, interfaces, etc for reference.

bb030e4

@Snille
Copy link
Author

Snille commented Mar 14, 2017

Hi again, looking good. :) Now it works without any alterations. Great work!
Thank you.

Result:

{
	"lan": {
		"inKbps":200.06687090799,
		"outKbps":553.31116912934,
		"interface":"bge1"
	},
	"wan": {
		"inKbps":1074.477155649,
		"outKbps":376.96074702806,
		"interface":"bge0",
		"friendlyiface":"wan",
		"name":"WAN_DHCP",
		"status":"okay",
		"monitorip":"X.X.X.X",
		"sourceip":"X.X.X.X",
		"delay":"40.233ms",
		"loss":"2%"
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants