While remove the services automatically rrd and xml files

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
udaykumar
Posts: 66
Joined: Thu Jan 11, 2018 12:55 am

While remove the services automatically rrd and xml files

Post by udaykumar »

Hi Team,
While we remove the services from nagiosxi automatically rrd and xml files should be deleted which are associated host. But as we observed in /usr/local/nagios/share/perdata/xxx/.rrd and xml files are still exist.

could you please suggest what we have do to remove automatically all these files.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: While remove the services automatically rrd and xml file

Post by lmiltchev »

We had an internal feature request on adding this functionality in Nagios XI, but the task got canceled. I am not sure why is that. Perhaps, there was not enough interest from users. In any case, the decision to implement the enhancement is at the sole discretion of our development team.

Having said that, you could automatically remove the RRDs upon host/service deletion via the Deadpool.
example01.PNG
This is the only way to do this (I can think of). You can read more on Deadpool here:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Hope this helps.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: While remove the services automatically rrd and xml file

Post by ssax »

I think this should probably work for you:

*** Take an XI backup/VM snapshot/file level backups first so that you can undo your changes if neccessary, just in case.

See here:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Code: Select all

#!/bin/bash
# Set some vars
perfdata_dir='/usr/local/nagios/share/perfdata'
cutoff_days=5

echo 'WARNING: This script will delete all RRDs (and their respective XML files) under /usr/local/nagios/share/perfdata'
echo '         that have not been written to in 5 days, that also includes hosts/services that have been DOWN for more'
echo '         than 5 days, please be aware of that limitation.'
echo
echo '         Please take an XI backup and/or a filesystem level backup first, just in case, see here for more information:'
echo
echo '         https://assets.nagios.com/downloads/nagiosxi/docs/Backing-Up-And-Restoring-Nagios-XI.pdf'
echo
read -r -p "Are you sure you want to continue? [y/N] " ok

case "$ok" in
    Y | y ) :
        echo 'Starting Deletion'
        # Get a list of RRDs that haven't had mtime updated in $cutoff_days
        rrd_array=($(find $perfdata_dir -type f -name "*.rrd" -mtime +$cutoff_days))

        # Loop through and delete all .rrd and .xml files
        for i in "${rrd_array[@]}"; do
            # Ignore .pnp-internal directory
            if [[ $i == *".pnp-internal"* ]]; then
                continue;
            fi

            # Do the deletion of RRD and XML files
            echo "Deleting: $i"
            \rm -f "$i"
            echo "Deleting: ${i/rrd/xml}"
            \rm -f "${i/rrd/xml}"
        done
        echo "Done"
        exit 0
        ;;
    * )     exit 1
esac
** WARNING, the above would also delete RRDs for hosts and services that have been down for more than 5 days **
Last edited by ssax on Tue Sep 10, 2019 1:53 pm, edited 2 times in total.
Reason: Add warning, added warning to script
Locked