Webtop dashboard

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
nareshbtech
Posts: 5
Joined: Tue Aug 26, 2014 6:51 am

Webtop dashboard

Post by nareshbtech »

Dear all

is there a way to display nagios alerts in pi charts based on groups as shown below

Image

please guide me

thanks

Moderator Note: I have moved your thread to the Nagios Core section
nareshbtech
Posts: 5
Joined: Tue Aug 26, 2014 6:51 am

Re: Webtop dashboard

Post by nareshbtech »

i found this wil get the data but will be an amature way
write a custom php were we graph the data that fetched from status.cgi
i am able to see the data of service totals with the filter of hostgoroup

http://nagios-host/nagios/cgi-bin/statu ... nux-server
and extract the values from the table
td class='serviceTotalsOK'>3381
td class='serviceTotalsWARNING'>57
td class='serviceTotalsUNKNOWN'>93
td class='serviceTotalsCRITICAL'>441
td class='serviceTotals'>0


whwere we can graph this data using any plotter

but by this way we are fetching full html page is there a better way to do this
please suggest

thank you
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Webtop dashboard

Post by sreinhardt »

Are you on core 4.0.x? If so, you can certainly use the json interface. Otherwise scraping web pages, status.dat or retention.dat are about the options you have, unless you want to write C to build into a new module for core.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Webtop dashboard

Post by abrist »

Just to reinforce Spenser's suggestion: The JSON CGIs are the one true way (among others :P ). If you have core 4, browse to the following url to play with the GET query options:

Code: Select all

http://<nagios ip>/nagios/jsonquery.html
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
nareshbtech
Posts: 5
Joined: Tue Aug 26, 2014 6:51 am

Re: Webtop dashboard

Post by nareshbtech »

Thanx abrait , sreinhardt

i have used scrapping method as fo now should impriove min


here is my script with makes the data.csv where we have the alert summuray data

Code: Select all

#! /usr/bin/env python
import urllib2
import sys
import csv
from bs4 import BeautifulSoup
SERVER = sys.argv[1]
authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
authinfo.add_password(None, SERVER, 'nagiosadmin', 'xxxxx')
page = sys.argv[1]
handler = urllib2.HTTPBasicAuthHandler(authinfo)
myopener = urllib2.build_opener(handler)
opened = urllib2.install_opener(myopener)
output = urllib2.urlopen(page)
soup = BeautifulSoup(output)




table = soup.find("table", { "class" : sys.argv[2] })
headers = [header.text for header in table.find_all('th')]
rows = []
for row in table.find_all('tr'):
      rows.append([val.text.encode('utf8') for val in row.find_all('td')])

with open('data.dat', 'wb') as f:
     writer = csv.writer(f)
     writer.writerow(headers)
     writer.writerows(row for row in rows if row)


with open('data.dat') as f:
    reader = csv.reader(f)
    cols = []
    for row in reader:
        cols.append(row)

with open('data.csv', 'wb') as f:
    writer = csv.writer(f)
    for i in range(len(max(cols, key=len))):
        writer.writerow([(c[i] if i<len(c) else '') for c in cols])

in this script i pass two variables one is the URL and other is the group

now to genereate the graph i am using gnuplot

Code: Select all

#!/usr/bin/gnuplot
reset
set terminal png
set yrange [0:]
set style fill solid
set boxwidth 1 absolute
set xtic scale 0
set datafile separator ","
set term png
set output hist
upROW(x,y)=(x eq "Up") ? y:1/0
UnrROW(x,y) =(x eq "Unreachable") ? y:1/0
dwnROW(x,y) =(x eq "Down") ? y:1/0
PenROW(x,y) =(x eq "Pending") ? y:1/0
plot data u ($0):(PenROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "gray" ti "pen" , '' u ($0):(UnrROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "black" ti "UnRch" , '' u ($0):(dwnROW(stringcolumn(1),$2)):xtic(1) w boxes lc rgb "red" ti "Down"
the output is
Image


Thank you any suggestions are helpfull
Attachments
nag-aps-linux-servers-srv.png
nag-aps-linux-servers-srv.png (5.92 KiB) Viewed 5853 times
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Webtop dashboard

Post by slansing »

What is your next question? It looks like you are plotting it fine, are you having troubles with something else? I'm not sure what you are using in your initial image, if that is what you are trying to re-produce.
nareshbtech
Posts: 5
Joined: Tue Aug 26, 2014 6:51 am

Re: Webtop dashboard

Post by nareshbtech »

Hi, slansing

Thx yes the present setups if fine
but i just want to provide a solution for any one who refers this port in future

and my next target is to display alerts from the past defined time (say 24hrs) to have more granularity
and hence i think i have to use jason status cgi with filters "Host Time Field" set to "laststatechanve"

the issue is when i give the start and end time its not tatking the values

Program_start": 1408733527000,
"last_data_update": 1409486951000

acc to the jason querry the format should be "MM-DD-YYYY HH:MI" but now working any suggestions


[link removed]
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Webtop dashboard

Post by abrist »

Those values seem a bit big for unix time (in seconds). You most likely need to divide them by 1000 before submitting the time (as javascript timestamps are is ms instead of secs).
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
nareshbtech
Posts: 5
Joined: Tue Aug 26, 2014 6:51 am

Re: Webtop dashboard

Post by nareshbtech »

as discussed used json status cgi to get the same values
the script is similar and the time stamps are generated for the past 6 hrs

now=`date +%s`
prev=`date -d "6 hours ago" +%s`
python jason.py "http://$f1/nagios/cgi-bin/statusjson.cgi?query=hostcount&hostgroup=$f2&hosttimefield=lasthardstatechange&starttime=$prev&endtime=$now"

cat jason.py
#!/usr/bin/python

import urllib2
import csv, json, sys
SERVER = sys.argv[1]
authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
authinfo.add_password(None, SERVER, 'nagiosadmin', 'xxxxxxxxxxx')
page = SERVER
handler = urllib2.HTTPBasicAuthHandler(authinfo)
myopener = urllib2.build_opener(handler)
opened = urllib2.install_opener(myopener)
output = urllib2.urlopen(page)
html = output.read()
with open("Output.txt", "w") as text_file:
text_file.write(html)

Image
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Webtop dashboard

Post by abrist »

Time/date objects in Javascript include the milliseconds. The cgis use seconds for GET args. So when you eval the json from the cgis, it will use mills, but when you submit a time back, you need to divide by 1000.
What are the current issues?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked