-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Rewrite broken netonix.inc.php #7189
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is absolutely fine. It does look prime for switching over to the new YAML format - do you fancy doing that? If not I can provide the file for you to try.
@@ -19,32 +19,29 @@ | |||
* | |||
* @package LibreNMS | |||
* @link http://librenms.org | |||
* @copyright 2016 Tony Murray | |||
* @author Tony Murray <murraytony@gmail.com> | |||
* @copyright 2017 Andrew Holmes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should append your copyright rather than removing the old one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure about that - but this makes more sense, and is why I asked :)
I can give YAML a try - it looks pretty simple, and is making me annoyed that I spent all this time on the PHP version. I'm not quite sure which variables go where, though; I've gotten this far...
I think I've got that mostly right? Unsure which bits are configurable / which are set elsewhere... It may be helpful to put up one of the examples on the wiki in the form of the other language; would ease translating between the two for someone less familiar with either :P |
Looks good, just need to use: If you remove the php discovery file Then re-run discovery, the sensors should persist. If they do it works, if they don't then something is up :) |
Hmm, this has not worked. I must have broken something... I was missing one section of the YAML, too. Before I sit here throwing modifications back and forth, here's where I got;
This shows up when it caches the SNMP;
But when it gets to the actual sensor discovery, this is all I get;
I must be missing something about how this is meant to work; is there a definition-of-the-definitions I can look at anywhere? For reference, here's what the table looks like in iReasoning MIB Browser. The table itself is .1.3.6.1.4.1.46242.5. and port statuses are found at .1.3.6.1.4.1.46242.5.1.2.portnumber What am I doing wrong? :( |
Are the states still in the webui? If so, that output looks ok, it will do a mysql query to check the sensor exists and if it does it will continue on without doing anything else - that's expected as the php file would have discovered the sensors and now the yaml will just carry on. If they've dropped then yes, something is wrong and we'd need to see the debug output - or if you want we can just merge this in as is for now? |
The "state" sensor section has evaporated entirely from the webUI - and the first time I ran discovery with the .yaml in place, it gave me a nice slab of -s next to the sensor output to show it deleting them - it's getting far enough to cache the OID, but not far enough to generate the sensor defs :( I'm happy to merge it in as-is - but I would like to work out why YAML isn't working... |
@neg2led pastebin the output of |
Sure thing; it's here |
I think it's because we don't get a numeric value back :/ What does this show:
|
Indeed, each port index just returns the status string;
|
So I assume this never worked then? It will need a custom poller file writing as well to translate the description to a numerical value. |
The original file in the master branch never worked, no - the SNMPget commands used an invalid OID that never loaded. But the file I've added here works - is that weird? With this file in place, and the yaml removed, when I run discovery they show up as you can see here And when I run the poller, they poll, though it looks kind of odd |
Let's just go with your php version :) |
So if you can update the copyright we can merge in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
Hmm, the original file worked for me. However, it looks like they added the 24VH and 48VH after that code was developed. Renaming the state loses the history, is that required to add 24VH and 48VH? @laf the state sensor code will map string values to numeric values. |
I made no changes to the install other than this file to make this work - should I have to add a MIB to my conf? The commands used by libre specify alternate MIB dirs anyway, no? This system is an otherwise-blank Ubuntu 16.04 system with nginx/mariadb that does nothing but run libre - built with the instructions on the main site - would you not expect that to work without modification to snmp.conf? With the existing discovery module, discovery goes like this - As you can see, the discovery bulkwalk goes fine, but when it goes to insert the sensors into the database, the SNMP OID it uses has the .1.3.6.1.4. section repeated at the start;
So when we get to running the poller it tries to pull data from an OID that doesn't exist, and fails miserably;
When run with this file in place discovery looks quite a bit happier;
And the poller works;
While stressing that I'm still struggling to wrap my head around PHP arrays, the difference seems to be due to this bit of code in the original (lines 27/28); librenms/includes/discovery/sensors/state/netonix.inc.php Lines 27 to 28 in 30c1b79
When you get to the end and it creates the actual sensors, it lands up concatenating $cur_oid with $index - which at this point is ".3.6.1.4.1.46242.5.1.2.portnumber", apparently?
Which at this point spits out the string we see above in discovery, likely because
should look more like this as per the doco; This change alone is actually enough to fix the original file - save for the fact that 24VH and 48VH are missing from the state table - but I rewrote the rest of it to match the docu style so that I actually understood what I was doing Sorry for the wall of text! I hope this makes sense. If I had to guess, I'd say it works on your system because you have the MIB installed globally - so it gets translated to the text form in snmpwalk's output even though no MIB is specified in the actual command/routine? |
RE: renaming the state - it shouldn't be necessary, but currently the discovery file checks for a state map with $NAME & creates it if it doesn't exist; so if it already exists, nothing is done, and the two new states aren't added to the table.
L33 creates a state table for state $NAME So if $NAME already exists, no creation code. It seems like it should be fairly simple to add some sanity-checking (check how many states are in the table and recreate if != 5?) but I don't have enough confidence in my PHP-fu to know where to start (for fear of trashing my DB) |
@neg2led I never said it doesn't work for you, just that it was working for devices that don't have 24VH and 48VH. I worked a bit last night and fixed the yaml code for this. I am changing the code so it will update the translation states too. |
@neg2led Can you test murrants PR with the yaml file you created? |
@murrant sounds great to me - much more elegant than my fix :) I've applied the changes from #7221 to my system and added this file
as includes/definitions/discovery/netonix.yaml, and sure enough, it works great :) discovery looks like this and polling looks like this What's the next step here - should I close this PR and create a new one to add the yaml (maybe after 7221 is merged?) |
You can just change this PR to revert the other changes and include the yaml file. We will merge it after the other PR. (which needs some more testing to make sure it doesn't break other sensors) My hint is |
I... have made an error. Goddamnit, Git. Lemme fix that... |
no worries :) |
The inspection completed: No new issues |
Alright, I made enough of a hash of this (and closed it?!) that I'm just going again. I tried to be smart, and it did not pay off... See #7224 |
This thread has been automatically locked since there has not been any recent activity after it was closed. |
Please let me know if there's anything I've done wrong here, I'm still new to contributing to projects like these.
Rewrote netonix.inc.php to account for all 5 states & follow coding style of other state modules.
The existing netonix.inc.php file does not correctly map all 5 possible PoE states, and doesn't match the coding style / template used in other sensor state files. There's a forum report here about this that's apparently been missed :(
The original file only allows for 3 states, Off / 24V / 48V, mapped to values 1/2/3 respectively, but there are 5 possible states for outputs;
The 24VH/48VH modes are "High Power" mode, aka 4-pair PoE, where all 4 pairs of the cable are used to supply power. The vast majority of PoE devices do not use this; it's mostly found on wireless equipment such as Ubiquiti AirFiber radios, and if used with an incompatible device will usually fry the port & device; but these are, after all, netonix WISP switches.
I've recreated the state index as follows, and rewritten the file to follow the standard format. Please let me know if I should credit the original author; as this was written from scratch by following the documentation, no code is copied - though one line came out identical (string concat)
This maintains compatibility with any existing alert rules, while adding the two extra states required. The generic state of all states other than "Off" has been set to 0 (could easily be convinced to make the VH states 1/warn) while "Off" is at -1 as per convention.
I've changed the name of the state index from netonixPoeStatus to netonixPoeState as I had issues with the code not updating the state index. I'm unsure how to clean this up; as a result of my testing I actually have three separate indexes... If someone could let me know how to purge the old, broken index, that'd be great...
Pre-commit results;
DO NOT DELETE THIS TEXT
Please note
Testers
If you would like to test this pull request then please run:
./scripts/github-apply <pr_id>
, i.e./scripts/github-apply 5926