Add New DB Column/Table

We have a jack lookup tool available for users at our university. It gives basic information about the network jacks available around campus (e.g. port description, VLAN, speed/duplex, MAC address, etc.) It uses Libre’s DB to find all of that info. We’ve had requests to add a couple of fields (maximum allowed MAC addresses and if sticky MAC’s is enabled). Those OID’s are not polled by default in Libre I couldn’t figure out how to get it to poll for them. So I decided to write a script that polled those. I added two columns to the end of the “ports” table (ifMaxMacAllowed and ifStickyMacEnabled) using the below statements:

ALTER TABLE ports
ADD ifMaxMacAllowed INT NOT NULL;
ALTER TABLE ports
ADD ifStickyMacEnabled CHAR(1) NOT NULL;

My script would then populate all of the new fields with the results from the script after figuring out what row the data belonged in. My script used mysql.connector to connect to the db and run the statements. It would use the below statement to update the row:

UPDATE ports
SET ifMaxMacAllowed = [int], ifStickyMacEnabled = ‘[y/n]’ WHERE ifAlias = [port description] AND ifDescr = [port #]

Everything worked well. All of the rows were updated with the correct data. However, I discovered (a few days later) the MAC addresses from the “ports_fdb” and “ipv4_mac” tables had somehow been deleted. We have been able to repopulate the fields so that part is fine. We reverted everything back to the way it was so it could pass validation.What I don’t know is how/why the MAC addresses were deleted. My script did not poll all of our switches (DC and others were left out), and only the switches polled by my script were affected. I’m not very knowledgeable with DB’s and their design; I just know a little SQL. Should I have done this differently? Any help would be appreciated.

mradams


When asking for help and support, please provide as much information as possible. This should include:

  • Steps to reproduce an issue.
  • The output of ./validate.php

If it’s an issue with the WebUI then please consider including a screenshot and the browser version you are using.

If you are having troubles with discovery/polling include the pastebin output of:

./discovery.php -h HOSTNAME -d | ./pbin.sh
./poller.php -h HOSTNAME -r -f -d | ./pbin.sh

If you need to post any text longer than a few lines, please use a pastebin service such as https://p.libren.ms using non-expiring pastes.

This is because you set NOT NULL without a default value. So when things were attempted to be queried by LibreNMS. The queries generate errors because it doesn’t specify values for those fields and you required them to be NOT NULL. :wink:

Instead of having a separate script, you could alter LibreNMS to poll those OIDs.

1 Like

@murrant Thank you. So if I just set a default value then the MAC addresses won’t be deleted? I still don’t understand how they were deleted in the first place when I never referenced them.

I tried researching adding those OID’s to polling, but I couldn’t figure out how/I didn’t understand how to do it. I’m a network engineer who knows some Python, not a sys admin. Do you know what I need to do to add these OID’s to polling?

Thank you for your help

because it broke the LibreNMS update queries and caused the cleanup code to clean up everything :wink:

I’m a network engineer who has learned some python… and php and others :wink:

You don’t have to be a sys admin to know some thing about code languages. That’s silly :grinning:

1 Like

Never said you did, and my problem probably isn’t really with coding languages. I know Java from college, and Python because it’s used heavily now in networking. I don’t know PHP because it’s never been relevant to my job, or anything I’ve learned. I also don’t know much about maintaining and configuring a server because I’ve never had to do it. Where I work, we’re pretty specialized so I typically only deal with networking, and never have to worry about servers because we have a server team. This is a special case. I just started working on Libre within the past two weeks, and am nowhere near fully familiar with everything, and probably never will be.
Like I said above, all I originally wanted to do was to poll two new OID’s, and have the values saved to the DB. I couldn’t find that documentation, and everything I tried didn’t work.

I defined a default value, and through multiple polling cycles, I haven’t seen any issues.

Thank you.

1 Like