So we run multiple networks at work, and I inadvertently enabled discovery polling of devices. We use a separate system to monitor servers, but Libre to monitor core network devices.
Is there any way to mass delete these devices that have been autodiscovered? There’s hundreds of them!
Nope its really easy to do it on command line though.
if you don’t want to make a bash loop, then load up a spreadsheet with all your devices IPs in, just affix ./delhost to a new column before the IPs and copy paste the whole thing into prompt.
Note if your using the autodiscovery in librenms, then they will be re-added automagically so you may want to turn that feature off.
Putting in a text file the names of the host to be deleted: Execute next command in shell:
mysql -u root -p librenms_database_name -e "select hostname from devices where hostname like ‘your_hostname-matching_criteria’ into outfile ‘name_of_the_text_file’ ;"
(you will be asked for user password)
(your_hostname_matchng_criteria: follow the select like syntax)
Proceed with deletion: as root (use sudo if needed) execute in bash:
for i in cat name_of_the_text_file; do sudo /opt/librenms/delhost.php $i; done
Thats’s all. Take into account:
librenms: this is the name of librenms database. Change as appropriate.
name_of_the_text_file: you can use any file name and it will be stored into the database directory. Be carefull to don’t overwrite database or other existing files or your db will become broken…
To do it easier, put the next lines in a bash script and execute it: