Page 1 of 1

Export current perfdata to csv/excel

Posted: Tue Sep 30, 2014 2:21 pm
by BanditBBS
Any method to export current perf data into a spreadsheet?

For example, one of my disk checks is replyign with this:

Code: Select all

DISK WARNING - free space: /ut1002 98 GB (17% inode=17%); /un1001 18 GB (18% inode=18%); /un1002 17 GB (17% inode=17%);| /=1GB;0;0;0;1 /tmp=1GB;7;8;0;9 /usr=5GB;11;12;0;14 /var=8GB;11;12;0;14 /boot=0GB;0;0;0;0 /dev/shm=0GB;49;55;0;62 /interface=60GB;76;86;0;96 /ua1002=90GB;96;108;0;120 /ua1001=62GB;88;99;0;110 /backupnew=0GB;1167;1313;0;1459 /us1001=38GB;39;44;0;49 /ur1001=218GB;560;630;0;700 /ut1002=451GB;440;495;0;550 /un1001=81GB;79;89;0;99 /un1002=82GB;79;89;0;99 /uc1001=0GB;3;3;0;4 /uf1001=316GB;800;900;0;1000 /ud1007=672GB;720;810;0;900 /ud1008=590GB;720;810;0;900 /ud1010=325GB;720;810;0;900 /ud1011=610GB;720;810;0;900 /ud1012=515GB;720;810;0;900 /backup=0GB;629;708;0;787
We'd like to get all that data into a spreadsheet so we can play with the numbers, any method to do that?

Re: Export current perfdata to csv/excel

Posted: Tue Sep 30, 2014 2:52 pm
by abrist
Echoing that string through a a series of seds would give you a csv:

Code: Select all

echo "<string>" | sed 's/.*|//g' | sed 's/ /\n/g' | sed 's/=/,/g' | sed 's/;/,/g'
Outputs:

Code: Select all

/,1GB,0,0,0,1
/tmp,1GB,7,8,0,9
/usr,5GB,11,12,0,14
/var,8GB,11,12,0,14
/boot,0GB,0,0,0,0
/dev/shm,0GB,49,55,0,62
/interface,60GB,76,86,0,96
/ua1002,90GB,96,108,0,120
/ua1001,62GB,88,99,0,110
/backupnew,0GB,1167,1313,0,1459
/us1001,38GB,39,44,0,49
/ur1001,218GB,560,630,0,700
/ut1002,451GB,440,495,0,550
/un1001,81GB,79,89,0,99
/un1002,82GB,79,89,0,99
/uc1001,0GB,3,3,0,4
/uf1001,316GB,800,900,0,1000
/ud1007,672GB,720,810,0,900
/ud1008,590GB,720,810,0,900
/ud1010,325GB,720,810,0,900
/ud1011,610GB,720,810,0,900
/ud1012,515GB,720,810,0,900
/backup,0GB,629,708,0,787
But I would presume you are looking for a solution in the ui. I wonder if the actions component could do this.

Re: Export current perfdata to csv/excel

Posted: Tue Sep 30, 2014 2:54 pm
by Box293
Have a look at my performance data tool, it displays the data from RRDs into a table.

http://exchange.nagios.org/directory/Ad ... ol/details

Re: Export current perfdata to csv/excel

Posted: Tue Sep 30, 2014 3:20 pm
by BanditBBS
Andy,

Is there a variable I can use inthe actions component to use the most recent perfdata?

Box,
I like that, definitely keeping it installed, but won't work for this project.

Re: Export current perfdata to csv/excel

Posted: Tue Sep 30, 2014 3:32 pm
by abrist
BanditBBS wrote:Is there a variable I can use in the actions component to use the most recent perfdata?
Yep. For hosts: %hostperfdata%
Services: %serviceperfdata%
So you could pass these to a script and then run the seds on the string and then do whatever you want with the string.
Check out the actions component documentation:
http://assets.nagios.com/downloads/nagi ... ponent.pdf

Re: Export current perfdata to csv/excel

Posted: Wed Oct 01, 2014 4:18 pm
by BanditBBS
Prepare for ugliness beyond comparison...
.
.
.
.
You have been warned...
.

Code: Select all

#! /bin/bash
cd /app01/perfdata
mkdir /tmp/disk
ls -ldm1 $1* >> /tmp/disk/folders.txt
while read line
do
        if [ -f /app01/perfdata/$line/Check_Disk.xml ]; then
                temp=$(cat /app01/perfdata/$line/Check_Disk.xml |grep NAGIOS_PERFDATA)
                temp2=",$line"
                echo "$temp" | sed 's/<NAGIOS_PERFDATA>//g' | sed 's/<\/NAGIOS_PERFDATA>//g' |sed "s/ /$temp2\n/g" | sed 's/=/,/g' | sed 's/GB;/,/g' | sed 's/MB;/,/g' | sed 's/;/,/g' >> /tmp/test.csv

        fi
done < /tmp/disk/folders.txt
rm -rf /tmp/disk
That does what I want, the reason for MB and GB removal is one XI box is charting as MB and the other is charting as GB, otherwise if it was mixed I'd keep it. Also, the 1 command line argument I supply is the 3-4 letter code for the customer I want to see the data for.

Close this up, I just posted in case anyone else wants something similar.