Fetching a Daily Opennms Hardware Report

Posted by – June 27, 2008

The code below shows how can you retrieve a daily hardware report from opennms server, you can change this script to fetch the hardware report of several days without care if the current day is the first os last day of month because the date range is calculated in seconds and not based on math operations in day of month.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

#Just testing if the user has supplied the ip address of server
#to get hardware statistics
if [ "$1d" != "d" ]; then

   DAY=`date +%d`
   MONTH=`date +%m`
   YEAR=`date +%Y`
 
   #Getting the number of seconds ellapsed at the end of
   #current day
   TODAY=`date --date="$MONTH/$DAY/$YEAR 23:59:59" +%s`

   #You can expand the date range by multiplying the number
   #of second in each day by number of days
   DAY_START=`expr $TODAY - 86400`
   DAY_END=`expr $TODAY`

   echo Retrieving statistics...
 
   #Retrieving opennms hardware report based on the
   #date range calculated above
   eval "wget --no-check-certificate
        --http-user=user --http-passwd=password
        -O /my/reports/summary_$CURRENT_DAY$CURRENT_MONTH$CURRENT_YEAR.xml 'https://my.opennm.server/opennms/summary/results.htm?filterRule=ipaddr+iplike+$1&startTime=$DAY_START&endTime=$DAY_END&attributeSieve=.*'"

else
   echo You must provide the ip address of target machine!
fi
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>