Imported Upstream version 4.3.2

This commit is contained in:
Mario Fetka 2017-05-19 23:37:19 +02:00
parent 25c8be1dce
commit 7faf575ca1
443 changed files with 66003 additions and 48681 deletions

25
.gitignore vendored
View File

@ -9,11 +9,34 @@ config.log
config.status config.status
daemon-init daemon-init
Makefile Makefile
tags
.deps/ .deps/
.libs/ .libs/
nbproject/
.kdev4/
.settings/
.cproject
.project
*.kdev4
*.o *.o
*.la *.la
*.lo *.lo
*.gcda *.gcda
*.gcno *.gcno
/gmon.out *.gcov
*.a
*.so
cgi/run*
gmon.out
core.[1-9]*
/Documentation
*.pre-indent
*.swp
html/angularjs/angular-1.3.9
html/angularjs/ui-utils-0.2.1
html/bootstrap-3.3.0
html/d3
html/index.php

1045
Changelog

File diff suppressed because it is too large Load Diff

9
LEGAL
View File

@ -1,3 +1,12 @@
Copyright(c) 1999-2009:
Ethan Galstad <egalstad@nagios.org>
Copyright(c) 2009 until further notice:
Nagios Core Development Team and Nagios Community Contributors
For detailed authorship information, refer to the source control
management history and pay particular attention to commit messages
and the THANKS file.
All source code, binaries, documentation, information, and other files All source code, binaries, documentation, information, and other files
contained in this distribution are provided AS IS with NO WARRANTY OF contained in this distribution are provided AS IS with NO WARRANTY OF

View File

@ -1,12 +1,12 @@
############################### ###############################
# Makefile for Nagios # Makefile for Nagios
# #
# Last Modified: 04-13-2008
############################### ###############################
# Source code directories # Source code directories
SRC_BASE=@srcdir@/base SRC_BASE=@srcdir@/base
SRC_LIB=@srcdir@/lib
SRC_CGI=@srcdir@/cgi SRC_CGI=@srcdir@/cgi
SRC_HTM=@srcdir@/html SRC_HTM=@srcdir@/html
SRC_MODULE=@srcdir@/module SRC_MODULE=@srcdir@/module
@ -15,6 +15,7 @@ SRC_COMMON=@srcdir@/common
SRC_XDATA=@srcdir@/xdata SRC_XDATA=@srcdir@/xdata
SRC_CONTRIB=@srcdir@/contrib SRC_CONTRIB=@srcdir@/contrib
SRC_TTAP=@srcdir@/t-tap SRC_TTAP=@srcdir@/t-tap
SRC_WORKERS=@srcdir@/worker
CC=@CC@ CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ CFLAGS=@CFLAGS@ @DEFS@
@ -28,32 +29,32 @@ CFGDIR=@sysconfdir@
BINDIR=@bindir@ BINDIR=@bindir@
CGIDIR=@sbindir@ CGIDIR=@sbindir@
LIBEXECDIR=@libexecdir@ LIBEXECDIR=@libexecdir@
LIBDIR=@libdir@
INCLUDEDIR=@includedir@/nagios
HTMLDIR=@datadir@ HTMLDIR=@datadir@
datarootdir=@datarootdir@
LN_S=@LN_S@
INSTALL=@INSTALL@ INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@ INSTALL_OPTS=@INSTALL_OPTS@
COMMAND_OPTS=@COMMAND_OPTS@ COMMAND_OPTS=@COMMAND_OPTS@
HTTPD_CONF=@HTTPD_CONF@ HTTPD_CONF=@HTTPD_CONF@
LN_HTTPD_SITES_ENABLED=@LN_HTTPD_SITES_ENABLED@
INIT_DIR=@init_dir@ INIT_DIR=@init_dir@
INIT_OPTS=-o root -g root INIT_OPTS=@INIT_OPTS@
CGICFGDIR=$(CGIDIR) CGICFGDIR=$(CGIDIR)
PERLDIR=@PERLDIR@
USE_EVENTBROKER=@USE_EVENTBROKER@ USE_EVENTBROKER=@USE_EVENTBROKER@
USE_LIBTAP=@USE_LIBTAP@ USE_LIBTAP=@USE_LIBTAP@
INSTALLPERLSTUFF=@INSTALLPERLSTUFF@
CGIEXTRAS=@CGIEXTRAS@ CGIEXTRAS=@CGIEXTRAS@
SNPRINTF_O=@SNPRINTF_O@
CP=@CP@ CP=@CP@
@SET_MAKE@ @SET_MAKE@
none: none:
@echo "Please supply a command line argument (i.e. 'make all'). Other targets are:" @echo "Please supply a command line argument (i.e. 'make all'). Other targets are:"
@echo " nagios cgis contrib modules" @echo " nagios cgis contrib modules workers"
@echo " clean" @echo " clean"
@echo " install install-base install-cgis install-html install-exfoliation install-config install-init install-commandmode fullinstall" @echo " install install-base install-cgis install-html install-exfoliation install-config install-init install-commandmode fullinstall"
# @echo " uninstall" # @echo " uninstall"
@ -66,7 +67,7 @@ indent:
@sh indent-all.sh @sh indent-all.sh
ctags: ctags:
ctags -R ctags -R --exclude=html/angularjs --exclude=html/d3 --exclude=t-tap
all: all:
cd $(SRC_BASE) && $(MAKE) cd $(SRC_BASE) && $(MAKE)
@ -75,6 +76,7 @@ all:
if [ x$(USE_EVENTBROKER) = xyes ]; then \ if [ x$(USE_EVENTBROKER) = xyes ]; then \
cd $(SRC_MODULE) && $(MAKE); \ cd $(SRC_MODULE) && $(MAKE); \
fi fi
cd $(SRC_WORKERS) && $(MAKE) $@
@echo "" @echo ""
@echo "*** Compile finished ***" @echo "*** Compile finished ***"
@ -121,7 +123,7 @@ all:
@echo "" @echo ""
@echo " - Look at the sample config files" @echo " - Look at the sample config files"
@echo " - Read the documentation on the Nagios Library at:" @echo " - Read the documentation on the Nagios Library at:"
@echo " http://library.nagios.com" @echo " https://library.nagios.com"
@echo "" @echo ""
@echo "before you post a question to one of the mailing lists." @echo "before you post a question to one of the mailing lists."
@echo "Also make sure to include pertinent information that could" @echo "Also make sure to include pertinent information that could"
@ -134,13 +136,16 @@ all:
@echo "" @echo ""
@echo "For more information on obtaining support for Nagios, visit:" @echo "For more information on obtaining support for Nagios, visit:"
@echo "" @echo ""
@echo " http://support.nagios.com" @echo " https://support.nagios.com"
@echo "" @echo ""
@echo "*************************************************************" @echo "*************************************************************"
@echo "" @echo ""
@echo "Enjoy." @echo "Enjoy."
@echo "" @echo ""
$(SRC_LIB)/libnagios.a:
cd $(SRC_LIB) && $(MAKE)
nagios: nagios:
cd $(SRC_BASE) && $(MAKE) cd $(SRC_BASE) && $(MAKE)
@ -161,7 +166,11 @@ contrib:
modules: modules:
cd $(SRC_MODULE) && $(MAKE) cd $(SRC_MODULE) && $(MAKE)
workers:
cd $(SRC_WORKERS) && $(MAKE) all
clean: clean:
cd $(SRC_LIB) && $(MAKE) $@
cd $(SRC_BASE) && $(MAKE) $@ cd $(SRC_BASE) && $(MAKE) $@
cd $(SRC_CGI) && $(MAKE) $@ cd $(SRC_CGI) && $(MAKE) $@
cd $(SRC_COMMON) && $(MAKE) $@ cd $(SRC_COMMON) && $(MAKE) $@
@ -171,10 +180,12 @@ clean:
cd $(SRC_CONTRIB) && $(MAKE) $@ cd $(SRC_CONTRIB) && $(MAKE) $@
cd $(SRC_MODULE) && $(MAKE) $@ cd $(SRC_MODULE) && $(MAKE) $@
cd $(SRC_TTAP) && $(MAKE) $@ cd $(SRC_TTAP) && $(MAKE) $@
cd $(SRC_WORKERS) && $(MAKE) $@
rm -f *.cfg core rm -f *.cfg core
rm -f *~ *.*~ */*~ */*.*~ */*/*.*~ rm -f *~ *.*~ */*~ */*.*~ */*/*.*~
distclean: clean distclean: clean
cd $(SRC_LIB) && $(MAKE) $@
cd $(SRC_BASE) && $(MAKE) $@ cd $(SRC_BASE) && $(MAKE) $@
cd $(SRC_CGI) && $(MAKE) $@ cd $(SRC_CGI) && $(MAKE) $@
cd $(SRC_COMMON) && $(MAKE) $@ cd $(SRC_COMMON) && $(MAKE) $@
@ -184,6 +195,7 @@ distclean: clean
cd $(SRC_CONTRIB) && $(MAKE) $@ cd $(SRC_CONTRIB) && $(MAKE) $@
cd $(SRC_MODULE) && $(MAKE) $@ cd $(SRC_MODULE) && $(MAKE) $@
cd $(SRC_TTAP) && $(MAKE) $@ cd $(SRC_TTAP) && $(MAKE) $@
cd $(SRC_WORKERS) && $(MAKE) $@
rm -f sample-config/*.cfg sample-config/*.conf sample-config/template-object/*.cfg rm -f sample-config/*.cfg sample-config/*.conf sample-config/template-object/*.cfg
rm -f daemon-init pkginfo rm -f daemon-init pkginfo
rm -f Makefile subst rm -f Makefile subst
@ -192,7 +204,8 @@ distclean: clean
devclean: distclean devclean: distclean
test: test: nagios cgis
cd $(SRC_LIB) && $(MAKE) test
$(MAKE) test-perl $(MAKE) test-perl
$(MAKE) test-tap $(MAKE) test-tap
@ -211,7 +224,7 @@ test-perl: cgis
install-html: install-html:
cd $(SRC_HTM) && $(MAKE) install cd $(SRC_HTM) && $(MAKE) install
make install-exfoliation $(MAKE) install-exfoliation
install-base: install-base:
cd $(SRC_BASE) && $(MAKE) install cd $(SRC_BASE) && $(MAKE) install
@ -237,10 +250,8 @@ install-basic:
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LIBEXECDIR) $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LIBEXECDIR)
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LOGDIR) $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LOGDIR)
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LOGDIR)/archives $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(LOGDIR)/archives
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(CHECKRESULTDIR) $(INSTALL) -m 775 $(COMMAND_OPTS) -d $(DESTDIR)$(CHECKRESULTDIR)
if [ $(INSTALLPERLSTUFF) = yes ]; then \ chmod g+s $(DESTDIR)$(CHECKRESULTDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) p1.pl $(DESTDIR)$(BINDIR); \
fi;
@echo "" @echo ""
@echo "*** Main program, CGIs and HTML files installed ***" @echo "*** Main program, CGIs and HTML files installed ***"
@ -285,14 +296,25 @@ install-config:
install-webconf: install-webconf:
$(INSTALL) -m 644 sample-config/httpd.conf $(DESTDIR)$(HTTPD_CONF)/nagios.conf $(INSTALL) -m 644 sample-config/httpd.conf $(DESTDIR)$(HTTPD_CONF)/nagios.conf
if [ $(LN_HTTPD_SITES_ENABLED) -eq 1 ]; then \
$(LN_S) $(DESTDIR)$(HTTPD_CONF)/nagios.conf $(DESTDIR)/etc/apache2/sites-enabled/nagios.conf; \
fi
@echo "" @echo ""
@echo "*** Nagios/Apache conf file installed ***" @echo "*** Nagios/Apache conf file installed ***"
@echo "" @echo ""
install-exfoliation: install-exfoliation:
cp -rf contrib/exfoliation/stylesheets/* $(DESTDIR)$(HTMLDIR)/stylesheets @cd contrib/exfoliation; \
cp -rf contrib/exfoliation/images/* $(DESTDIR)$(HTMLDIR)/images $(INSTALL) $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/stylesheets; \
for file in $$(find ./stylesheets/ -type f); do \
$(INSTALL) -m 644 $(INSTALL_OPTS) $${file} $(DESTDIR)$(HTMLDIR)/$${file}; \
done; \
$(INSTALL) $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images; \
for file in $$(find ./images -type f); do \
$(INSTALL) -m 644 $(INSTALL_OPTS) $${file} $(DESTDIR)$(HTMLDIR)/$${file}; \
done; \
cd ../..
@echo "" @echo ""
@echo "*** Exfoliation theme installed ***" @echo "*** Exfoliation theme installed ***"
@ -300,8 +322,16 @@ install-exfoliation:
@echo "" @echo ""
install-classicui: install-classicui:
cp -rf html/stylesheets/* $(DESTDIR)$(HTMLDIR)/stylesheets @cd html; \
cp -rf html/images/* $(DESTDIR)$(HTMLDIR)/images $(INSTALL) $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/stylesheets; \
for file in $$(find ./stylesheets/ -type f); do \
$(INSTALL) -m 644 $(INSTALL_OPTS) $${file} $(DESTDIR)$(HTMLDIR)/$${file}; \
done; \
$(INSTALL) $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images; \
for file in $$(find ./images -type f); do \
$(INSTALL) -m 644 $(INSTALL_OPTS) $${file} $(DESTDIR)$(HTMLDIR)/$${file}; \
done; \
cd ..
@echo "" @echo ""
@echo "*** Classic theme installed ***" @echo "*** Classic theme installed ***"
@ -328,7 +358,25 @@ install-commandmode:
@echo "" @echo ""
fullinstall: install install-init install-commandmode install-webconf install-devel: install-headers install-lib
install-headers:
$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)
$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/lib
$(INSTALL) -m 644 include/*.h $(DESTDIR)$(INCLUDEDIR)
$(INSTALL) -m 644 lib/*.h $(DESTDIR)$(INCLUDEDIR)/lib
rm -f $(DESTDIR)$(INCLUDEDIR)/config*.h
install-lib: $(SRC_LIB)/libnagios.a
$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)
$(INSTALL) -m 644 $(SRC_LIB)/libnagios.a $(DESTDIR)$(LIBDIR)
dox:
@rm -rf Documentation
doxygen doxy.conf
fullinstall: install install-init install-commandmode install-webconf install-devel
# Uninstall is too destructive if base install directory is /usr, etc. # Uninstall is too destructive if base install directory is /usr, etc.
#uninstall: #uninstall:
@ -375,5 +423,11 @@ pkgset: nagios.SPARC.pkg.tar.gz
pkgclean: pkgclean:
rm -rf pkg Prototype nagios.SPARC.pkg.tar.gz rm -rf pkg Prototype nagios.SPARC.pkg.tar.gz
dist: distclean
rm -f nagios-$(VERSION)
ln -s . nagios-$(VERSION)
tar zhcf nagios-$(VERSION).tar.gz --exclude nagios-$(VERSION)/nagios-$(VERSION).tar.gz --exclude nagios-$(VERSION)/nagios-$(VERSION) --exclude RCS --exclude CVS --exclude build-* --exclude *~ --exclude .git* nagios-$(VERSION)/
rm -f nagios-$(VERSION)
# Targets that always get built # Targets that always get built
.PHONY: indent clean clean distclean .PHONY: indent clean clean distclean dox test html

View File

@ -1,39 +0,0 @@
package OutputTrap;
#
# Methods for use by tied STDOUT in embedded PERL module.
#
# Simply redirects STDOUT to a temporary file associated with the
# current child/grandchild process.
#
use strict;
# Perl before 5.6 does not seem to have warnings.pm ???
#use warnings;
use IO::File;
sub TIEHANDLE {
my ($class, $fn) = @_;
my $handle = new IO::File "> $fn" or die "Cannot open embedded work filei $!\n";
bless { FH => $handle, Value => 0}, $class;
}
sub PRINT {
my $self = shift;
my $handle = $self -> {FH};
print $handle join("",@_);
}
sub PRINTF {
my $self = shift;
my $fmt = shift;
my $handle = $self -> {FH};
printf $handle ($fmt,@_);
}
sub CLOSE {
my $self = shift;
my $handle = $self -> {FH};
close $handle;
}
1;
__END__

30
README
View File

@ -1,29 +1 @@
Nagios 3.x README README.asciidoc
-----------------
Nagios is a host/service/network monitoring program written in C and
released under the GNU General Public License. CGI programs are
included to allow you to view the current status, history, etc via
a web interface if you so desire.
Features:
1) Monitoring of network services (via SMTP, POP3, HTTP, PING, etc).
2) A plugin interface to allow for user-developed service monitoring methods.
3) Notifications when problems occur and get resolved (via email, pager,
or user-defined method).
4) Ability to define "event handlers" for proactive problem resolution
5) Web output (current status, notifications, problem history, log file, etc.)
6) Automatic log file rotation/archiving
For installation instructions, use a web browser to read the HTML documentation
in the html/docs subdirectory.
Visit the Nagios homepage at http://www.nagios.org for online
documentation, new releases, bug reports, information on the mailing
lists, etc.
-- Ethan Galstad (egalstad@nagios.org)

80
README.asciidoc Normal file
View File

@ -0,0 +1,80 @@
Nagios 4.x README
=================
Nagios is a host/service/network monitoring program written in C and
released under the GNU General Public License, version 2. CGI programs
are included to allow you to view the current status, history, etc via
a web interface if you so desire.
Visit the Nagios homepage at https://www.nagios.org for documentation,
new releases, bug reports, information on discussion forums, and more.
https://www.nagios.org/about/features/[Features]
-----------------------------------------------
* Monitoring of network services (via SMTP, POP3, HTTP, PING, etc).
* Monitoring of host resources (processor load, disk usage, etc.).
* A plugin interface to allow for user-developed service monitoring
methods.
* Ability to define network host hierarchy using "parent" hosts,
allowing detection of and distinction between hosts that are down
and those that are unreachable.
* Notifications when problems occur and get resolved (via email,
pager, or user-defined method).
* Ability to define event handlers for proactive problem resolution.
* Automatic log file rotation/archiving.
* Optional web interface for viewing current network status,
notification and problem history, log file, etc.
Changes
-------
See the
https://raw.githubusercontent.com/NagiosEnterprises/nagioscore/master/Changelog[Changelog]
for a summary of important changes and fixes, or the
https://github.com/NagiosEnterprises/nagioscore/commits/master[commit history]
for more detail.
Download
--------
Latest releases can be downloaded from https://www.nagios.org/download/
Installation
------------
http://nagios.sourceforge.net/docs/nagioscore/4/en/quickstart.html[Quickstart installation guides]
are available to help you get Nagios up and monitoring.
Documentation & Support
-----------------------
* http://nagios.sourceforge.net/docs/nagioscore/4/en/[User Guide]
* https://library.nagios.com/library/products/nagioscore/[Nagios Core Documentation Library]
* https://support.nagios.com/forum/viewforum.php?f=7[Support Forums]
* https://www.nagios.org/support/[Additional Support Resources]
Contributing
------------
The Nagios source code is hosted on GitHub:
https://github.com/NagiosEnterprises/nagioscore
Do you have an idea or feature request to make Nagios better? Join or
start a discussion on the
https://support.nagios.com/forum/viewforum.php?f=34[Nagios Core Development forum].
Bugs can be reported by
https://github.com/NagiosEnterprises/nagioscore/issues/new[opening an
issue on GitHub]. If you have identified a security related issue in
Nagios, please contact security@nagios.com.
Patches and GitHub pull requests are welcome. Pull requests on GitHub
link commits in version control to review and discussion of the
changes, helping to show how and why changes were made, in addition to
who was involved.
Created by Ethan Galstad, the success of Nagios has been due to the
fantastic community members that support it and provide bug reports,
patches, and great ideas. See the
https://raw.githubusercontent.com/NagiosEnterprises/nagioscore/master/THANKS[THANKS file]
for some of the many who have contributed since 1999.

608
THANKS
View File

@ -5,299 +5,329 @@ THANKS!
The success of Nagios has been due to the fantastic community members that The success of Nagios has been due to the fantastic community members that
support it and provide bug reports, patches, and great ideas. Here are a support it and provide bug reports, patches, and great ideas. Here are a
few of the many members that have contributed to Nagios in various ways few of the many members that have contributed to Nagios in various ways
since 1999. If I missed your name, let me know. since 1999. If I missed your name, misspelled it or otherwise got it
wrong, please let me know.
* Greg Abrams
* Petr Adamec
* Gavin Adams
* David Allan
* Felipe Almeida
* Markus Almroth
* Jon Andrews
* Michael Anthon
* Bernd Arnold
* Erwan Arzur
* Volker Aust
* Hendrik Baecker
* Markus Baertschi
* Michael Bailey
* Luigi Balzano
* Sebastien Barbereau
* Wolfgang Barth
* Devin Bayer
* Simon Beale
* Ben Bell
* Marlo Bell
* Ray Bengen
* Derrick Bennett
* Chris Bensend
* Kevin Benton
* Gary Berger
* Sven-Göran Bergh
* Jochen Bern
* Tom Bertelson
* Joel Berry
* Olivier Beytrison
* Christoph Biedl
* Dennis Biringer
* Mike Bird
* Jason Blakey
* Jeffrey Blank
* Ian Blenke
* Fran Boon
* Jeremy Bouse
* Adam Bowen * Adam Bowen
* Ludo Bosmans * Ahmon Dancy
* Henning Brauer * Alain Radix
* Michael Bunk * Albrecht Dress
* Daniel Burke * Alessandro Ren
* Grant Byers * Alex Peeters
* John Calcote
* Don Carroll
* Ian Cass
* Alexios Chouhoulas * Alexios Chouhoulas
* Allan Clark * Allan Clark
* Jonathan Clarke
* Justin Clarke
* Perry Clarke
* Nick Cleaton
* Charlie Cook
* Garry Cook
* Jeff Cours
* Michelle Craft
* Matthias Cramer
* Matthieu Kermagoret
* Jim Crilley
* Joel Crisp
* Jean-Eric Cuendet
* Ahmon Dancy
* Jan David
* Stephen Davies
* Karl DeBisschop
* Tom De Blende
* Mark DeTrano
* Thomas Dohl
* Mike Dorman
* Albrecht Dress
* Alok Dubey * Alok Dubey
* Jim Dumser * Aman Gupta
* Thomas Dunkel
* Matthias Eble
* Ari Edelkind
* Matthias Eichler
* Rob Enders
* Andreas Ericsson
* Matt Ezell
* Sylvain Falardeau
* Duncan Ferguson
* Sean Finney
* Andy Finkenstadt
* Mika Fischer
* Matthias Flacke
* Marcus Fleige
* Matthias Flittner
* Bastian Friedrich
* Jean Gabes
* Szabo Gabor
* Mathieu Gagne
* Dan Gailey
* Darren Gamble
* Robert Gash
* Hugo Gayosso
* Subhendu Ghosh
* Mark Goldfinch
* Jeffrey Goldschrafe
* Jan Grant
* Stephen Gran
* Matthew Grant
* Martin Green
* Todd Green
* Nathan Grennan
* Sebastian Guarino
* Thomas Guyot-Sionnest
* Sergio Guzman
* Hugo Hallqvist
* Lars Hansson
* Ben Heavner
* Lars Hecking
* Jason Hedden
* Karl Hegbloom
* Thomas Hepper
* Marcus Hildenbrand
* Arne Hinrichsen
* Ronald Ho
* Stanley Hopcroft
* Sam Howard
* Torsten Huebler
* Stig Jacobsen
* Percy Jahn
* Stewart James
* Olivier Jan
* Jeff Johnson
* Jonathan Kamens
* Andrew Kaplan
* Lars Kellogg-Stedman
* Paul Kent
* Matthieu Kermagoret
* Matthias Kerk
* Bo Kersey
* Andreas Kirchwitz
* Burkhard Klaus
* Tobias Klausmann
* Igno Kley
* Rene Klootwijk
* David Kmoch
* Brandon Knitter
* Uwe Knop
* Ryoji Kobayashi
* Uwe Knop
* Daniel Koffler
* Petya Kohts
* Chris Kolquist
* Jiri Kostern
* Christoph Kron
* Ivan Kuncl
* Dean Lane
* Ingo Lantschner
* Gerhard Lausser
* William Leibzon
* Pedro Leite
* Bernard Li
* Joerg Linge
* Michael Little
* Shad Lords
* Larry Low
* Michael Lubben
* Tyler Lund
* Jacob Lundqvist
* James Maddison
* Joseph Maiorana
* Ricardo Maraschini
* Michael Marineau
* Roberto Marrodan
* Ernst-Deiter Martin
* Christoph Maser
* Christian Masopust
* Emanuel Massano
* Richard Mayhew
* Mike McHenry
* Gordon Messmer
* Lars Michelson
* Martin Mielke
* Christian Mies
* Gary Miller
* Peter Valdemar Morch
* James Moseley
* Tobias Mucke
* Gerd Mueller
* Bob (Netshell)
* Time Niemueller
* Sven Nierlein
* Michael O'Reilly
* Tomer Okavi
* Vadim Okun
* Hiren Patel
* Rob Patrick
* Remi Paulmier
* Alex Peeters
* James "Showkilr" Peterson
* Cary Petterborg
* Bill Pier
* Badri Pillai
* Steven Pokrandt
* Jim Popovitch
* Janet Post
* Paul Pot
* Daniel Pouzzner
* Marc Powell
* William Preston
* Patrick Proy
* Luiz Felipe R E
* Alain Radix
* Kenneth Ray
* Nick Reinking
* Rob Remus
* Alessandro Ren
* Bob Rentschler
* Mindaugas Riauba
* Matthew Richardson
* Dietmar Rieder
* Brian Riggs
* Peter Ringe
* Eirik Robertstad
* Stefan Rompf
* Amir Rosenblatt * Amir Rosenblatt
* Luke Ross
* Ralph Rossner
* Chris Rothecker
* John Rouillard
* Yves Rubin
* Mattias Ryrlen
* Jonathan Saggau
* Karel Salavec
* Jorge Sanchez
* Bogdan Sandu
* Pavel Satrapa
* Frederic Schaer
* Mark Schenker
* David Schlecht
* Russell Scibetti
* Max Schubert
* Stefan Schurtz
* Thomas Sebastien
* Brian Seklecki
* Denis Seleznyov
* Lonny Selinger
* Nate Shafer
* Moshe Sharon
* Andy Shellam
* Nick Shore
* Ryan Skorstad
* Michael Smedius
* Gordon Smith
* Lou Sneddon
* Mark Spieth
* Tim Starling
* Thomas Stolle
* Kevin Stone
* Herbert Straub
* Sven Strickroth
* SUSE Linux Team
* Horvath Tamas
* Nicholas Tang
* Glenn Thompson
* Robert Thompson
* Josh Thorstad
* David Tilloy
* Gennaro Tortone
* Steve Underwood
* Kai Ung
* Stephane Urbanovski
* Franky Van Liedekerke
* Nikola Vassilev
* Esteban Manchado Velazquez
* Geert Vanderkelen
* Carlos Velasco
* Jan Vejvalka
* Robert August Vincent II
* Dave Viner
* Ton Voon
* Lars Vogdt
* Phil Walther
* Jeremy Weatherford
* Holger Weiss
* Tom Welsh
* Brad Werschler
* Peter Westlake
* Todd Wheeler
* Florian Weimer
* Tim Wilde
* Chris Witterholt
* Evan Winter
* Armin Wolfermann
* Greg Woods
* Cliff Woolley
* Mitch Wright
* Michal Zimen
* Pawel Zuzelski
* Anders K. Lindgren * Anders K. Lindgren
* Andreas Ericsson
* Andreas Kirchwitz
* Andrew Kaplan
* Andrew Widdersheim
* Andy Finkenstadt
* Andy Shellam
* Anton Lofgren
* Ari Edelkind
* Armin Wolfermann
* Arne Hinrichsen
* Badri Pillai
* Bastian Friedrich
* Ben Bell
* Ben Heavner
* Bernard Li
* Bernd Arnold
* Bill Pier
* Bo Kersey
* Bob (Netshell)
* Bob Rentschler
* Bogdan Sandu
* Brad Werschler
* Brandon Knitter
* Brian Riggs
* Brian Seklecki
* Burkhard Klaus
* Carlos Velasco
* Cary Petterborg
* Charlie Cook
* Chris Bensend
* Chris Kolquist
* Chris Rothecker
* Chris Witterholt
* Christian Masopust
* Christian Mies
* Christoph Biedl
* Christoph Kron
* Christoph Maser
* Cliff Woolley
* Dan Gailey
* Daniel Burke
* Daniel Koffler
* Daniel Pouzzner
* Daniel Wittenberg
* Darren Gamble
* Dave Viner
* David Allan
* David Kmoch
* David Schlecht
* David Tilloy
* Dawid Golunski
* Dean Lane
* Denis Seleznyov
* Dennis Biringer
* Derrick Bennett
* Devin Bayer
* Dietmar Rieder
* Dirkjan Bussink
* Don Carroll
* Duncan Ferguson
* Eirik Robertstad
* Emanuel Massano
* Ernst-Deiter Martin
* Erwan Arzur
* Esteban Manchado Velazquez
* Evan Winter
* Felipe Almeida
* Florian Weimer
* Fran Boon
* Franky Van Liedekerke
* Frederic Schaer
* Frederic Van Espen
* Garry Cook
* Gary Berger
* Gary Miller
* Gavin Adams
* Geert Vanderkelen
* Gennaro Tortone
* Geoff Montee
* Gerd Mueller
* Gerhard Lausser
* gherteg
* Glenn Thompson
* Gordon Messmer
* Gordon Smith
* Grant Byers
* Greg Abrams
* Greg Woods
* Hayakawa Shinya
* Helmut Mikulcik
* Hendrik Baecker
* Henning Brauer
* Herbert Straub
* Hiren Patel
* Holger Weiss
* Horvath Tamas
* Hugo Gayosso
* Hugo Hallqvist
* Ian Blenke
* Ian Cass
* Igno Kley
* Ingo Lantschner
* Ivan Kuncl
* Jacob Lundqvist
* James "Showkilr" Peterson
* James Maddison
* James Moseley
* Jan David
* Jan Grant
* Jan Vejvalka
* Janet Post
* Janice Singh
* Jason Blakey
* Jason Hedden
* Jean Gabes
* Jean-Eric Cuendet
* Jeff Cours
* Jeff Johnson
* Jeffrey Blank
* Jeffrey Goldschrafe
* Jeremy Bouse
* Jeremy Weatherford
* Jim Crilley
* Jim Dumser
* Jim Popovitch
* Jiri Kostern
* Jochen Bern
* Joel Berry
* Joel Crisp
* Joerg Linge
* John Calcote
* John Rouillard
* Jon Andrews
* Jonathan Clarke
* Jonathan Kamens
* Jonathan Saggau
* Jorge Sanchez
* Joseph Maiorana
* Josh Soref
* Josh Thorstad
* Justin Clarke
* Kai Kunstmann
* Kai Ung
* Karel Salavec
* Karl DeBisschop
* Karl Hegbloom
* Karsten Weiss
* Kenneth Ray
* Kevin Benton
* Kevin Stone
* Larry Low
* Lars Hansson
* Lars Hecking
* Lars Kellogg-Stedman
* Lars Michelson
* Lars Vogdt
* lev
* Lonny Selinger
* Lou Sneddon
* Ludo Bosmans
* Luigi Balzano
* Luiz Felipe R E
* Luke Ross
* Marc Powell
* Marcus Fleige
* Marcus Hildenbrand
* Mark DeTrano
* Mark Frost
* Mark Goldfinch
* Mark Schenker
* Mark Spieth
* Markus Almroth
* Markus Baertschi
* Marlo Bell
* Martin Green
* Martin Mielke
* Mathieu Gagne
* Matt Ezell
* Matthew Grant
* Matthew Richardson
* Matthias Cramer
* Matthias Eble
* Matthias Eichler
* Matthias Flacke
* Matthias Flittner
* Matthias Kerk
* Matthieu Kermagoret
* Matthieu Kermagoret
* Mattias Ryrlen
* Max Schubert
* Max Sikstrom
* Michael Anthon
* Michael Bailey
* Michael Bunk
* Michael Little
* Michael Lubben
* Michael Marineau
* Michael O'Reilly
* Michael Smedius
* Michal Zimen
* Michelle Craft
* Mika Fischer
* Mike Bird
* Mike Dorman
* Mike McHenry
* Mindaugas Riauba
* Mitch Wright
* Moshe Sharon
* Nate Shafer
* Nathan Grennan
* Nicholas Tang
* Nick Cleaton
* Nick Reinking
* Nick Shore
* Nikola Vassilev
* Olivier Beytrison
* Olivier Jan
* Parth Laxmikant Kolekar
* Patrick Proy
* Patrik Halfar
* Paul Kent
* Paul Pot
* Pavel Satrapa
* Pawel Zuzelski
* Pedro Leite
* Percy Jahn
* Perry Clarke
* Peter Ringe
* Peter Valdemar Morch
* Peter Westlake
* Petr Adamec
* Petya Kohts
* Phil Mayers
* Phil Randal
* Phil Walther
* Ralph Rossner
* Ray Bengen
* Remi Paulmier
* Rene Klootwijk
* Ricardo Maraschini
* Richard Mayhew
* Rob Enders
* Rob Patrick
* Rob Remus
* Robert August Vincent II
* Robert Gash
* Robert Thompson
* Roberto Marrodan
* Robin Kearney
* Robin Sonefors
* Ronald Ho
* Rostislav Opočenský
* Russell Scibetti
* Ryan Skorstad
* Ryoji Kobayashi
* Sam Howard
* Sean Finney
* Sebastian Guarino
* Sebastien Barbereau
* Sergio Guzman
* Shad Lords
* Simon Beale
* Stanley Hopcroft
* Stefan Rompf
* Stefan Schurtz
* Stephane Urbanovski
* Stephen Davies
* Stephen Gran
* Steve Underwood
* Steven Pokrandt
* Stewart James
* Stig Jacobsen
* Subhendu Ghosh
* SUSE Linux Team
* Sven Nierlein
* Sven Strickroth
* Sven-Göran Bergh
* Sylvain Falardeau
* Szabo Gabor
* Thomas Dohl
* Thomas Dunkel
* Thomas Guyot-Sionnest
* Thomas Hepper
* Thomas Sebastien
* Thomas Stolle
* Tim Starling
* Tim Wilde
* Time Niemueller
* Tobias Klausmann
* Tobias Mucke
* Todd Green
* Todd Wheeler
* Tom Bertelson
* Tom De Blende
* Tom Welsh
* Tomer Okavi
* Ton Voon
* Torsten Huebler
* Tyler Lund
* Uwe Knop
* Uwe Knop
* Vadim Okun
* Volkan Yazici
* Volker Aust
* William Leibzon
* William Preston
* Wolfgang Barth
* xoubih
* Yves Rubin
* Zakhar Kleyman
* Z. Liu

View File

@ -1,5 +1,18 @@
Upgrading to Nagios 3.x Upgrading Nagios Core
----------------------- =====================
nagios-4.3.0 - 2017-02-21
-------------------------
If you use "corewindow", as in
http://localhost/nagios?corewindow=www.somewhere.com
note that this functionality has been disabled by default in this
release. If you still want to use it, run ./configure with the
parameter --enable-corewindow
nagios-3.0
----------
The HTML documentation covers what you need to know in order The HTML documentation covers what you need to know in order
to upgrade from Nagios 2.x You can find the documentation in to upgrade from Nagios 2.x You can find the documentation in
@ -11,9 +24,3 @@ Make sure to read the following sections:
- "What's New" (whatsnew.html) - "What's New" (whatsnew.html)
- "Upgrading Nagios" (upgrading.html) - "Upgrading Nagios" (upgrading.html)

View File

@ -1,7 +1,6 @@
############################ ############################
# Makefile for Nagios # Makefile for Nagios
# #
# Last Modified: 12-05-2008
############################ ############################
@ -9,9 +8,10 @@
SRC_COMMON=../common SRC_COMMON=../common
SRC_INCLUDE=../include SRC_INCLUDE=../include
SRC_XDATA=../xdata SRC_XDATA=../xdata
SRC_LIB=../lib
CC=@CC@ CC=@CC@
CFLAGS=-Wall @CFLAGS@ @DEFS@ -DNSCORE CFLAGS=-Wall -I.. @CFLAGS@ @DEFS@ -DNSCORE
# Compiler flags for use with gprof # Compiler flags for use with gprof
#CFLAGS=-pg -DHAVE_CONFIG_H -DNSCORE #CFLAGS=-pg -DHAVE_CONFIG_H -DNSCORE
@ -47,82 +47,52 @@ CGIURL=@cgiurl@
HTMURL=@htmurl@ HTMURL=@htmurl@
MATHLIBS=-lm MATHLIBS=-lm
PERLLIBS=@PERLLIBS@
PERLXSI_O=@PERLXSI_O@
SOCKETLIBS=@SOCKETLIBS@ SOCKETLIBS=@SOCKETLIBS@
THREADLIBS=@THREADLIBS@
BROKERLIBS=@BROKERLIBS@ BROKERLIBS=@BROKERLIBS@
BROKER_LDFLAGS=@BROKER_LDFLAGS@ BROKER_LDFLAGS=@BROKER_LDFLAGS@
CP=@CP@ CP=@CP@
# External data I/O code and headers
XSDC=@XSDC@
XSDH=@XSDH@
XCDC=@XCDC@
XCDH=@XCDH@
XRDC=@XRDC@
XRDH=@XRDH@
XODC=@XODC@
XODH=@XODH@
XPDC=@XPDC@
XPDH=@XPDH@
XDDC=@XDDC@
XDDH=@XDDH@
# Extra base code # Extra base code
BASEEXTRALIBS=@BASEEXTRALIBS@ BASEEXTRALIBS=@BASEEXTRALIBS@
# Generated automatically from configure script # Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
BROKER_O=@BROKER_O@ BROKER_O=@BROKER_O@
BROKER_H=@BROKER_H@ BROKER_H=@BROKER_H@
# Object data # Object data
#ODATALIBS=$(SRC_COMMON)/objects.c $(SRC_XDATA)/$(XODC)
#ODATAHDRS=$(SRC_INCLUDE)/objects.h $(SRC_XDATA)/$(XODH)
ODATALIBS=objects-base.o xobjects-base.o ODATALIBS=objects-base.o xobjects-base.o
ODATAHDRS= ODATAHDRS=
ODATADEPS=$(ODATALIBS) ODATADEPS=$(ODATALIBS)
# Retention data # Retention data
#RDATALIBS=sretention.o $(SRC_XDATA)/$(XRDC)
#RDATAHDRS=$(SRC_INCLUDE)/sretention.h $(SRC_XDATA)/$(XRDH)
RDATALIBS=retention-base.o xretention-base.o RDATALIBS=retention-base.o xretention-base.o
RDATAHDRS= RDATAHDRS=
RDATADEPS=$(RDATALIBS) RDATADEPS=$(RDATALIBS)
# Comment data # Comment data
#CDATALIBS=$(SRC_COMMON)/comments.c $(SRC_XDATA)/$(XCDC)
#CDATAHDRS=$(SRC_INCLUDE)/comments.h $(SRC_XDATA)/$(XCDH)
CDATALIBS=comments-base.o xcomments-base.o CDATALIBS=comments-base.o xcomments-base.o
CDATAHDRS= CDATAHDRS=
CDATADEPS=$(CDATALIBS) CDATADEPS=$(CDATALIBS)
# Status data # Status data
#SDATALIBS=$(SRC_COMMON)/statusdata.c $(SRC_XDATA)/$(XSDC)
#SDATAHDRS=$(SRC_INCLUDE)/statusdata.h $(SRC_XDATA)/$(XSDH)
SDATALIBS=statusdata-base.o xstatusdata-base.o SDATALIBS=statusdata-base.o xstatusdata-base.o
SDATAHDRS= SDATAHDRS=
SDATADEPS=$(SDATALIBS) SDATADEPS=$(SDATALIBS)
# Performance data # Performance data
#PDATALIBS=perfdata.o $(SRC_XDATA)/$(XPDC)
#PDATAHDRS=$(SRC_INCLUDE)/perfdata.h $(SRC_XDATA)/$(XPDH)
PDATALIBS=perfdata-base.o xperfdata-base.o PDATALIBS=perfdata-base.o xperfdata-base.o
PDATAHDRS= PDATAHDRS=
PDATADEPS=$(PDATALIBS) PDATADEPS=$(PDATALIBS)
# Downtime data # Downtime data
#DDATALIBS=$(SRC_COMMON)/downtime.c $(SRC_XDATA)/$(XDDC) DDATALIBS=downtime-base.o
#DDATAHDRS=$(SRC_INCLUDE)/downtime.h $(SRC_XDATA)/$(XDDH)
DDATALIBS=downtime-base.o xdowntime-base.o
DDATAHDRS= DDATAHDRS=
DDATADEPS=$(DDATALIBS) DDATADEPS=$(DDATALIBS)
OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o skiplist.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS) $(SNPRINTF_O) $(PERLXSI_O) OBJS=$(BROKER_O) $(SRC_COMMON)/shared.o nerd.o query-handler.o workers.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o utils.o $(RDATALIBS) $(CDATALIBS) $(ODATALIBS) $(SDATALIBS) $(PDATALIBS) $(DDATALIBS) $(BASEEXTRALIBS)
OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(DDATADEPS) $(BROKER_H) OBJDEPS=$(ODATADEPS) $(ODATADEPS) $(RDATADEPS) $(CDATADEPS) $(SDATADEPS) $(PDATADEPS) $(DDATADEPS) $(BROKER_H)
all: nagios nagiostats all: nagios nagiostats
@ -133,56 +103,61 @@ all: nagios nagiostats
macros-base.o: $(SRC_COMMON)/macros.c $(SRC_INCLUDE)/macros.h macros-base.o: $(SRC_COMMON)/macros.c $(SRC_INCLUDE)/macros.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/macros.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/macros.c
skiplist.o: $(SRC_COMMON)/skiplist.c $(SRC_INCLUDE)/skiplist.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/skiplist.c
objects-base.o: $(SRC_COMMON)/objects.c $(SRC_INCLUDE)/objects.h objects-base.o: $(SRC_COMMON)/objects.c $(SRC_INCLUDE)/objects.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/objects.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/objects.c
xobjects-base.o: $(SRC_XDATA)/$(XODC) $(SRC_XDATA)/$(XODH) xobjects-base.o: $(SRC_XDATA)/xodtemplate.c $(SRC_XDATA)/xodtemplate.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XODC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xodtemplate.c
statusdata-base.o: $(SRC_COMMON)/statusdata.c $(SRC_INCLUDE)/statusdata.h statusdata-base.o: $(SRC_COMMON)/statusdata.c $(SRC_INCLUDE)/statusdata.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/statusdata.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/statusdata.c
xstatusdata-base.o: $(SRC_XDATA)/$(XSDC) $(SRC_XDATA)/$(XSDH) xstatusdata-base.o: $(SRC_XDATA)/xsddefault.c $(SRC_XDATA)/xsddefault.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XSDC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xsddefault.c
comments-base.o: $(SRC_COMMON)/comments.c $(SRC_INCLUDE)/comments.h comments-base.o: $(SRC_COMMON)/comments.c $(SRC_INCLUDE)/comments.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/comments.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/comments.c
xcomments-base.o: $(SRC_XDATA)/$(XCDC) $(SRC_XDATA)/$(XCDH) xcomments-base.o: $(SRC_XDATA)/xcddefault.c $(SRC_XDATA)/xcddefault.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XCDC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xcddefault.c
downtime-base.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h downtime-base.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c
xdowntime-base.o: $(SRC_XDATA)/$(XDDC) $(SRC_XDATA)/$(XDDH)
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XDDC)
perfdata-base.o: perfdata.c $(SRC_INCLUDE)/perfdata.h perfdata-base.o: perfdata.c $(SRC_INCLUDE)/perfdata.h
$(CC) $(CFLAGS) -c -o $@ perfdata.c $(CC) $(CFLAGS) -c -o $@ perfdata.c
xperfdata-base.o: $(SRC_XDATA)/$(XPDC) $(SRC_XDATA)/$(XPDH) xperfdata-base.o: $(SRC_XDATA)/xpddefault.c $(SRC_XDATA)/xpddefault.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XPDC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xpddefault.c
retention-base.o: sretention.c $(SRC_INCLUDE)/sretention.h retention-base.o: sretention.c $(SRC_INCLUDE)/sretention.h
$(CC) $(CFLAGS) -c -o $@ sretention.c $(CC) $(CFLAGS) -c -o $@ sretention.c
xretention-base.o: $(SRC_XDATA)/$(XRDC) $(SRC_XDATA)/$(XRDH) xretention-base.o: $(SRC_XDATA)/xrddefault.c $(SRC_XDATA)/xrddefault.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XRDC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xrddefault.c
$(SRC_COMMON)/shared.o: $(SRC_COMMON)/shared.c $(SRC_COMMON)/shared.o: $(SRC_COMMON)/shared.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
workers.o: workers.c wpres-phash.h
$(CC) $(CFLAGS) -c -o $@ $<
wpres-phash.h: wpres.gperf
gperf -S 1 -t -H wpres_key_phash -N wpres_get_key $< > $@
########## NAGIOS ########## ########## NAGIOS ##########
nagios: nagios.c $(OBJS) $(OBJDEPS) $(SRC_INCLUDE)/nagios.h $(SRC_INCLUDE)/locations.h libnagios:
$(CC) $(CFLAGS) -o $@ nagios.c $(OBJS) $(BROKER_LDFLAGS) $(LDFLAGS) $(PERLLIBS) $(MATHLIBS) $(SOCKETLIBS) $(THREADLIBS) $(BROKERLIBS) $(LIBS) $(MAKE) -C $(SRC_LIB)
nagiostats: nagiostats.c $(SRC_INCLUDE)/locations.h nagios.o: nagios.c $(SRC_INCLUDE)/nagios.h $(SRC_INCLUDE)/locations.h
$(CC) $(CFLAGS) -o $@ nagiostats.c $(LDFLAGS) $(MATHLIBS) $(LIBS) $(CC) $(CFLAGS) -c -o $@ nagios.c
nagios: nagios.o $(OBJS) $(OBJDEPS) libnagios
$(CC) $(CFLAGS) -o $@ $< $(OBJS) $(BROKER_LDFLAGS) $(LDFLAGS) $(MATHLIBS) $(SOCKETLIBS) $(BROKERLIBS) $(LIBS) $(SRC_LIB)/libnagios.a
nagiostats: nagiostats.c $(SRC_INCLUDE)/locations.h libnagios
$(CC) $(CFLAGS) -o $@ nagiostats.c $(LDFLAGS) $(MATHLIBS) $(LIBS) $(SRC_LIB)/libnagios.a
$(OBJS): $(SRC_INCLUDE)/locations.h $(OBJS): $(SRC_INCLUDE)/locations.h
@ -195,6 +170,7 @@ distclean: clean
rm -f Makefile rm -f Makefile
devclean: distclean devclean: distclean
rm -f wpres-phash.h
install: install:
$(MAKE) install-basic $(MAKE) install-basic
@ -211,3 +187,5 @@ install-basic:
strip-post-install: strip-post-install:
$(STRIP) $(DESTDIR)$(BINDIR)/@nagios_name@ $(STRIP) $(DESTDIR)$(BINDIR)/@nagios_name@
$(STRIP) $(DESTDIR)$(BINDIR)/@nagiostats_name@ $(STRIP) $(DESTDIR)$(BINDIR)/@nagiostats_name@
.PHONY: libnagios

View File

@ -2,9 +2,6 @@
* *
* BROKER.C - Event broker routines for Nagios * BROKER.C - Event broker routines for Nagios
* *
* Copyright (c) 2010 Nagios Core Development Team
* Copyright (c) 2002-2006 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-03-2010
* *
* License: * License:
* *
@ -32,31 +29,6 @@
#include "../include/nebstructs.h" #include "../include/nebstructs.h"
#include "../include/nebmods.h" #include "../include/nebmods.h"
extern unsigned long event_broker_options;
extern time_t program_start;
extern int nagios_pid;
extern int daemon_mode;
extern time_t last_command_check;
extern time_t last_log_rotation;
extern int enable_notifications;
extern int execute_service_checks;
extern int accept_passive_service_checks;
extern int execute_host_checks;
extern int accept_passive_host_checks;
extern int enable_event_handlers;
extern int obsess_over_services;
extern int obsess_over_hosts;
extern int enable_flap_detection;
extern int enable_failure_prediction;
extern int process_performance_data;
extern int aggregate_status_updates;
extern unsigned long modified_host_process_attributes;
extern unsigned long modified_service_process_attributes;
extern char *global_host_event_handler;
extern char *global_service_event_handler;
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
@ -241,7 +213,7 @@ int broker_event_handler(int type, int flags, int attr, int eventhandler_type, v
/* send host check data to broker */ /* send host check data to broker */
int broker_host_check(int type, int flags, int attr, host *hst, int check_type, int state, int state_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, char *output, char *long_output, char *perfdata, struct timeval *timestamp) { int broker_host_check(int type, int flags, int attr, host *hst, int check_type, int state, int state_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, char *output, char *long_output, char *perfdata, struct timeval *timestamp, check_result *cr) {
char *command_buf = NULL; char *command_buf = NULL;
char *command_name = NULL; char *command_name = NULL;
char *command_args = NULL; char *command_args = NULL;
@ -287,6 +259,7 @@ int broker_host_check(int type, int flags, int attr, host *hst, int check_type,
ds.output = output; ds.output = output;
ds.long_output = long_output; ds.long_output = long_output;
ds.perf_data = perfdata; ds.perf_data = perfdata;
ds.check_result_ptr = cr;
/* make callbacks */ /* make callbacks */
return_code = neb_make_callbacks(NEBCALLBACK_HOST_CHECK_DATA, (void *)&ds); return_code = neb_make_callbacks(NEBCALLBACK_HOST_CHECK_DATA, (void *)&ds);
@ -300,7 +273,7 @@ int broker_host_check(int type, int flags, int attr, host *hst, int check_type,
/* send service check data to broker */ /* send service check data to broker */
int broker_service_check(int type, int flags, int attr, service *svc, int check_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, struct timeval *timestamp) { int broker_service_check(int type, int flags, int attr, service *svc, int check_type, struct timeval start_time, struct timeval end_time, char *cmd, double latency, double exectime, int timeout, int early_timeout, int retcode, char *cmdline, struct timeval *timestamp, check_result *cr) {
char *command_buf = NULL; char *command_buf = NULL;
char *command_name = NULL; char *command_name = NULL;
char *command_args = NULL; char *command_args = NULL;
@ -347,6 +320,7 @@ int broker_service_check(int type, int flags, int attr, service *svc, int check_
ds.output = svc->plugin_output; ds.output = svc->plugin_output;
ds.long_output = svc->long_plugin_output; ds.long_output = svc->long_plugin_output;
ds.perf_data = svc->perf_data; ds.perf_data = svc->perf_data;
ds.check_result_ptr = cr;
/* make callbacks */ /* make callbacks */
return_code = neb_make_callbacks(NEBCALLBACK_SERVICE_CHECK_DATA, (void *)&ds); return_code = neb_make_callbacks(NEBCALLBACK_SERVICE_CHECK_DATA, (void *)&ds);
@ -488,7 +462,6 @@ void broker_program_status(int type, int flags, int attr, struct timeval *timest
ds.program_start = program_start; ds.program_start = program_start;
ds.pid = nagios_pid; ds.pid = nagios_pid;
ds.daemon_mode = daemon_mode; ds.daemon_mode = daemon_mode;
ds.last_command_check = last_command_check;
ds.last_log_rotation = last_log_rotation; ds.last_log_rotation = last_log_rotation;
ds.notifications_enabled = enable_notifications; ds.notifications_enabled = enable_notifications;
ds.active_service_checks_enabled = execute_service_checks; ds.active_service_checks_enabled = execute_service_checks;
@ -497,7 +470,6 @@ void broker_program_status(int type, int flags, int attr, struct timeval *timest
ds.passive_host_checks_enabled = accept_passive_host_checks; ds.passive_host_checks_enabled = accept_passive_host_checks;
ds.event_handlers_enabled = enable_event_handlers; ds.event_handlers_enabled = enable_event_handlers;
ds.flap_detection_enabled = enable_flap_detection; ds.flap_detection_enabled = enable_flap_detection;
ds.failure_prediction_enabled = enable_failure_prediction;
ds.process_performance_data = process_performance_data; ds.process_performance_data = process_performance_data;
ds.obsess_over_hosts = obsess_over_hosts; ds.obsess_over_hosts = obsess_over_hosts;
ds.obsess_over_services = obsess_over_services; ds.obsess_over_services = obsess_over_services;
@ -975,12 +947,14 @@ void broker_statechange_data(int type, int flags, int attr, int statechange_type
ds.host_name = temp_service->host_name; ds.host_name = temp_service->host_name;
ds.service_description = temp_service->description; ds.service_description = temp_service->description;
ds.output = temp_service->plugin_output; ds.output = temp_service->plugin_output;
ds.longoutput = temp_service->long_plugin_output;
} }
else { else {
temp_host = (host *)data; temp_host = (host *)data;
ds.host_name = temp_host->name; ds.host_name = temp_host->name;
ds.service_description = NULL; ds.service_description = NULL;
ds.output = temp_host->plugin_output; ds.output = temp_host->plugin_output;
ds.longoutput = temp_host->long_plugin_output;
} }
ds.object_ptr = data; ds.object_ptr = data;
ds.state = state; ds.state = state;
@ -1012,6 +986,4 @@ struct timeval get_broker_timestamp(struct timeval *timestamp) {
return tv; return tv;
} }
#endif #endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@
* *
* FLAPPING.C - State flap detection and handling routines for Nagios * FLAPPING.C - State flap detection and handling routines for Nagios
* *
* Copyright (c) 2001-2009 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 05-15-2009
* *
* License: * License:
* *
@ -32,21 +30,6 @@
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/broker.h" #include "../include/broker.h"
extern int interval_length;
extern int enable_flap_detection;
extern double low_service_flap_threshold;
extern double high_service_flap_threshold;
extern double low_host_flap_threshold;
extern double high_host_flap_threshold;
extern host *host_list;
extern service *service_list;
extern unsigned long modified_host_process_attributes;
extern unsigned long modified_service_process_attributes;
/******************************************************************/ /******************************************************************/
/******************** FLAP DETECTION FUNCTIONS ********************/ /******************** FLAP DETECTION FUNCTIONS ********************/
@ -91,14 +74,9 @@ void check_for_service_flapping(service *svc, int update, int allow_flapstart_no
/* should we update state history for this state? */ /* should we update state history for this state? */
if(update_history == TRUE) { if(update_history == TRUE) {
if(svc->current_state == STATE_OK && svc->flap_detection_on_ok == FALSE) if(!should_flap_detect(svc))
update_history = FALSE;
if(svc->current_state == STATE_WARNING && svc->flap_detection_on_warning == FALSE)
update_history = FALSE;
if(svc->current_state == STATE_UNKNOWN && svc->flap_detection_on_unknown == FALSE)
update_history = FALSE;
if(svc->current_state == STATE_CRITICAL && svc->flap_detection_on_critical == FALSE)
update_history = FALSE; update_history = FALSE;
} }
/* record current service state */ /* record current service state */
@ -142,13 +120,13 @@ void check_for_service_flapping(service *svc, int update, int allow_flapstart_no
log_debug_info(DEBUGL_FLAPPING, 2, "LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n", low_threshold, high_threshold, curved_percent_change, curved_percent_change); log_debug_info(DEBUGL_FLAPPING, 2, "LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n", low_threshold, high_threshold, curved_percent_change, curved_percent_change);
/* don't do anything if we don't have flap detection enabled on a program-wide basis */ /* don't do anything if we don't have flap detection enabled
if(enable_flap_detection == FALSE) on a program-wide basis or for this service */
return; if(enable_flap_detection == FALSE || svc->flap_detection_enabled == FALSE) {
if(svc->is_flapping == TRUE)
/* don't do anything if we don't have flap detection enabled for this service */ clear_service_flap(svc, curved_percent_change, high_threshold, low_threshold, 1);
if(svc->flap_detection_enabled == FALSE)
return; return;
}
/* are we flapping, undecided, or what?... */ /* are we flapping, undecided, or what?... */
@ -172,7 +150,7 @@ void check_for_service_flapping(service *svc, int update, int allow_flapstart_no
/* did the service just stop flapping? */ /* did the service just stop flapping? */
else if(is_flapping == FALSE && svc->is_flapping == TRUE) else if(is_flapping == FALSE && svc->is_flapping == TRUE)
clear_service_flap(svc, curved_percent_change, high_threshold, low_threshold); clear_service_flap(svc, curved_percent_change, high_threshold, low_threshold, 0);
return; return;
} }
@ -215,12 +193,9 @@ void check_for_host_flapping(host *hst, int update, int actual_check, int allow_
/* should we update state history for this state? */ /* should we update state history for this state? */
if(update_history == TRUE) { if(update_history == TRUE) {
if(hst->current_state == HOST_UP && hst->flap_detection_on_up == FALSE) if(!(hst->flap_detection_options & (1 << hst->current_state)))
update_history = FALSE;
if(hst->current_state == HOST_DOWN && hst->flap_detection_on_down == FALSE)
update_history = FALSE;
if(hst->current_state == HOST_UNREACHABLE && hst->flap_detection_on_unreachable == FALSE)
update_history = FALSE; update_history = FALSE;
} }
/* if we didn't have an actual check, only update if we've waited long enough */ /* if we didn't have an actual check, only update if we've waited long enough */
@ -278,13 +253,13 @@ void check_for_host_flapping(host *hst, int update, int actual_check, int allow_
log_debug_info(DEBUGL_FLAPPING, 2, "LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n", low_threshold, high_threshold, curved_percent_change, curved_percent_change); log_debug_info(DEBUGL_FLAPPING, 2, "LFT=%.2f, HFT=%.2f, CPC=%.2f, PSC=%.2f%%\n", low_threshold, high_threshold, curved_percent_change, curved_percent_change);
/* don't do anything if we don't have flap detection enabled on a program-wide basis */ /* don't do anything if we don't have flap detection enabled
if(enable_flap_detection == FALSE) on a program-wide basis or for this service */
return; if(enable_flap_detection == FALSE || hst->flap_detection_enabled == FALSE) {
if(hst->is_flapping == TRUE)
/* don't do anything if we don't have flap detection enabled for this host */ clear_host_flap(hst, curved_percent_change, high_threshold, low_threshold, 1);
if(hst->flap_detection_enabled == FALSE)
return; return;
}
/* are we flapping, undecided, or what?... */ /* are we flapping, undecided, or what?... */
@ -308,7 +283,7 @@ void check_for_host_flapping(host *hst, int update, int actual_check, int allow_
/* did the host just stop flapping? */ /* did the host just stop flapping? */
else if(is_flapping == FALSE && hst->is_flapping == TRUE) else if(is_flapping == FALSE && hst->is_flapping == TRUE)
clear_host_flap(hst, curved_percent_change, high_threshold, low_threshold); clear_host_flap(hst, curved_percent_change, high_threshold, low_threshold, 0);
return; return;
} }
@ -361,17 +336,22 @@ void set_service_flap(service *svc, double percent_change, double high_threshold
/* handles a service that has stopped flapping */ /* handles a service that has stopped flapping */
void clear_service_flap(service *svc, double percent_change, double high_threshold, double low_threshold) { void clear_service_flap(service *svc, double percent_change, double high_threshold, double low_threshold, int is_disabled) {
log_debug_info(DEBUGL_FUNCTIONS, 0, "clear_service_flap()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "clear_service_flap()\n");
if(svc == NULL) if(svc == NULL)
return; return;
log_debug_info(DEBUGL_FLAPPING, 1, "Service '%s' on host '%s' stopped flapping.\n", svc->description, svc->host_name); if (is_disabled == 0) {
log_debug_info(DEBUGL_FLAPPING, 1, "Service '%s' on host '%s' stopped flapping.\n", svc->description, svc->host_name);
/* log a notice - this one is parsed by the history CGI */ /* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE FLAPPING ALERT: %s;%s;STOPPED; Service appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n", svc->host_name, svc->description, percent_change, low_threshold); logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE FLAPPING ALERT: %s;%s;STOPPED; Service appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n", svc->host_name, svc->description, percent_change, low_threshold);
} else {
log_debug_info(DEBUGL_FLAPPING, 1, "Disabled flap detection for service '%s' on host '%s'.\n", svc->description, svc->host_name);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "SERVICE FLAPPING ALERT: %s;%s;STOPPED; Disabled flap detection for service\n", svc->host_name, svc->description);
}
/* delete the comment we added earlier */ /* delete the comment we added earlier */
if(svc->flapping_comment_id != 0) if(svc->flapping_comment_id != 0)
@ -386,12 +366,14 @@ void clear_service_flap(service *svc, double percent_change, double high_thresho
broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, NEBATTR_FLAPPING_STOP_NORMAL, SERVICE_FLAPPING, svc, percent_change, high_threshold, low_threshold, NULL); broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, NEBATTR_FLAPPING_STOP_NORMAL, SERVICE_FLAPPING, svc, percent_change, high_threshold, low_threshold, NULL);
#endif #endif
/* send a notification */ if (is_disabled == 0) {
service_notification(svc, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE); /* send a notification */
service_notification(svc, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* should we send a recovery notification? */ /* should we send a recovery notification? */
if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK) if(svc->check_flapping_recovery_notification == TRUE && svc->current_state == STATE_OK)
service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE); service_notification(svc, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
}
/* clear the recovery notification flag */ /* clear the recovery notification flag */
svc->check_flapping_recovery_notification = FALSE; svc->check_flapping_recovery_notification = FALSE;
@ -442,17 +424,22 @@ void set_host_flap(host *hst, double percent_change, double high_threshold, doub
/* handles a host that has stopped flapping */ /* handles a host that has stopped flapping */
void clear_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold) { void clear_host_flap(host *hst, double percent_change, double high_threshold, double low_threshold, int is_disabled) {
log_debug_info(DEBUGL_FUNCTIONS, 0, "clear_host_flap()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "clear_host_flap()\n");
if(hst == NULL) if(hst == NULL)
return; return;
log_debug_info(DEBUGL_FLAPPING, 1, "Host '%s' stopped flapping.\n", hst->name); if (is_disabled == 0) {
log_debug_info(DEBUGL_FLAPPING, 1, "Host '%s' stopped flapping.\n", hst->name);
/* log a notice - this one is parsed by the history CGI */ /* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "HOST FLAPPING ALERT: %s;STOPPED; Host appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n", hst->name, percent_change, low_threshold); logit(NSLOG_INFO_MESSAGE, FALSE, "HOST FLAPPING ALERT: %s;STOPPED; Host appears to have stopped flapping (%2.1f%% change < %2.1f%% threshold)\n", hst->name, percent_change, low_threshold);
} else {
log_debug_info(DEBUGL_FLAPPING, 1, "Disabled flap detection for host '%s'.\n", hst->name);
/* log a notice - this one is parsed by the history CGI */
logit(NSLOG_INFO_MESSAGE, FALSE, "HOST FLAPPING ALERT: %s;STOPPED; Disabled flap detection\n", hst->name);
}
/* delete the comment we added earlier */ /* delete the comment we added earlier */
if(hst->flapping_comment_id != 0) if(hst->flapping_comment_id != 0)
@ -467,12 +454,14 @@ void clear_host_flap(host *hst, double percent_change, double high_threshold, do
broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, NEBATTR_FLAPPING_STOP_NORMAL, HOST_FLAPPING, hst, percent_change, high_threshold, low_threshold, NULL); broker_flapping_data(NEBTYPE_FLAPPING_STOP, NEBFLAG_NONE, NEBATTR_FLAPPING_STOP_NORMAL, HOST_FLAPPING, hst, percent_change, high_threshold, low_threshold, NULL);
#endif #endif
/* send a notification */ if (is_disabled == 0) {
host_notification(hst, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE); /* send a notification */
host_notification(hst, NOTIFICATION_FLAPPINGSTOP, NULL, NULL, NOTIFICATION_OPTION_NONE);
/* should we send a recovery notification? */ /* should we send a recovery notification? */
if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP) if(hst->check_flapping_recovery_notification == TRUE && hst->current_state == HOST_UP)
host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE); host_notification(hst, NOTIFICATION_NORMAL, NULL, NULL, NOTIFICATION_OPTION_NONE);
}
/* clear the recovery notification flag */ /* clear the recovery notification flag */
hst->check_flapping_recovery_notification = FALSE; hst->check_flapping_recovery_notification = FALSE;
@ -488,8 +477,7 @@ void clear_host_flap(host *hst, double percent_change, double high_threshold, do
/* enables flap detection on a program wide basis */ /* enables flap detection on a program wide basis */
void enable_flap_detection_routines(void) { void enable_flap_detection_routines(void) {
host *temp_host = NULL; unsigned int i;
service *temp_service = NULL;
unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED;
log_debug_info(DEBUGL_FUNCTIONS, 0, "enable_flap_detection_routines()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "enable_flap_detection_routines()\n");
@ -514,20 +502,18 @@ void enable_flap_detection_routines(void) {
update_program_status(FALSE); update_program_status(FALSE);
/* check for flapping */ /* check for flapping */
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) for(i = 0; i < num_objects.hosts; i++)
check_for_host_flapping(temp_host, FALSE, FALSE, TRUE); check_for_host_flapping(host_ary[i], FALSE, FALSE, TRUE);
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) for(i = 0; i < num_objects.services; i++)
check_for_service_flapping(temp_service, FALSE, TRUE); check_for_service_flapping(service_ary[i], FALSE, TRUE);
return;
} }
/* disables flap detection on a program wide basis */ /* disables flap detection on a program wide basis */
void disable_flap_detection_routines(void) { void disable_flap_detection_routines(void) {
host *temp_host = NULL; unsigned int i;
service *temp_service = NULL;
unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED; unsigned long attr = MODATTR_FLAP_DETECTION_ENABLED;
log_debug_info(DEBUGL_FUNCTIONS, 0, "disable_flap_detection_routines()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "disable_flap_detection_routines()\n");
@ -552,10 +538,10 @@ void disable_flap_detection_routines(void) {
update_program_status(FALSE); update_program_status(FALSE);
/* handle the details... */ /* handle the details... */
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) for(i = 0; i < num_objects.hosts; i++)
handle_host_flap_detection_disabled(temp_host); handle_host_flap_detection_disabled(host_ary[i]);
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) for(i = 0; i < num_objects.services; i++)
handle_service_flap_detection_disabled(temp_service); handle_service_flap_detection_disabled(service_ary[i]);
return; return;
} }
@ -788,8 +774,3 @@ void handle_service_flap_detection_disabled(service *svc) {
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* LOGGING.C - Log file functions for use with Nagios * LOGGING.C - Log file functions for use with Nagios
* *
* Copyright (c) 1999-2007 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-28-2007
* *
* License: * License:
* *
@ -28,98 +26,11 @@
#include "../include/macros.h" #include "../include/macros.h"
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/broker.h" #include "../include/broker.h"
#include <fcntl.h>
extern char *log_file; static FILE *debug_file_fp;
extern char *temp_file; static FILE *log_fp;
extern char *log_archive_path;
extern host *host_list;
extern service *service_list;
extern int use_syslog;
extern int log_service_retries;
extern int log_initial_states;
extern unsigned long logging_options;
extern unsigned long syslog_options;
extern int verify_config;
extern int test_scheduling;
extern time_t last_log_rotation;
extern int log_rotation_method;
extern int daemon_mode;
extern char *debug_file;
extern int debug_level;
extern int debug_verbosity;
extern unsigned long max_debug_file_size;
FILE *debug_file_fp = NULL;
static pthread_mutex_t debug_fp_lock;
/* These simple helpers should most likely be elsewhere */
static const char *service_state_name(int state) {
switch(state) {
case STATE_OK:
return "OK";
case STATE_WARNING:
return "WARNING";
case STATE_CRITICAL:
return "CRITICAL";
}
return "UNKNOWN";
}
static const char *host_state_name(int state) {
switch(state) {
case HOST_UP:
return "UP";
case HOST_DOWN:
return "DOWN";
case HOST_UNREACHABLE:
return "UNREACHABLE";
}
return "(unknown)";
}
static const char *state_type_name(int state_type) {
return state_type == HARD_STATE ? "HARD" : "SOFT";
}
/*
* since we don't want child processes to hang indefinitely
* in case they inherit a locked lock, we use soft-locking
* here, which basically tries to acquire the lock for a
* short while and then gives up, returning -1 to signal
* the error
*/
static inline int soft_lock(pthread_mutex_t *lock) {
int i;
for(i = 0; i < 5; i++) {
if(!pthread_mutex_trylock(lock)) {
/* success */
return 0;
}
if(errno == EDEADLK) {
/* we already have the lock */
return 0;
}
/* sleep briefly */
usleep(30);
}
return -1; /* we failed to get the lock. Nothing to do */
}
/******************************************************************/ /******************************************************************/
/************************ LOGGING FUNCTIONS ***********************/ /************************ LOGGING FUNCTIONS ***********************/
@ -199,29 +110,92 @@ static void write_to_all_logs_with_timestamp(char *buffer, unsigned long data_ty
} }
static FILE *open_log_file(void)
{
int fh;
struct stat st;
if(log_fp) /* keep it open unless we rotate */
return log_fp;
if ((fh = open(log_file, O_RDWR|O_APPEND|O_CREAT|O_NOFOLLOW, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1) {
if (daemon_mode == FALSE)
printf("Warning: Cannot open log file '%s' for writing\n", log_file);
return NULL;
}
log_fp = fdopen(fh, "a+");
if(log_fp == NULL) {
if (daemon_mode == FALSE)
printf("Warning: Cannot open log file '%s' for writing\n", log_file);
return NULL;
}
if ((fstat(fh, &st)) == -1) {
log_fp = NULL;
close(fh);
if (daemon_mode == FALSE)
printf("Warning: Cannot fstat log file '%s'\n", log_file);
return NULL;
}
if (st.st_nlink != 1 || (st.st_mode & S_IFMT) != S_IFREG) {
log_fp = NULL;
close(fh);
if (daemon_mode == FALSE)
printf("Warning: log file '%s' has an invalid mode\n", log_file);
return NULL;
}
(void)fcntl(fileno(log_fp), F_SETFD, FD_CLOEXEC);
return log_fp;
}
int fix_log_file_owner(uid_t uid, gid_t gid)
{
int r1 = 0, r2 = 0;
if (!(log_fp = open_log_file()))
return -1;
r1 = fchown(fileno(log_fp), uid, gid);
if (open_debug_log() != OK)
return -1;
if (debug_file_fp)
r2 = fchown(fileno(debug_file_fp), uid, gid);
/* return 0 if both are 0 and otherwise < 0 */
return r1 < r2 ? r1 : r2;
}
int close_log_file(void)
{
if(!log_fp)
return 0;
fflush(log_fp);
fclose(log_fp);
log_fp = NULL;
return 0;
}
/* write something to the nagios log file */ /* write something to the nagios log file */
int write_to_log(char *buffer, unsigned long data_type, time_t *timestamp) { int write_to_log(char *buffer, unsigned long data_type, time_t *timestamp) {
FILE *fp = NULL; FILE *fp;
time_t log_time = 0L; time_t log_time = 0L;
if(buffer == NULL) if(buffer == NULL)
return ERROR; return ERROR;
/* don't log anything if we're not actually running... */ /* don't log anything if we're not actually running... */
if(verify_config == TRUE || test_scheduling == TRUE) if(verify_config || test_scheduling == TRUE)
return OK; return OK;
/* make sure we can log this type of entry */ /* make sure we can log this type of entry */
if(!(data_type & logging_options)) if(!(data_type & logging_options))
return OK; return OK;
fp = fopen(log_file, "a+"); fp = open_log_file();
if(fp == NULL) { if (fp == NULL)
if(daemon_mode == FALSE)
printf("Warning: Cannot open log file '%s' for writing\n", log_file);
return ERROR; return ERROR;
}
/* what timestamp should we use? */ /* what timestamp should we use? */
if(timestamp == NULL) if(timestamp == NULL)
time(&log_time); time(&log_time);
@ -232,9 +206,8 @@ int write_to_log(char *buffer, unsigned long data_type, time_t *timestamp) {
strip(buffer); strip(buffer);
/* write the buffer to the log file */ /* write the buffer to the log file */
fprintf(fp, "[%lu] %s\n", log_time, buffer); fprintf(fp, "[%llu] %s\n", (unsigned long long)log_time, buffer);
fflush(fp);
fclose(fp);
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
/* send data to the event broker */ /* send data to the event broker */
@ -252,7 +225,7 @@ int write_to_syslog(char *buffer, unsigned long data_type) {
return ERROR; return ERROR;
/* don't log anything if we're not actually running... */ /* don't log anything if we're not actually running... */
if(verify_config == TRUE || test_scheduling == TRUE) if(verify_config || test_scheduling == TRUE)
return OK; return OK;
/* bail out if we shouldn't write to syslog */ /* bail out if we shouldn't write to syslog */
@ -295,13 +268,14 @@ int log_service_event(service *svc) {
return ERROR; return ERROR;
asprintf(&temp_buffer, "SERVICE ALERT: %s;%s;%s;%s;%d;%s\n", asprintf(&temp_buffer, "SERVICE ALERT: %s;%s;%s;%s;%d;%s\n",
svc->host_name, svc->description, svc->host_name, svc->description,
service_state_name(svc->current_state), service_state_name(svc->current_state),
state_type_name(svc->state_type), state_type_name(svc->state_type),
svc->current_attempt, svc->current_attempt,
(svc->plugin_output == NULL) ? "" : svc->plugin_output); (svc->plugin_output == NULL) ? "" : svc->plugin_output);
write_to_all_logs(temp_buffer, log_options); write_to_all_logs(temp_buffer, log_options);
free(temp_buffer);
return OK; return OK;
} }
@ -321,11 +295,11 @@ int log_host_event(host *hst) {
log_options = NSLOG_HOST_UP; log_options = NSLOG_HOST_UP;
asprintf(&temp_buffer, "HOST ALERT: %s;%s;%s;%d;%s\n", asprintf(&temp_buffer, "HOST ALERT: %s;%s;%s;%d;%s\n",
hst->name, hst->name,
host_state_name(hst->current_state), host_state_name(hst->current_state),
state_type_name(hst->state_type), state_type_name(hst->state_type),
hst->current_attempt, hst->current_attempt,
(hst->plugin_output == NULL) ? "" : hst->plugin_output); (hst->plugin_output == NULL) ? "" : hst->plugin_output);
write_to_all_logs(temp_buffer, log_options); write_to_all_logs(temp_buffer, log_options);
@ -347,11 +321,11 @@ int log_host_states(int type, time_t *timestamp) {
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) { for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
asprintf(&temp_buffer, "%s HOST STATE: %s;%s;%s;%d;%s\n", (type == INITIAL_STATES) ? "INITIAL" : "CURRENT", asprintf(&temp_buffer, "%s HOST STATE: %s;%s;%s;%d;%s\n", (type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
temp_host->name, temp_host->name,
host_state_name(temp_host->current_state), host_state_name(temp_host->current_state),
state_type_name(temp_host->state_type), state_type_name(temp_host->state_type),
temp_host->current_attempt, temp_host->current_attempt,
(temp_host->plugin_output == NULL) ? "" : temp_host->plugin_output); (temp_host->plugin_output == NULL) ? "" : temp_host->plugin_output);
write_to_all_logs_with_timestamp(temp_buffer, NSLOG_INFO_MESSAGE, timestamp); write_to_all_logs_with_timestamp(temp_buffer, NSLOG_INFO_MESSAGE, timestamp);
@ -379,12 +353,12 @@ int log_service_states(int type, time_t *timestamp) {
continue; continue;
asprintf(&temp_buffer, "%s SERVICE STATE: %s;%s;%s;%s;%d;%s\n", asprintf(&temp_buffer, "%s SERVICE STATE: %s;%s;%s;%s;%d;%s\n",
(type == INITIAL_STATES) ? "INITIAL" : "CURRENT", (type == INITIAL_STATES) ? "INITIAL" : "CURRENT",
temp_service->host_name, temp_service->description, temp_service->host_name, temp_service->description,
service_state_name(temp_service->current_state), service_state_name(temp_service->current_state),
state_type_name(temp_service->state_type), state_type_name(temp_service->state_type),
temp_service->current_attempt, temp_service->current_attempt,
temp_service->plugin_output); temp_service->plugin_output);
write_to_all_logs_with_timestamp(temp_buffer, NSLOG_INFO_MESSAGE, timestamp); write_to_all_logs_with_timestamp(temp_buffer, NSLOG_INFO_MESSAGE, timestamp);
@ -404,6 +378,8 @@ int rotate_log_file(time_t rotation_time) {
int rename_result = 0; int rename_result = 0;
int stat_result = -1; int stat_result = -1;
struct stat log_file_stat; struct stat log_file_stat;
struct stat archive_stat;
int archive_stat_result;
if(log_rotation_method == LOG_ROTATION_NONE) { if(log_rotation_method == LOG_ROTATION_NONE) {
return OK; return OK;
@ -427,11 +403,26 @@ int rotate_log_file(time_t rotation_time) {
stat_result = stat(log_file, &log_file_stat); stat_result = stat(log_file, &log_file_stat);
close_log_file();
/* get the archived filename to use */ /* get the archived filename to use */
asprintf(&log_archive, "%s%snagios-%02d-%02d-%d-%02d.log", log_archive_path, (log_archive_path[strlen(log_archive_path) - 1] == '/') ? "" : "/", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour); asprintf(&log_archive, "%s%snagios-%02d-%02d-%d-%02d.log", log_archive_path, (log_archive_path[strlen(log_archive_path) - 1] == '/') ? "" : "/", t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour);
/* HACK: If the archive exists, don't overwrite it. This is a hack
because the real problem is that some log rotations are executed
early and as a result the next log rotation is scheduled for
the same time as the one that ran early */
archive_stat_result = stat(log_archive, &archive_stat);
if((0 == archive_stat_result) ||
((-1 == archive_stat_result) && (ENOENT != errno))) {
return OK;
}
/* rotate the log file */ /* rotate the log file */
rename_result = my_rename(log_file, log_archive); rename_result = my_rename(log_file, log_archive);
log_fp = open_log_file();
if (log_fp == NULL)
return ERROR;
if(rename_result) { if(rename_result) {
my_free(log_archive); my_free(log_archive);
@ -451,9 +442,11 @@ int rotate_log_file(time_t rotation_time) {
chown(log_file, log_file_stat.st_uid, log_file_stat.st_gid); chown(log_file, log_file_stat.st_uid, log_file_stat.st_gid);
} }
/* log current host and service state */ /* log current host and service state if activated */
log_host_states(CURRENT_STATES, &rotation_time); if(log_current_states==TRUE) {
log_service_states(CURRENT_STATES, &rotation_time); log_host_states(CURRENT_STATES, &rotation_time);
log_service_states(CURRENT_STATES, &rotation_time);
}
/* free memory */ /* free memory */
my_free(log_archive); my_free(log_archive);
@ -476,41 +469,36 @@ int write_log_file_info(time_t *timestamp) {
/* opens the debug log for writing */ /* opens the debug log for writing */
int open_debug_log(void) { int open_debug_log(void)
{
int fh;
struct stat st;
/* don't do anything if we're not actually running... */ /* don't do anything if we're not actually running... */
if(verify_config == TRUE || test_scheduling == TRUE) if(verify_config || test_scheduling == TRUE)
return OK; return OK;
/* don't do anything if we're not debugging */ /* don't do anything if we're not debugging */
if(debug_level == DEBUGL_NONE) if(debug_level == DEBUGL_NONE)
return OK; return OK;
if((debug_file_fp = fopen(debug_file, "a+")) == NULL) if ((fh = open(debug_file, O_RDWR|O_APPEND|O_CREAT|O_NOFOLLOW, S_IRUSR|S_IWUSR)) == -1)
return ERROR;
if((debug_file_fp = fdopen(fh, "a+")) == NULL)
return ERROR; return ERROR;
return OK; if ((fstat(fh, &st)) == -1) {
debug_file_fp = NULL;
close(fh);
return ERROR;
}
if (st.st_nlink != 1 || (st.st_mode & S_IFMT) != S_IFREG) {
debug_file_fp = NULL;
close(fh);
return ERROR;
} }
(void)fcntl(fh, F_SETFD, FD_CLOEXEC);
/* change the ownership of the debug log. This is done so that if Nagios
receives a HUP signal, it will be owned by a user that can reopen the file */
int chown_debug_log(uid_t uid, gid_t gid) {
/* don't do anything if we're not actually running... */
if(verify_config == TRUE || test_scheduling == TRUE)
return OK;
/* don't do anything if we're not debugging */
if(debug_level == DEBUGL_NONE)
return OK;
if(chown(debug_file, uid, gid) < 0) {
logit(NSLOG_RUNTIME_WARNING, TRUE,
"Failed to change ownership on debug log: %s.",
strerror(errno));
return ERROR;
}
return OK; return OK;
} }
@ -531,7 +519,7 @@ int close_debug_log(void) {
/* write to the debug log */ /* write to the debug log */
int log_debug_info(int level, int verbosity, const char *fmt, ...) { int log_debug_info(int level, int verbosity, const char *fmt, ...) {
va_list ap; va_list ap;
char *temp_path = NULL; char *tmppath = NULL;
struct timeval current_time; struct timeval current_time;
if(!(debug_level == DEBUGL_ALL || (level & debug_level))) if(!(debug_level == DEBUGL_ALL || (level & debug_level)))
@ -543,15 +531,6 @@ int log_debug_info(int level, int verbosity, const char *fmt, ...) {
if(debug_file_fp == NULL) if(debug_file_fp == NULL)
return ERROR; return ERROR;
/*
* lock it so concurrent threads don't stomp on each other's
* writings. We maintain the lock until we've (optionally)
* renamed the file.
* If soft_lock() fails we return early.
*/
if(soft_lock(&debug_fp_lock) < 0)
return ERROR;
/* write the timestamp */ /* write the timestamp */
gettimeofday(&current_time, NULL); gettimeofday(&current_time, NULL);
fprintf(debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, (unsigned long)getpid()); fprintf(debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, (unsigned long)getpid());
@ -571,25 +550,22 @@ int log_debug_info(int level, int verbosity, const char *fmt, ...) {
close_debug_log(); close_debug_log();
/* rotate the log file */ /* rotate the log file */
asprintf(&temp_path, "%s.old", debug_file); asprintf(&tmppath, "%s.old", debug_file);
if(temp_path) { if(tmppath) {
/* unlink the old debug file */ /* unlink the old debug file */
unlink(temp_path); unlink(tmppath);
/* rotate the debug file */ /* rotate the debug file */
my_rename(debug_file, temp_path); my_rename(debug_file, tmppath);
/* free memory */ /* free memory */
my_free(temp_path); my_free(tmppath);
} }
/* open a new file */ /* open a new file */
open_debug_log(); open_debug_log();
} }
pthread_mutex_unlock(&debug_fp_lock);
return OK; return OK;
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,7 @@
* NAGIOSTATS.C - Displays Nagios Statistics * NAGIOSTATS.C - Displays Nagios Statistics
* *
* Program: Nagiostats * Program: Nagiostats
* Version: 3.5.1
* License: GPL * License: GPL
* Copyright (c) 2003-2008 Ethan Galstad (egalstad@nagios.org)
*
* Last Modified: 12-20-2008
* *
* License: * License:
* *
@ -26,6 +22,7 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "../lib/libnagios.h"
#include "../include/config.h" #include "../include/config.h"
#include "../include/common.h" #include "../include/common.h"
#include "../include/nagios.h" #include "../include/nagios.h"
@ -38,175 +35,165 @@
#define STATUS_SERVICE_DATA 4 #define STATUS_SERVICE_DATA 4
char *main_config_file = NULL; static char *main_config_file = NULL;
char *status_file = NULL; char *status_file = NULL;
char *nagiostats_file = NULL; static char *mrtg_variables = NULL;
char *mrtg_variables = NULL; static const char *mrtg_delimiter = "\n";
char *mrtg_delimiter = "\n";
int mrtg_mode = FALSE; static int mrtg_mode = FALSE;
time_t status_creation_date = 0L; static time_t status_creation_date = 0L;
char *status_version = NULL; static char *status_version = NULL;
time_t program_start = 0L; time_t program_start = 0L;
int status_service_entries = 0; static int status_service_entries = 0;
int status_host_entries = 0; static int status_host_entries = 0;
unsigned long nagios_pid = 0L; int nagios_pid = 0;
double min_service_state_change = 0.0; static double min_service_state_change = 0.0;
int have_min_service_state_change = FALSE; static int have_min_service_state_change = FALSE;
double max_service_state_change = 0.0; static double max_service_state_change = 0.0;
int have_max_service_state_change = FALSE; static int have_max_service_state_change = FALSE;
double average_service_state_change = 0.0; static double average_service_state_change = 0.0;
double min_active_service_state_change = 0.0; static double min_active_service_state_change = 0.0;
int have_min_active_service_state_change = FALSE; static int have_min_active_service_state_change = FALSE;
double max_active_service_state_change = 0.0; static double max_active_service_state_change = 0.0;
int have_max_active_service_state_change = FALSE; static int have_max_active_service_state_change = FALSE;
double average_active_service_state_change = 0.0; static double average_active_service_state_change = 0.0;
double min_active_service_latency = 0.0; static double min_active_service_latency = 0.0;
int have_min_active_service_latency = FALSE; static int have_min_active_service_latency = FALSE;
double max_active_service_latency = 0.0; static double max_active_service_latency = 0.0;
int have_max_active_service_latency = FALSE; static int have_max_active_service_latency = FALSE;
double average_active_service_latency = 0.0; static double average_active_service_latency = 0.0;
double min_active_service_execution_time = 0.0; static double min_active_service_execution_time = 0.0;
int have_min_active_service_execution_time = FALSE; static int have_min_active_service_execution_time = FALSE;
double max_active_service_execution_time = 0.0; static double max_active_service_execution_time = 0.0;
int have_max_active_service_execution_time = FALSE; static int have_max_active_service_execution_time = FALSE;
double average_active_service_execution_time = 0.0; static double average_active_service_execution_time = 0.0;
double min_passive_service_state_change = 0.0; static double min_passive_service_state_change = 0.0;
int have_min_passive_service_state_change = FALSE; static int have_min_passive_service_state_change = FALSE;
double max_passive_service_state_change = 0.0; static double max_passive_service_state_change = 0.0;
int have_max_passive_service_state_change = FALSE; static int have_max_passive_service_state_change = FALSE;
double average_passive_service_state_change = 0.0; static double average_passive_service_state_change = 0.0;
double min_passive_service_latency = 0.0; static double min_passive_service_latency = 0.0;
int have_min_passive_service_latency = FALSE; static int have_min_passive_service_latency = FALSE;
double max_passive_service_latency = 0.0; static double max_passive_service_latency = 0.0;
int have_max_passive_service_latency = FALSE; static int have_max_passive_service_latency = FALSE;
double average_passive_service_latency = 0.0; static double average_passive_service_latency = 0.0;
int have_min_host_state_change = FALSE; static int have_min_host_state_change = FALSE;
double min_host_state_change = 0.0; static double min_host_state_change = 0.0;
int have_max_host_state_change = FALSE; static int have_max_host_state_change = FALSE;
double max_host_state_change = 0.0; static double max_host_state_change = 0.0;
double average_host_state_change = 0.0; static double average_host_state_change = 0.0;
int have_min_active_host_state_change = FALSE; static int have_min_active_host_state_change = FALSE;
double min_active_host_state_change = 0.0; static double min_active_host_state_change = 0.0;
int have_max_active_host_state_change = FALSE; static int have_max_active_host_state_change = FALSE;
double max_active_host_state_change = 0.0; static double max_active_host_state_change = 0.0;
double average_active_host_state_change = 0.0; static double average_active_host_state_change = 0.0;
int have_min_active_host_latency = FALSE; static int have_min_active_host_latency = FALSE;
double min_active_host_latency = 0.0; static double min_active_host_latency = 0.0;
int have_max_active_host_latency = FALSE; static int have_max_active_host_latency = FALSE;
double max_active_host_latency = 0.0; static double max_active_host_latency = 0.0;
double average_active_host_latency = 0.0; static double average_active_host_latency = 0.0;
int have_min_active_host_execution_time = FALSE; static int have_min_active_host_execution_time = FALSE;
double min_active_host_execution_time = 0.0; static double min_active_host_execution_time = 0.0;
int have_max_active_host_execution_time = FALSE; static int have_max_active_host_execution_time = FALSE;
double max_active_host_execution_time = 0.0; static double max_active_host_execution_time = 0.0;
double average_active_host_execution_time = 0.0; static double average_active_host_execution_time = 0.0;
int have_min_passive_host_latency = FALSE; static int have_min_passive_host_latency = FALSE;
double min_passive_host_latency = 0.0; static double min_passive_host_latency = 0.0;
int have_max_passive_host_latency = FALSE; static int have_max_passive_host_latency = FALSE;
double max_passive_host_latency = 0.0; static double max_passive_host_latency = 0.0;
double average_passive_host_latency = 0.0; static double average_passive_host_latency = 0.0;
double min_passive_host_state_change = 0.0; static double min_passive_host_state_change = 0.0;
int have_min_passive_host_state_change = FALSE; static int have_min_passive_host_state_change = FALSE;
double max_passive_host_state_change = 0.0; static double max_passive_host_state_change = 0.0;
int have_max_passive_host_state_change = FALSE; static int have_max_passive_host_state_change = FALSE;
double average_passive_host_state_change = 0.0; static double average_passive_host_state_change = 0.0;
int passive_service_checks = 0; static int passive_service_checks = 0;
int active_service_checks = 0; static int active_service_checks = 0;
int services_ok = 0; static int services_ok = 0;
int services_warning = 0; static int services_warning = 0;
int services_unknown = 0; static int services_unknown = 0;
int services_critical = 0; static int services_critical = 0;
int services_flapping = 0; static int services_flapping = 0;
int services_in_downtime = 0; static int services_in_downtime = 0;
int services_checked = 0; static int services_checked = 0;
int services_scheduled = 0; static int services_scheduled = 0;
int passive_host_checks = 0; static int passive_host_checks = 0;
int active_host_checks = 0; static int active_host_checks = 0;
int hosts_up = 0; static int hosts_up = 0;
int hosts_down = 0; static int hosts_down = 0;
int hosts_unreachable = 0; static int hosts_unreachable = 0;
int hosts_flapping = 0; static int hosts_flapping = 0;
int hosts_in_downtime = 0; static int hosts_in_downtime = 0;
int hosts_checked = 0; static int hosts_checked = 0;
int hosts_scheduled = 0; static int hosts_scheduled = 0;
int passive_services_checked_last_1min = 0; static int passive_services_checked_last_1min = 0;
int passive_services_checked_last_5min = 0; static int passive_services_checked_last_5min = 0;
int passive_services_checked_last_15min = 0; static int passive_services_checked_last_15min = 0;
int passive_services_checked_last_1hour = 0; static int passive_services_checked_last_1hour = 0;
int active_services_checked_last_1min = 0; static int active_services_checked_last_1min = 0;
int active_services_checked_last_5min = 0; static int active_services_checked_last_5min = 0;
int active_services_checked_last_15min = 0; static int active_services_checked_last_15min = 0;
int active_services_checked_last_1hour = 0; static int active_services_checked_last_1hour = 0;
int passive_hosts_checked_last_1min = 0; static int passive_hosts_checked_last_1min = 0;
int passive_hosts_checked_last_5min = 0; static int passive_hosts_checked_last_5min = 0;
int passive_hosts_checked_last_15min = 0; static int passive_hosts_checked_last_15min = 0;
int passive_hosts_checked_last_1hour = 0; static int passive_hosts_checked_last_1hour = 0;
int active_hosts_checked_last_1min = 0; static int active_hosts_checked_last_1min = 0;
int active_hosts_checked_last_5min = 0; static int active_hosts_checked_last_5min = 0;
int active_hosts_checked_last_15min = 0; static int active_hosts_checked_last_15min = 0;
int active_hosts_checked_last_1hour = 0; static int active_hosts_checked_last_1hour = 0;
int active_host_checks_last_1min = 0; static int active_host_checks_last_1min = 0;
int active_host_checks_last_5min = 0; static int active_host_checks_last_5min = 0;
int active_host_checks_last_15min = 0; static int active_host_checks_last_15min = 0;
int active_ondemand_host_checks_last_1min = 0; static int active_ondemand_host_checks_last_1min = 0;
int active_ondemand_host_checks_last_5min = 0; static int active_ondemand_host_checks_last_5min = 0;
int active_ondemand_host_checks_last_15min = 0; static int active_ondemand_host_checks_last_15min = 0;
int active_scheduled_host_checks_last_1min = 0; static int active_scheduled_host_checks_last_1min = 0;
int active_scheduled_host_checks_last_5min = 0; static int active_scheduled_host_checks_last_5min = 0;
int active_scheduled_host_checks_last_15min = 0; static int active_scheduled_host_checks_last_15min = 0;
int passive_host_checks_last_1min = 0; static int passive_host_checks_last_1min = 0;
int passive_host_checks_last_5min = 0; static int passive_host_checks_last_5min = 0;
int passive_host_checks_last_15min = 0; static int passive_host_checks_last_15min = 0;
int active_cached_host_checks_last_1min = 0; static int active_cached_host_checks_last_1min = 0;
int active_cached_host_checks_last_5min = 0; static int active_cached_host_checks_last_5min = 0;
int active_cached_host_checks_last_15min = 0; static int active_cached_host_checks_last_15min = 0;
int parallel_host_checks_last_1min = 0; static int parallel_host_checks_last_1min = 0;
int parallel_host_checks_last_5min = 0; static int parallel_host_checks_last_5min = 0;
int parallel_host_checks_last_15min = 0; static int parallel_host_checks_last_15min = 0;
int serial_host_checks_last_1min = 0; static int serial_host_checks_last_1min = 0;
int serial_host_checks_last_5min = 0; static int serial_host_checks_last_5min = 0;
int serial_host_checks_last_15min = 0; static int serial_host_checks_last_15min = 0;
int active_service_checks_last_1min = 0; static int active_service_checks_last_1min = 0;
int active_service_checks_last_5min = 0; static int active_service_checks_last_5min = 0;
int active_service_checks_last_15min = 0; static int active_service_checks_last_15min = 0;
int active_ondemand_service_checks_last_1min = 0; static int active_ondemand_service_checks_last_1min = 0;
int active_ondemand_service_checks_last_5min = 0; static int active_ondemand_service_checks_last_5min = 0;
int active_ondemand_service_checks_last_15min = 0; static int active_ondemand_service_checks_last_15min = 0;
int active_scheduled_service_checks_last_1min = 0; static int active_scheduled_service_checks_last_1min = 0;
int active_scheduled_service_checks_last_5min = 0; static int active_scheduled_service_checks_last_5min = 0;
int active_scheduled_service_checks_last_15min = 0; static int active_scheduled_service_checks_last_15min = 0;
int passive_service_checks_last_1min = 0; static int passive_service_checks_last_1min = 0;
int passive_service_checks_last_5min = 0; static int passive_service_checks_last_5min = 0;
int passive_service_checks_last_15min = 0; static int passive_service_checks_last_15min = 0;
int active_cached_service_checks_last_1min = 0; static int active_cached_service_checks_last_1min = 0;
int active_cached_service_checks_last_5min = 0; static int active_cached_service_checks_last_5min = 0;
int active_cached_service_checks_last_15min = 0; static int active_cached_service_checks_last_15min = 0;
int external_commands_last_1min = 0; static int external_commands_last_1min = 0;
int external_commands_last_5min = 0; static int external_commands_last_5min = 0;
int external_commands_last_15min = 0; static int external_commands_last_15min = 0;
int total_external_command_buffer_slots = 0; static int display_mrtg_values(void);
int used_external_command_buffer_slots = 0; static int display_stats(void);
int high_external_command_buffer_slots = 0; static int read_config_file(void);
static int read_status_file(void);
int display_mrtg_values(void);
int display_stats(void);
int read_config_file(void);
int read_status_file(void);
void strip(char *);
void get_time_breakdown(unsigned long, int *, int *, int *, int *);
int read_nagiostats_file(void);
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -219,30 +206,26 @@ int main(int argc, char **argv) {
#ifdef HAVE_GETOPT_H #ifdef HAVE_GETOPT_H
int option_index = 0; int option_index = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, NULL, 'h'},
{"version", no_argument, 0, 'V'}, {"version", no_argument, NULL, 'V'},
{"license", no_argument, 0, 'L'}, {"license", no_argument, NULL, 'L'},
{"config", required_argument, 0, 'c'}, {"config", required_argument, NULL, 'c'},
{"statsfile", required_argument, 0, 's'}, {"statsfile", required_argument, NULL, 's'},
{"mrtg", no_argument, 0, 'm'}, {"mrtg", no_argument, NULL, 'm'},
{"data", required_argument, 0, 'd'}, {"data", required_argument, NULL, 'd'},
{"delimiter", required_argument, 0, 'D'}, {"delimiter", required_argument, NULL, 'D'},
{0, 0, 0, 0} {NULL, 0, NULL, 0}
}; };
#define getopt(argc, argv, OPTSTR) getopt_long(argc, argv, OPTSTR, long_options, &option_index)
#endif #endif
/* defaults */ /* defaults */
main_config_file = strdup(DEFAULT_CONFIG_FILE); main_config_file = strdup(DEFAULT_CONFIG_FILE);
status_file = strdup(DEFAULT_STATUS_FILE);
/* get all command line arguments */ /* get all command line arguments */
while(1) { while(1) {
#ifdef HAVE_GETOPT_H
c = getopt_long(argc, argv, "+hVLc:ms:d:D:", long_options, &option_index);
#else
c = getopt(argc, argv, "+hVLc:ms:d:D:"); c = getopt(argc, argv, "+hVLc:ms:d:D:");
#endif
if(c == -1 || c == EOF) if(c == -1 || c == EOF)
break; break;
@ -265,7 +248,7 @@ int main(int argc, char **argv) {
main_config_file = strdup(optarg); main_config_file = strdup(optarg);
break; break;
case 's': case 's':
nagiostats_file = strdup(optarg); status_file = strdup(optarg);
break; break;
case 'm': case 'm':
mrtg_mode = TRUE; mrtg_mode = TRUE;
@ -280,7 +263,6 @@ int main(int argc, char **argv) {
default: default:
break; break;
} }
} }
if(mrtg_mode == FALSE) { if(mrtg_mode == FALSE) {
@ -324,7 +306,7 @@ int main(int argc, char **argv) {
printf("\n"); printf("\n");
printf("Output:\n"); printf("Output:\n");
printf(" -m, --mrtg display output in MRTG compatible format.\n"); printf(" -m, --mrtg display output in MRTG compatible format.\n");
printf(" -d, --data=VARS comma-seperated list of variables to output in MRTG\n"); printf(" -d, --data=VARS comma-separated list of variables to output in MRTG\n");
printf(" (or compatible) format. See possible values below.\n"); printf(" (or compatible) format. See possible values below.\n");
printf(" Percentages are rounded, times are in milliseconds.\n"); printf(" Percentages are rounded, times are in milliseconds.\n");
printf(" -D, --delimiter=C character to use as delimiter in MRTG output mode.\n"); printf(" -D, --delimiter=C character to use as delimiter in MRTG output mode.\n");
@ -336,7 +318,7 @@ int main(int argc, char **argv) {
printf(" STATUSFILEAGE string with age of status data file.\n"); printf(" STATUSFILEAGE string with age of status data file.\n");
printf(" STATUSFILEAGETT string with age of status data file (time_t format).\n"); printf(" STATUSFILEAGETT string with age of status data file (time_t format).\n");
printf(" NAGIOSVERSION string with Nagios version.\n"); printf(" NAGIOSVERSION string with Nagios version.\n");
printf(" NAGIOSPID pid number of Nagios deamon.\n"); printf(" NAGIOSPID pid number of Nagios daemon.\n");
printf(" NAGIOSVERPID string with Nagios version and PID.\n"); printf(" NAGIOSVERPID string with Nagios version and PID.\n");
printf(" TOTCMDBUF total number of external command buffer slots available.\n"); printf(" TOTCMDBUF total number of external command buffer slots available.\n");
printf(" USEDCMDBUF number of external command buffer slots currently in use.\n"); printf(" USEDCMDBUF number of external command buffer slots currently in use.\n");
@ -347,7 +329,7 @@ int main(int argc, char **argv) {
printf(" NUMSVCWARN number of services WARNING.\n"); printf(" NUMSVCWARN number of services WARNING.\n");
printf(" NUMSVCUNKN number of services UNKNOWN.\n"); printf(" NUMSVCUNKN number of services UNKNOWN.\n");
printf(" NUMSVCCRIT number of services CRITICAL.\n"); printf(" NUMSVCCRIT number of services CRITICAL.\n");
printf(" NUMSVCPROB number of service problems (WARNING, UNKNOWN or CRITIAL).\n"); printf(" NUMSVCPROB number of service problems (WARNING, UNKNOWN or CRITICAL).\n");
printf(" NUMSVCCHECKED number of services that have been checked since start.\n"); printf(" NUMSVCCHECKED number of services that have been checked since start.\n");
printf(" NUMSVCSCHEDULED number of services that are currently scheduled to be checked.\n"); printf(" NUMSVCSCHEDULED number of services that are currently scheduled to be checked.\n");
printf(" NUMSVCFLAPPING number of services that are currently flapping.\n"); printf(" NUMSVCFLAPPING number of services that are currently flapping.\n");
@ -376,18 +358,18 @@ int main(int argc, char **argv) {
printf(" xxxPSVHSTLAT MIN/MAX/AVG passive host check latency (ms).\n"); printf(" xxxPSVHSTLAT MIN/MAX/AVG passive host check latency (ms).\n");
printf(" xxxPSVHSTPSC MIN/MAX/AVG passive host check %% state change.\n"); printf(" xxxPSVHSTPSC MIN/MAX/AVG passive host check %% state change.\n");
printf(" xxxHSTPSC MIN/MAX/AVG host check %% state change.\n"); printf(" xxxHSTPSC MIN/MAX/AVG host check %% state change.\n");
printf(" NUMACTHSTCHECKSxM number of total active host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMACTHSTCHECKSxM number of total active host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMOACTHSTCHECKSxM number of on-demand active host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMOACTHSTCHECKSxM number of on-demand active host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMCACHEDHSTCHECKSxM number of cached host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMCACHEDHSTCHECKSxM number of cached host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMSACTHSTCHECKSxM number of scheduled active host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMSACTHSTCHECKSxM number of scheduled active host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMPARHSTCHECKSxM number of parallel host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMPARHSTCHECKSxM number of parallel host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMSERHSTCHECKSxM number of serial host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMSERHSTCHECKSxM number of serial host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMPSVHSTCHECKSxM number of passive host checks occuring in last 1/5/15 minutes.\n"); printf(" NUMPSVHSTCHECKSxM number of passive host checks occurring in last 1/5/15 minutes.\n");
printf(" NUMACTSVCCHECKSxM number of total active service checks occuring in last 1/5/15 minutes.\n"); printf(" NUMACTSVCCHECKSxM number of total active service checks occurring in last 1/5/15 minutes.\n");
printf(" NUMOACTSVCCHECKSxM number of on-demand active service checks occuring in last 1/5/15 minutes.\n"); printf(" NUMOACTSVCCHECKSxM number of on-demand active service checks occurring in last 1/5/15 minutes.\n");
printf(" NUMCACHEDSVCCHECKSxM number of cached service checks occuring in last 1/5/15 minutes.\n"); printf(" NUMCACHEDSVCCHECKSxM number of cached service checks occurring in last 1/5/15 minutes.\n");
printf(" NUMSACTSVCCHECKSxM number of scheduled active service checks occuring in last 1/5/15 minutes.\n"); printf(" NUMSACTSVCCHECKSxM number of scheduled active service checks occurring in last 1/5/15 minutes.\n");
printf(" NUMPSVSVCCHECKSxM number of passive service checks occuring in last 1/5/15 minutes.\n"); printf(" NUMPSVSVCCHECKSxM number of passive service checks occurring in last 1/5/15 minutes.\n");
printf(" NUMEXTCMDSxM number of external commands processed in last 1/5/15 minutes.\n"); printf(" NUMEXTCMDSxM number of external commands processed in last 1/5/15 minutes.\n");
printf("\n"); printf("\n");
@ -398,30 +380,21 @@ int main(int argc, char **argv) {
exit(ERROR); exit(ERROR);
} }
/* read pre-processed stats file */ /* if we got no -s option, we must read the main config file */
if(nagiostats_file) { if (status_file == NULL) {
result = read_nagiostats_file();
if(result == ERROR && mrtg_mode == FALSE) {
printf("Error reading stats file '%s': %s\n", nagiostats_file, strerror(errno));
return ERROR;
}
}
/* else read the normal status file */
else {
/* read main config file */ /* read main config file */
result = read_config_file(); result = read_config_file();
if(result == ERROR && mrtg_mode == FALSE) { if(result == ERROR && mrtg_mode == FALSE) {
printf("Error processing config file '%s'\n", main_config_file); printf("Error processing config file '%s'\n", main_config_file);
return ERROR; return ERROR;
} }
}
/* read status file */ /* read status file */
result = read_status_file(); result = read_status_file();
if(result == ERROR && mrtg_mode == FALSE) { if(result == ERROR && mrtg_mode == FALSE) {
printf("Error reading status file '%s': %s\n", status_file, strerror(errno)); printf("Error reading status file '%s': %s\n", status_file, strerror(errno));
return ERROR; return ERROR;
}
} }
/* display stats */ /* display stats */
@ -430,9 +403,6 @@ int main(int argc, char **argv) {
else else
display_mrtg_values(); display_mrtg_values();
if(nagiostats_file);
free(nagiostats_file);
/* Opsera patch - return based on error, because mrtg_mode was always returning OK */ /* Opsera patch - return based on error, because mrtg_mode was always returning OK */
if(result == ERROR) if(result == ERROR)
return ERROR; return ERROR;
@ -442,7 +412,7 @@ int main(int argc, char **argv) {
int display_mrtg_values(void) { static int display_mrtg_values(void) {
char *temp_ptr; char *temp_ptr;
time_t current_time; time_t current_time;
unsigned long time_difference; unsigned long time_difference;
@ -480,18 +450,11 @@ int display_mrtg_values(void) {
else if(!strcmp(temp_ptr, "NAGIOSVERSION")) else if(!strcmp(temp_ptr, "NAGIOSVERSION"))
printf("%s%s", status_version, mrtg_delimiter); printf("%s%s", status_version, mrtg_delimiter);
else if(!strcmp(temp_ptr, "NAGIOSPID")) else if(!strcmp(temp_ptr, "NAGIOSPID"))
printf("%lu%s", nagios_pid, mrtg_delimiter); printf("%d%s", nagios_pid, mrtg_delimiter);
else if(!strcmp(temp_ptr, "NAGIOSVERPID")) else if(!strcmp(temp_ptr, "NAGIOSVERPID"))
printf("Nagios %s (pid=%lu)%s", status_version, nagios_pid, mrtg_delimiter); printf("Nagios %s (pid=%d)%s", status_version, nagios_pid, mrtg_delimiter);
else if(!strcmp(temp_ptr, "TOTCMDBUF"))
printf("%d%s", total_external_command_buffer_slots, mrtg_delimiter);
else if(!strcmp(temp_ptr, "USEDCMDBUF"))
printf("%d%s", used_external_command_buffer_slots, mrtg_delimiter);
else if(!strcmp(temp_ptr, "HIGHCMDBUF"))
printf("%d%s", high_external_command_buffer_slots, mrtg_delimiter);
else if(!strcmp(temp_ptr, "NUMSERVICES")) else if(!strcmp(temp_ptr, "NUMSERVICES"))
printf("%d%s", status_service_entries, mrtg_delimiter); printf("%d%s", status_service_entries, mrtg_delimiter);
else if(!strcmp(temp_ptr, "NUMHOSTS")) else if(!strcmp(temp_ptr, "NUMHOSTS"))
@ -771,7 +734,7 @@ int display_mrtg_values(void) {
} }
int display_stats(void) { static int display_stats(void) {
time_t current_time; time_t current_time;
unsigned long time_difference; unsigned long time_difference;
int days; int days;
@ -783,7 +746,7 @@ int display_stats(void) {
printf("CURRENT STATUS DATA\n"); printf("CURRENT STATUS DATA\n");
printf("------------------------------------------------------\n"); printf("------------------------------------------------------\n");
printf("Status File: %s\n", (nagiostats_file != NULL) ? nagiostats_file : status_file); printf("Status File: %s\n", status_file);
time_difference = (current_time - status_creation_date); time_difference = (current_time - status_creation_date);
get_time_breakdown(time_difference, &days, &hours, &minutes, &seconds); get_time_breakdown(time_difference, &days, &hours, &minutes, &seconds);
printf("Status File Age: %dd %dh %dm %ds\n", days, hours, minutes, seconds); printf("Status File Age: %dd %dh %dm %ds\n", days, hours, minutes, seconds);
@ -792,8 +755,7 @@ int display_stats(void) {
time_difference = (current_time - program_start); time_difference = (current_time - program_start);
get_time_breakdown(time_difference, &days, &hours, &minutes, &seconds); get_time_breakdown(time_difference, &days, &hours, &minutes, &seconds);
printf("Program Running Time: %dd %dh %dm %ds\n", days, hours, minutes, seconds); printf("Program Running Time: %dd %dh %dm %ds\n", days, hours, minutes, seconds);
printf("Nagios PID: %lu\n", nagios_pid); printf("Nagios PID: %d\n", nagios_pid);
printf("Used/High/Total Command Buffers: %d / %d / %d\n", used_external_command_buffer_slots, high_external_command_buffer_slots, total_external_command_buffer_slots);
printf("\n"); printf("\n");
printf("Total Services: %d\n", status_service_entries); printf("Total Services: %d\n", status_service_entries);
printf("Services Checked: %d\n", services_checked); printf("Services Checked: %d\n", services_checked);
@ -863,13 +825,19 @@ int display_stats(void) {
} }
int read_config_file(void) { static int read_config_file(void) {
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
FILE *fp; FILE *fp;
char *var; char *var;
char *val; char *val;
char *main_cfg_dir = NULL;
char *slash = NULL;
main_cfg_dir = nspath_absolute(main_config_file, NULL);
if ((slash = strrchr(main_cfg_dir, '/')))
*slash = 0;
fp = fopen(main_config_file, "r"); fp = fopen(main_config_file, "r");
if(fp == NULL) if(fp == NULL)
return ERROR; return ERROR;
@ -891,7 +859,7 @@ int read_config_file(void) {
if(!strcmp(var, "status_file") || !strcmp(var, "status_log") || !strcmp(var, "xsddefault_status_log")) { if(!strcmp(var, "status_file") || !strcmp(var, "status_log") || !strcmp(var, "xsddefault_status_log")) {
if(status_file) if(status_file)
free(status_file); free(status_file);
status_file = strdup(val); status_file = nspath_absolute(val, main_cfg_dir);
} }
} }
@ -902,7 +870,7 @@ int read_config_file(void) {
} }
int read_status_file(void) { static int read_status_file(void) {
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
FILE *fp = NULL; FILE *fp = NULL;
int data_type = STATUS_NO_DATA; int data_type = STATUS_NO_DATA;
@ -914,7 +882,7 @@ int read_status_file(void) {
double execution_time = 0.0; double execution_time = 0.0;
double latency = 0.0; double latency = 0.0;
int check_type = SERVICE_CHECK_ACTIVE; int check_type = CHECK_TYPE_ACTIVE;
int current_state = STATE_OK; int current_state = STATE_OK;
double state_change = 0.0; double state_change = 0.0;
int is_flapping = FALSE; int is_flapping = FALSE;
@ -984,7 +952,7 @@ int read_status_file(void) {
have_max_host_state_change = TRUE; have_max_host_state_change = TRUE;
max_host_state_change = state_change; max_host_state_change = state_change;
} }
if(check_type == HOST_CHECK_ACTIVE) { if(check_type == CHECK_TYPE_ACTIVE) {
active_host_checks++; active_host_checks++;
average_active_host_latency = (((average_active_host_latency * ((double)active_host_checks - 1.0)) + latency) / (double)active_host_checks); average_active_host_latency = (((average_active_host_latency * ((double)active_host_checks - 1.0)) + latency) / (double)active_host_checks);
if(have_min_active_host_latency == FALSE || min_active_host_latency > latency) { if(have_min_active_host_latency == FALSE || min_active_host_latency > latency) {
@ -1086,7 +1054,7 @@ int read_status_file(void) {
have_max_service_state_change = TRUE; have_max_service_state_change = TRUE;
max_service_state_change = state_change; max_service_state_change = state_change;
} }
if(check_type == SERVICE_CHECK_ACTIVE) { if(check_type == CHECK_TYPE_ACTIVE) {
active_service_checks++; active_service_checks++;
average_active_service_latency = (((average_active_service_latency * ((double)active_service_checks - 1.0)) + latency) / (double)active_service_checks); average_active_service_latency = (((average_active_service_latency * ((double)active_service_checks - 1.0)) + latency) / (double)active_service_checks);
if(have_min_active_service_latency == FALSE || min_active_service_latency > latency) { if(have_min_active_service_latency == FALSE || min_active_service_latency > latency) {
@ -1220,12 +1188,6 @@ int read_status_file(void) {
case STATUS_PROGRAM_DATA: case STATUS_PROGRAM_DATA:
if(!strcmp(var, "program_start")) if(!strcmp(var, "program_start"))
program_start = strtoul(val, NULL, 10); program_start = strtoul(val, NULL, 10);
else if(!strcmp(var, "total_external_command_buffer_slots"))
total_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "used_external_command_buffer_slots"))
used_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "high_external_command_buffer_slots"))
high_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "nagios_pid")) else if(!strcmp(var, "nagios_pid"))
nagios_pid = strtoul(val, NULL, 10); nagios_pid = strtoul(val, NULL, 10);
else if(!strcmp(var, "active_scheduled_host_check_stats")) { else if(!strcmp(var, "active_scheduled_host_check_stats")) {
@ -1377,342 +1339,6 @@ int read_status_file(void) {
} }
int read_nagiostats_file(void) {
char temp_buffer[MAX_INPUT_BUFFER];
FILE *fp = NULL;
char *var = NULL;
char *val = NULL;
char *temp_ptr = NULL;
time_t current_time;
time(&current_time);
fp = fopen(nagiostats_file, "r");
if(fp == NULL)
return ERROR;
/* read all lines in the status file */
while(fgets(temp_buffer, sizeof(temp_buffer) - 1, fp)) {
/* skip comments */
if(temp_buffer[0] == '#')
continue;
strip(temp_buffer);
var = strtok(temp_buffer, "=");
val = strtok(NULL, "\n");
if(val == NULL)
continue;
/**** INFO ****/
if(!strcmp(var, "created"))
status_creation_date = strtoul(val, NULL, 10);
else if(!strcmp(var, "nagios_version"))
status_version = strdup(val);
/**** PROGRAM INFO ****/
else if(!strcmp(var, "program_start"))
program_start = strtoul(val, NULL, 10);
else if(!strcmp(var, "total_external_command_buffer_slots"))
total_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "used_external_command_buffer_slots"))
used_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "high_external_command_buffer_slots"))
high_external_command_buffer_slots = atoi(val);
else if(!strcmp(var, "nagios_pid"))
nagios_pid = strtoul(val, NULL, 10);
else if(!strcmp(var, "active_scheduled_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_scheduled_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_scheduled_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_scheduled_host_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "active_ondemand_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_ondemand_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_ondemand_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_ondemand_host_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "cached_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_cached_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_cached_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_cached_host_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "passive_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
passive_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_host_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "active_scheduled_service_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_scheduled_service_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_scheduled_service_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_scheduled_service_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "active_ondemand_service_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_ondemand_service_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_ondemand_service_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_ondemand_service_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "cached_service_check_stats")) {
if((temp_ptr = strtok(val, ",")))
active_cached_service_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_cached_service_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_cached_service_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "passive_service_check_stats")) {
if((temp_ptr = strtok(val, ",")))
passive_service_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_service_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_service_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "external_command_stats")) {
if((temp_ptr = strtok(val, ",")))
external_commands_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
external_commands_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
external_commands_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "parallel_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
parallel_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
parallel_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
parallel_host_checks_last_15min = atoi(temp_ptr);
}
else if(!strcmp(var, "serial_host_check_stats")) {
if((temp_ptr = strtok(val, ",")))
serial_host_checks_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
serial_host_checks_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
serial_host_checks_last_15min = atoi(temp_ptr);
}
/***** HOST INFO *****/
else if(!strcmp(var, "total_hosts"))
status_host_entries = atoi(val);
else if(!strcmp(var, "hosts_checked"))
hosts_checked = atoi(val);
else if(!strcmp(var, "hosts_scheduled"))
hosts_scheduled = atoi(val);
else if(!strcmp(var, "hosts_flapping"))
hosts_flapping = atoi(val);
else if(!strcmp(var, "hosts_in_downtime"))
hosts_in_downtime = atoi(val);
else if(!strcmp(var, "hosts_up"))
hosts_up = atoi(val);
else if(!strcmp(var, "hosts_down"))
hosts_down = atoi(val);
else if(!strcmp(var, "hosts_unreachable"))
hosts_unreachable = atoi(val);
else if(!strcmp(var, "hosts_actively_checked"))
active_host_checks = atoi(val);
else if(!strcmp(var, "hosts_passively_checked"))
passive_host_checks = atoi(val);
else if(!strcmp(var, "total_host_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_host_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_host_latency")) {
if((temp_ptr = strtok(val, ",")))
min_active_host_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_host_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_host_latency = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_host_execution_time")) {
if((temp_ptr = strtok(val, ",")))
min_active_host_execution_time = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_host_execution_time = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_host_execution_time = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_host_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_active_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_host_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_hosts_last_x")) {
if((temp_ptr = strtok(val, ",")))
active_hosts_checked_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_hosts_checked_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_hosts_checked_last_15min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_hosts_checked_last_1hour = atoi(temp_ptr);
}
else if(!strcmp(var, "passive_host_latency")) {
if((temp_ptr = strtok(val, ",")))
min_passive_host_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_passive_host_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_passive_host_latency = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "passive_host_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_passive_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_passive_host_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_passive_host_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "passive_hosts_last_x")) {
if((temp_ptr = strtok(val, ",")))
passive_hosts_checked_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_hosts_checked_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_hosts_checked_last_15min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_hosts_checked_last_1hour = atoi(temp_ptr);
}
/***** SERVICE INFO *****/
else if(!strcmp(var, "total_services"))
status_service_entries = atoi(val);
else if(!strcmp(var, "services_checked"))
services_checked = atoi(val);
else if(!strcmp(var, "services_scheduled"))
services_scheduled = atoi(val);
else if(!strcmp(var, "services_flapping"))
services_flapping = atoi(val);
else if(!strcmp(var, "services_in_downtime"))
services_in_downtime = atoi(val);
else if(!strcmp(var, "services_ok"))
services_ok = atoi(val);
else if(!strcmp(var, "services_warning"))
services_warning = atoi(val);
else if(!strcmp(var, "services_critical"))
services_critical = atoi(val);
else if(!strcmp(var, "services_unknown"))
services_unknown = atoi(val);
else if(!strcmp(var, "services_actively_checked"))
active_service_checks = atoi(val);
else if(!strcmp(var, "services_passively_checked"))
passive_service_checks = atoi(val);
else if(!strcmp(var, "total_service_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_service_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_service_latency")) {
if((temp_ptr = strtok(val, ",")))
min_active_service_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_service_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_service_latency = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_service_execution_time")) {
if((temp_ptr = strtok(val, ",")))
min_active_service_execution_time = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_service_execution_time = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_service_execution_time = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_service_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_active_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_active_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_active_service_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "active_services_last_x")) {
if((temp_ptr = strtok(val, ",")))
active_services_checked_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_services_checked_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_services_checked_last_15min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
active_services_checked_last_1hour = atoi(temp_ptr);
}
else if(!strcmp(var, "passive_service_latency")) {
if((temp_ptr = strtok(val, ",")))
min_passive_service_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_passive_service_latency = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_passive_service_latency = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "passive_service_state_change")) {
if((temp_ptr = strtok(val, ",")))
min_passive_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
max_passive_service_state_change = strtod(temp_ptr, NULL);
if((temp_ptr = strtok(NULL, ",")))
average_passive_service_state_change = strtod(temp_ptr, NULL);
}
else if(!strcmp(var, "passive_services_last_x")) {
if((temp_ptr = strtok(val, ",")))
passive_services_checked_last_1min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_services_checked_last_5min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_services_checked_last_15min = atoi(temp_ptr);
if((temp_ptr = strtok(NULL, ",")))
passive_services_checked_last_1hour = atoi(temp_ptr);
}
}
fclose(fp);
/* 02-15-2008 exclude cached host checks from total (they were ondemand checks that never actually executed) */
active_host_checks_last_1min = active_scheduled_host_checks_last_1min + active_ondemand_host_checks_last_1min;
active_host_checks_last_5min = active_scheduled_host_checks_last_5min + active_ondemand_host_checks_last_5min;
active_host_checks_last_15min = active_scheduled_host_checks_last_15min + active_ondemand_host_checks_last_15min;
/* 02-15-2008 exclude cached service checks from total (they were ondemand checks that never actually executed) */
active_service_checks_last_1min = active_scheduled_service_checks_last_1min + active_ondemand_service_checks_last_1min;
active_service_checks_last_5min = active_scheduled_service_checks_last_5min + active_ondemand_service_checks_last_5min;
active_service_checks_last_15min = active_scheduled_service_checks_last_15min + active_ondemand_service_checks_last_15min;
return OK;
}
/* strip newline, carriage return, and tab characters from beginning and end of a string */ /* strip newline, carriage return, and tab characters from beginning and end of a string */
void strip(char *buffer) { void strip(char *buffer) {
register int x; register int x;
@ -1775,4 +1401,3 @@ void get_time_breakdown(unsigned long raw_time, int *days, int *hours, int *minu
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* NEBMODS.C - Event Broker Module Functions * NEBMODS.C - Event Broker Module Functions
* *
* Copyright (c) 2002-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 11-02-2008
* *
* License: * License:
* *
@ -32,14 +30,21 @@
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
nebmodule *neb_module_list = NULL; static nebmodule *neb_module_list;
nebcallback **neb_callback_list = NULL; static nebcallback **neb_callback_list;
extern char *temp_path;
/*#define DEBUG*/
/* compat stuff for USE_LTDL */
#ifdef USE_LTDL
# define dlopen(p, flags) lt_dlopen(p)
# define dlclose(p) lt_dlclose(p)
# define dlerror() lt_dlerror()
# define dlsym(hdl, sym) lt_dlsym(hdl, sym)
# define RTLD_NOW 0
# define RTLD_GLOBAL 0
#else
# define lt_dlinit() 0
# define lt_dlexit() 0
#endif
/****************************************************************************/ /****************************************************************************/
/****************************************************************************/ /****************************************************************************/
@ -49,39 +54,20 @@ extern char *temp_path;
/* initialize module routines */ /* initialize module routines */
int neb_init_modules(void) { int neb_init_modules(void) {
#ifdef USE_LTDL if(lt_dlinit())
int result = OK;
#endif
/* initialize library */
#ifdef USE_LTDL
result = lt_dlinit();
if(result)
return ERROR; return ERROR;
#endif
return OK; return OK;
} }
/* deinitialize module routines */ /* deinitialize module routines */
int neb_deinit_modules(void) { int neb_deinit_modules(void) {
#ifdef USE_LTDL if(lt_dlexit())
int result = OK;
#endif
/* deinitialize library */
#ifdef USE_LTDL
result = lt_dlexit();
if(result)
return ERROR; return ERROR;
#endif
return OK; return OK;
} }
/* add a new module to module list */ /* add a new module to module list */
int neb_add_module(char *filename, char *args, int should_be_loaded) { int neb_add_module(char *filename, char *args, int should_be_loaded) {
nebmodule *new_module = NULL; nebmodule *new_module = NULL;
@ -91,7 +77,7 @@ int neb_add_module(char *filename, char *args, int should_be_loaded) {
return ERROR; return ERROR;
/* allocate memory */ /* allocate memory */
new_module = (nebmodule *)malloc(sizeof(nebmodule)); new_module = (nebmodule *)calloc(1, sizeof(nebmodule));
if(new_module == NULL) if(new_module == NULL)
return ERROR; return ERROR;
@ -105,9 +91,6 @@ int neb_add_module(char *filename, char *args, int should_be_loaded) {
new_module->module_handle = NULL; new_module->module_handle = NULL;
new_module->init_func = NULL; new_module->init_func = NULL;
new_module->deinit_func = NULL; new_module->deinit_func = NULL;
#ifdef HAVE_PTHREAD_H
new_module->thread_id = (pthread_t)NULL;
#endif
/* add module to head of list */ /* add module to head of list */
new_module->next = neb_module_list; new_module->next = neb_module_list;
@ -119,20 +102,38 @@ int neb_add_module(char *filename, char *args, int should_be_loaded) {
} }
int neb_add_core_module(nebmodule *mod) {
mod->should_be_loaded = FALSE;
mod->is_currently_loaded = TRUE;
mod->core_module = TRUE;
#ifdef USE_LTDL
mod->module_handle = (lt_dlhandle)mod;
#else
mod->module_handle = mod;
#endif
mod->next = neb_module_list;
neb_module_list = mod;
return 0;
}
/* free memory allocated to module list */ /* free memory allocated to module list */
int neb_free_module_list(void) { int neb_free_module_list(void) {
nebmodule *temp_module = NULL; nebmodule *temp_module = NULL;
nebmodule *next_module = NULL; nebmodule *next_module = NULL;
int x = OK; int x = OK;
for(temp_module = neb_module_list; temp_module;) { for(temp_module = neb_module_list; temp_module; temp_module = next_module) {
next_module = temp_module->next; next_module = temp_module->next;
my_free(temp_module->filename);
my_free(temp_module->args);
for(x = 0; x < NEBMODULE_MODINFO_NUMITEMS; x++) for(x = 0; x < NEBMODULE_MODINFO_NUMITEMS; x++)
my_free(temp_module->info[x]); my_free(temp_module->info[x]);
/* don't free this stuff for core modules */
if (temp_module->core_module)
continue;
my_free(temp_module->filename);
my_free(temp_module->args);
my_free(temp_module); my_free(temp_module);
temp_module = next_module;
} }
neb_module_list = NULL; neb_module_list = NULL;
@ -152,27 +153,27 @@ int neb_free_module_list(void) {
/* load all modules */ /* load all modules */
int neb_load_all_modules(void) { int neb_load_all_modules(void) {
nebmodule *temp_module = NULL; nebmodule *temp_module = NULL;
int result = OK; int ret, errors = 0;
for(temp_module = neb_module_list; temp_module; temp_module = temp_module->next) { for(temp_module = neb_module_list; temp_module; temp_module = temp_module->next) {
result = neb_load_module(temp_module); ret = neb_load_module(temp_module);
if (ret != OK) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Failed to load module '%s'.\n", temp_module->filename ? temp_module->filename : "(no file?)");
errors++;
}
} }
return OK; return errors ? ERROR : OK;
} }
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
/* load a particular module */ /* load a particular module */
int neb_load_module(nebmodule *mod) { int neb_load_module(nebmodule *mod) {
int (*initfunc)(int, char *, void *); int (*initfunc)(int, char *, void *);
int *module_version_ptr = NULL; int *module_version_ptr = NULL;
char output_file[PATH_MAX]; int result = OK;
int dest_fd, result = OK;
if(mod == NULL || mod->filename == NULL) if(mod == NULL)
return ERROR; return ERROR;
/* don't reopen the module */ /* don't reopen the module */
@ -180,50 +181,13 @@ int neb_load_module(nebmodule *mod) {
return OK; return OK;
/* don't load modules unless they should be loaded */ /* don't load modules unless they should be loaded */
if(mod->should_be_loaded == FALSE) if(mod->should_be_loaded == FALSE || mod->filename == NULL)
return ERROR; return ERROR;
/********** /* load the module */
Using dlopen() is great, but a real danger as-is. The problem with loaded modules is that if you overwrite the original file (e.g. using 'mv'), mod->module_handle = dlopen(mod->filename, RTLD_NOW | RTLD_GLOBAL);
you do not alter the inode of the original file. Since the original file/module is memory-mapped in some fashion, Nagios will segfault the next
time an event broker call is directed to one of the module's callback functions. This is extremely problematic when it comes to upgrading NEB
modules while Nagios is running. A workaround is to (1) 'mv' the original/loaded module file to another name (on the same filesystem)
and (2) copy the new module file to the location of the original one (using the original filename). In this scenario, dlopen() will keep referencing
the original file/inode for callbacks. This is not an ideal solution. A better one is to delete the module file once it is loaded by dlopen().
This prevents other processed from unintentially overwriting the original file, which would cause Nagios to crash. However, if we delete the file
before anyone else can muck with it, things should be good. 'lsof' shows that a deleted file is still referenced by the kernel and callback
functions continue to work once the module has been loaded. Long story, but this took quite a while to figure out, as there isn't much
of anything I could find on the subject other than some sketchy info on similar problems on HP-UX. Hopefully this will save future coders some time.
So... the trick is to (1) copy the module to a temp file, (2) dlopen() the temp file, and (3) immediately delete the temp file.
************/
/*
* open a temp file for copying the module. We use my_fdcopy() so
* we re-use the destination file descriptor returned by mkstemp(3),
* which we have to close ourselves.
*/
snprintf(output_file, sizeof(output_file) - 1, "%s/nebmodXXXXXX", temp_path);
dest_fd = mkstemp(output_file);
result = my_fdcopy(mod->filename, output_file, dest_fd);
close(dest_fd);
if(result == ERROR) {
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Failed to safely copy module '%s'. The module will not be loaded\n", mod->filename);
return ERROR;
}
/* load the module (use the temp copy we just made) */
#ifdef USE_LTDL
mod->module_handle = lt_dlopen(output_file);
#else
mod->module_handle = (void *)dlopen(output_file, RTLD_NOW | RTLD_GLOBAL);
#endif
if(mod->module_handle == NULL) { if(mod->module_handle == NULL) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Could not load module '%s' -> %s\n", mod->filename, dlerror());
#ifdef USE_LTDL
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, lt_dlerror());
#else
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not load module '%s' -> %s\n", mod->filename, dlerror());
#endif
return ERROR; return ERROR;
} }
@ -231,28 +195,13 @@ int neb_load_module(nebmodule *mod) {
/* mark the module as being loaded */ /* mark the module as being loaded */
mod->is_currently_loaded = TRUE; mod->is_currently_loaded = TRUE;
/* delete the temp copy of the module we just created and loaded */
/* this will prevent other processes from overwriting the file (using the same inode), which would cause Nagios to crash */
/* the kernel will keep the deleted file in memory until we unload it */
/* NOTE: This *should* be portable to most Unices, but I've only tested it on Linux */
if(unlink(output_file) == -1) {
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not delete temporary file '%s' used for module '%s'. The module will be unloaded: %s\n", output_file, mod->filename, strerror(errno));
neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION);
return ERROR;
}
/* find module API version */ /* find module API version */
#ifdef USE_LTDL
module_version_ptr = (int *)lt_dlsym(mod->module_handle, "__neb_api_version");
#else
module_version_ptr = (int *)dlsym(mod->module_handle, "__neb_api_version"); module_version_ptr = (int *)dlsym(mod->module_handle, "__neb_api_version");
#endif
/* check the module API version */ /* check the module API version */
if(module_version_ptr == NULL || ((*module_version_ptr) != CURRENT_NEB_API_VERSION)) { if(module_version_ptr == NULL || ((*module_version_ptr) != CURRENT_NEB_API_VERSION)) {
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Module '%s' is using an old or unspecified version of the event broker API. Module will be unloaded.\n", mod->filename); logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Module '%s' is using an old or unspecified version of the event broker API. Module will be unloaded.\n", mod->filename);
neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION); neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_API_VERSION);
@ -260,16 +209,12 @@ int neb_load_module(nebmodule *mod) {
} }
/* locate the initialization function */ /* locate the initialization function */
#ifdef USE_LTDL mod->init_func = dlsym(mod->module_handle, "nebmodule_init");
mod->init_func = lt_dlsym(mod->module_handle, "nebmodule_init");
#else
mod->init_func = (void *)dlsym(mod->module_handle, "nebmodule_init");
#endif
/* if the init function could not be located, unload the module */ /* if the init function could not be located, unload the module */
if(mod->init_func == NULL) { if(mod->init_func == NULL) {
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Could not locate nebmodule_init() in module '%s'. Module will be unloaded.\n", mod->filename); logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Could not locate nebmodule_init() in module '%s'. Module will be unloaded.\n", mod->filename);
neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_NO_INIT); neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_NO_INIT);
@ -283,21 +228,17 @@ int neb_load_module(nebmodule *mod) {
/* if the init function returned an error, unload the module */ /* if the init function returned an error, unload the module */
if(result != OK) { if(result != OK) {
logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Function nebmodule_init() in module '%s' returned an error. Module will be unloaded.\n", mod->filename); logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Function nebmodule_init() in module '%s' returned an error. Module will be unloaded.\n", mod->filename);
neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_BAD_INIT); neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_BAD_INIT);
return ERROR; return ERROR;
} }
logit(NSLOG_INFO_MESSAGE, FALSE, "Event broker module '%s' initialized successfully.\n", mod->filename); logit(NSLOG_INFO_MESSAGE, TRUE, "Event broker module '%s' initialized successfully.\n", mod->filename);
/* locate the de-initialization function (may or may not be present) */ /* locate the de-initialization function (may or may not be present) */
#ifdef USE_LTDL mod->deinit_func = dlsym(mod->module_handle, "nebmodule_deinit");
mod->deinit_func = lt_dlsym(mod->module_handle, "nebmodule_deinit");
#else
mod->deinit_func = (void *)dlsym(mod->module_handle, "nebmodule_deinit");
#endif
log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' loaded with return code of '%d'\n", mod->filename, result); log_debug_info(DEBUGL_EVENTBROKER, 0, "Module '%s' loaded with return code of '%d'\n", mod->filename, result);
if(mod->deinit_func != NULL) if(mod->deinit_func != NULL)
@ -340,6 +281,12 @@ int neb_unload_module(nebmodule *mod, int flags, int reason) {
log_debug_info(DEBUGL_EVENTBROKER, 0, "Attempting to unload module '%s': flags=%d, reason=%d\n", mod->filename, flags, reason); log_debug_info(DEBUGL_EVENTBROKER, 0, "Attempting to unload module '%s': flags=%d, reason=%d\n", mod->filename, flags, reason);
/* remove the module's demand-loaded file */
if(daemon_dumps_core == TRUE && mod->dl_file) {
(void)unlink(mod->dl_file);
my_free(mod->dl_file);
}
/* call the de-initialization function if available (and the module was initialized) */ /* call the de-initialization function if available (and the module was initialized) */
if(mod->deinit_func && reason != NEBMODULE_ERROR_BAD_INIT) { if(mod->deinit_func && reason != NEBMODULE_ERROR_BAD_INIT) {
@ -356,12 +303,16 @@ int neb_unload_module(nebmodule *mod, int flags, int reason) {
/* deregister all of the module's callbacks */ /* deregister all of the module's callbacks */
neb_deregister_module_callbacks(mod); neb_deregister_module_callbacks(mod);
/* unload the module */ if(mod->core_module == FALSE) {
#ifdef USE_LTDL
result = lt_dlclose(mod->module_handle); /* unload the module */
#else result = dlclose(mod->module_handle);
result = dlclose(mod->module_handle);
#endif if (result != 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Could not unload module '%s' -> %s\n", mod->filename, dlerror());
return ERROR;
}
}
/* mark the module as being unloaded */ /* mark the module as being unloaded */
mod->is_currently_loaded = FALSE; mod->is_currently_loaded = FALSE;
@ -395,7 +346,7 @@ int neb_set_module_info(void *handle, int type, char *data) {
/* find the module */ /* find the module */
for(temp_module = neb_module_list; temp_module != NULL; temp_module = temp_module->next) { for(temp_module = neb_module_list; temp_module != NULL; temp_module = temp_module->next) {
if((void *)temp_module->module_handle == (void *)handle) if(temp_module->module_handle == handle)
break; break;
} }
if(temp_module == NULL) if(temp_module == NULL)
@ -441,7 +392,7 @@ int neb_register_callback(int callback_type, void *mod_handle, int priority, int
/* make sure module handle is valid */ /* make sure module handle is valid */
for(temp_module = neb_module_list; temp_module; temp_module = temp_module->next) { for(temp_module = neb_module_list; temp_module; temp_module = temp_module->next) {
if((void *)temp_module->module_handle == (void *)mod_handle) if(temp_module->module_handle == mod_handle)
break; break;
} }
if(temp_module == NULL) if(temp_module == NULL)
@ -453,8 +404,8 @@ int neb_register_callback(int callback_type, void *mod_handle, int priority, int
return NEBERROR_NOMEM; return NEBERROR_NOMEM;
new_callback->priority = priority; new_callback->priority = priority;
new_callback->module_handle = (void *)mod_handle; new_callback->module_handle = mod_handle;
new_callback->callback_func = (void *)callback_func; new_callback->callback_func = callback_func;
/* add new function to callback list, sorted by priority (first come, first served for same priority) */ /* add new function to callback list, sorted by priority (first come, first served for same priority) */
new_callback->next = NULL; new_callback->next = NULL;
@ -499,7 +450,7 @@ int neb_deregister_module_callbacks(nebmodule *mod) {
for(callback_type = 0; callback_type < NEBCALLBACK_NUMITEMS; callback_type++) { for(callback_type = 0; callback_type < NEBCALLBACK_NUMITEMS; callback_type++) {
for(temp_callback = neb_callback_list[callback_type]; temp_callback != NULL; temp_callback = next_callback) { for(temp_callback = neb_callback_list[callback_type]; temp_callback != NULL; temp_callback = next_callback) {
next_callback = temp_callback->next; next_callback = temp_callback->next;
if((void *)temp_callback->module_handle == (void *)mod->module_handle) if(temp_callback->module_handle == mod->module_handle)
neb_deregister_callback(callback_type, (int(*)(int, void*))temp_callback->callback_func); neb_deregister_callback(callback_type, (int(*)(int, void*))temp_callback->callback_func);
} }
@ -530,7 +481,7 @@ int neb_deregister_callback(int callback_type, int (*callback_func)(int, void *)
next_callback = temp_callback->next; next_callback = temp_callback->next;
/* we found it */ /* we found it */
if(temp_callback->callback_func == (void *)callback_func) if(temp_callback->callback_func == callback_func)
break; break;
last_callback = temp_callback; last_callback = temp_callback;

495
base/nerd.c Normal file
View File

@ -0,0 +1,495 @@
/*
* Nagios Event Radio Dispatcher
*
* This is a subscriber service which initiates a unix domain socket,
* listens to it and lets other programs connect to it and subscribe
* to various channels using a simple text-based syntax.
*
* This code uses the eventbroker api to get its data, which means
* we're finally eating our own dogfood in that respect.
*/
#define _GNU_SOURCE 1
#include <stdio.h>
#include "include/config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include "lib/libnagios.h"
#include "include/common.h"
#include "include/objects.h"
#include "include/broker.h"
#include "include/nebmods.h"
#include "include/nebmodules.h"
#include "include/nebstructs.h"
struct nerd_channel {
const char *name; /* name of this channel */
const char *description; /* user-presentable string to document the purpouse of this channel */
unsigned int id; /* channel id (might vary between invocations) */
unsigned int required_options; /* event_broker_options required for this channel */
unsigned int num_callbacks;
unsigned int callbacks[NEBCALLBACK_NUMITEMS];
int (*handler)(int , void *); /* callback handler for this channel */
objectlist *subscriptions; /* subscriber list */
};
static nebmodule nerd_mod; /* fake module to get our callbacks accepted */
static struct nerd_channel **channels;
static unsigned int num_channels, alloc_channels;
static unsigned int chan_host_checks_id, chan_service_checks_id;
static unsigned int chan_opath_checks_id;
static struct nerd_channel *find_channel(const char *name)
{
unsigned int i;
for(i = 0; i < num_channels; i++) {
struct nerd_channel *chan = channels[i];
if(!strcmp(name, chan->name)) {
return chan;
}
}
return NULL;
}
int nerd_get_channel_id(const char *name)
{
struct nerd_channel *chan;
chan = find_channel(name);
if (!chan)
return -1;
return chan->id;
}
static struct nerd_channel *nerd_get_channel(unsigned int chan_id)
{
return chan_id >= num_channels ? NULL : channels[chan_id];
}
objectlist *nerd_get_subscriptions(int chan_id)
{
struct nerd_channel *chan = nerd_get_channel(chan_id);
return chan ? chan->subscriptions : NULL;
}
static int nerd_register_channel_callbacks(struct nerd_channel *chan)
{
unsigned int i;
for(i = 0; i < chan->num_callbacks; i++) {
int result = neb_register_callback(chan->callbacks[i], &nerd_mod, 0, chan->handler);
if(result != 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "nerd: Failed to register callback %d for channel '%s': %d\n",
chan->callbacks[i], chan->name, result);
return -1;
}
}
return 0;
}
static int nerd_deregister_channel_callbacks(struct nerd_channel *chan)
{
unsigned int i;
for(i = 0; i < chan->num_callbacks; i++) {
neb_deregister_callback(chan->callbacks[i], chan->handler);
}
return 0;
}
static int subscribe(int sd, struct nerd_channel *chan, char *fmt)
{
struct nerd_subscription *subscr;
if(!(subscr = calloc(1, sizeof(*subscr))))
return -1;
subscr->sd = sd;
subscr->chan = chan;
subscr->format = fmt ? strdup(fmt) : NULL;
if(!chan->subscriptions) {
nerd_register_channel_callbacks(chan);
}
prepend_object_to_objectlist(&chan->subscriptions, subscr);
return 0;
}
static int cancel_channel_subscription(struct nerd_channel *chan, int sd)
{
objectlist *list, *next, *prev = NULL;
int cancelled = 0;
if(!chan)
return -1;
for(list = chan->subscriptions; list; list = next) {
struct nerd_subscription *subscr = (struct nerd_subscription *)list->object_ptr;
next = list->next;
if(subscr->sd == sd) {
cancelled++;
free(list);
free(subscr);
if(prev) {
prev->next = next;
} else {
chan->subscriptions = next;
}
continue;
}
prev = list;
}
if(cancelled) {
logit(NSLOG_INFO_MESSAGE, TRUE, "nerd: Cancelled %d subscription%s to channel '%s' for %d\n",
cancelled, cancelled == 1 ? "" : "s", chan->name, sd);
}
if(chan->subscriptions == NULL)
nerd_deregister_channel_callbacks(chan);
return 0;
}
static int unsubscribe(int sd, struct nerd_channel *chan)
{
objectlist *list, *next, *prev = NULL;
for(list = chan->subscriptions; list; list = next) {
struct nerd_subscription *subscr = (struct nerd_subscription *)list->object_ptr;
next = list->next;
if(subscr->sd == sd) {
/* found it, so remove it */
free(subscr);
free(list);
if(!prev) {
chan->subscriptions = next;
continue;
} else {
prev->next = next;
}
continue;
}
prev = list;
}
if(chan->subscriptions == NULL) {
nerd_deregister_channel_callbacks(chan);
}
return 0;
}
/* removes a subscriber entirely and closes its socket */
int nerd_cancel_subscriber(int sd)
{
unsigned int i;
for(i = 0; i < num_channels; i++) {
cancel_channel_subscription(channels[i], sd);
}
iobroker_close(nagios_iobs, sd);
return 0;
}
int nerd_broadcast(unsigned int chan_id, void *buf, unsigned int len)
{
struct nerd_channel *chan;
objectlist *list, *next;
if (!(chan = nerd_get_channel(chan_id)))
return -1;
for(list = chan->subscriptions; list; list = next) {
struct nerd_subscription *subscr = (struct nerd_subscription *)list->object_ptr;
int result;
next = list->next;
result = send(subscr->sd, buf, len, 0);
if(result < 0) {
if (errno == EAGAIN)
return 0;
nerd_cancel_subscriber(subscr->sd);
return 500;
}
}
return 0;
}
static int chan_host_checks(int cb, void *data)
{
nebstruct_host_check_data *ds = (nebstruct_host_check_data *)data;
check_result *cr = (check_result *)ds->check_result_ptr;
host *h;
char *buf;
int len;
if(ds->type != NEBTYPE_HOSTCHECK_PROCESSED)
return 0;
if(channels[chan_host_checks_id]->subscriptions == NULL)
return 0;
h = (host *)ds->object_ptr;
len = asprintf(&buf, "%s from %d -> %d: %s\n", h->name, h->last_state, h->current_state, cr->output);
nerd_broadcast(chan_host_checks_id, buf, len);
free(buf);
return 0;
}
static int chan_service_checks(int cb, void *data)
{
nebstruct_service_check_data *ds = (nebstruct_service_check_data *)data;
check_result *cr = (check_result *)ds->check_result_ptr;
service *s;
char *buf;
int len;
if(ds->type != NEBTYPE_SERVICECHECK_PROCESSED)
return 0;
s = (service *)ds->object_ptr;
len = asprintf(&buf, "%s;%s from %d -> %d: %s\n", s->host_name, s->description, s->last_state, s->current_state, cr->output);
nerd_broadcast(chan_service_checks_id, buf, len);
free(buf);
return 0;
}
static char **host_parent_path_cache;
static const char *host_parent_path(host *leaf, char sep)
{
char *ret;
unsigned int len = 0, pos = 0;
objectlist *stack = NULL, *list, *next;
host *h = leaf;
if(!h->parent_hosts)
return h->name;
if(!host_parent_path_cache) {
host_parent_path_cache = calloc(num_objects.hosts, sizeof(char *));
}
if(host_parent_path_cache[h->id]) {
return host_parent_path_cache[h->id];
}
while(h) {
len += strlen(h->name) + 2; /* room for separator */
prepend_object_to_objectlist(&stack, h->name);
if(h->parent_hosts && h->parent_hosts->host_ptr)
h = h->parent_hosts->host_ptr;
else
break;
}
ret = malloc(len + 1);
for(list = stack; list; list = next) {
char *ppart = (char *)list->object_ptr;
next = list->next;
free(list);
ret[pos++] = sep;
memcpy(ret + pos, ppart, strlen(ppart));
pos += strlen(ppart);
}
ret[pos++] = 0;
host_parent_path_cache[leaf->id] = ret;
return ret;
}
static int chan_opath_checks(int cb, void *data)
{
const int red = 0xff0000, green = 0xff00, blue = 0xff, pale = 0x555555;
unsigned int color;
check_result *cr;
host *h;
const char *name = "_HOST_";
char *buf = NULL;
if(cb == NEBCALLBACK_HOST_CHECK_DATA) {
nebstruct_host_check_data *ds = (nebstruct_host_check_data *)data;
if(ds->type != NEBTYPE_HOSTCHECK_PROCESSED)
return 0;
cr = ds->check_result_ptr;
h = ds->object_ptr;
color = red | green;
} else if(cb == NEBCALLBACK_SERVICE_CHECK_DATA) {
nebstruct_service_check_data *ds = (nebstruct_service_check_data *)data;
service *s;
if(ds->type != NEBTYPE_SERVICECHECK_PROCESSED)
return 0;
s = (service *)ds->object_ptr;
h = s->host_ptr;
cr = ds->check_result_ptr;
color = (red | green | blue) ^ pale;
name = s->description;
} else
return 0;
asprintf(&buf, "%lu|%s|M|%s/%s|%06X\n", cr->finish_time.tv_sec,
check_result_source(cr), host_parent_path(h, '/'), name, color);
nerd_broadcast(chan_opath_checks_id, buf, strlen(buf));
free(buf);
return 0;
}
static int nerd_deinit(void)
{
unsigned int i;
if(host_parent_path_cache) {
for(i = 0; i < num_objects.hosts; i++) {
my_free(host_parent_path_cache[i]);
}
my_free(host_parent_path_cache);
}
for(i = 0; i < num_channels; i++) {
struct nerd_channel *chan = channels[i];
objectlist *list, *next;
for(list = chan->subscriptions; list; list = next) {
struct nerd_subscription *subscr = (struct nerd_subscription *)list->object_ptr;
iobroker_close(nagios_iobs, subscr->sd);
next = list->next;
free(list);
free(subscr);
}
chan->subscriptions = NULL;
my_free(chan);
}
my_free(channels);
num_channels = 0;
alloc_channels = 0;
return 0;
}
int nerd_mkchan(const char *name, const char *description, int (*handler)(int, void *), unsigned int callbacks)
{
struct nerd_channel *chan, **ptr;
int i;
if(num_channels + 1 >= alloc_channels) {
alloc_channels = alloc_nr(alloc_channels);
ptr = realloc(channels, alloc_channels * sizeof(struct nerd_channel *));
if(!ptr)
return -1;
channels = ptr;
}
if(!(chan = calloc(1, sizeof(*chan))))
return -1;
chan->name = name;
chan->description = description;
chan->handler = handler;
for(i = 0; callbacks && i < NEBCALLBACK_NUMITEMS; i++) {
if(!(callbacks & (1 << i)))
continue;
chan->callbacks[chan->num_callbacks++] = i;
}
channels[num_channels++] = chan;
logit(NSLOG_INFO_MESSAGE, TRUE, "nerd: Channel %s registered successfully\n", chan->name);
return num_channels - 1;
}
#define NERD_SUBSCRIBE 0
#define NERD_UNSUBSCRIBE 1
static int nerd_qh_handler(int sd, char *request, unsigned int len)
{
char *chan_name, *fmt;
struct nerd_channel *chan;
int action;
if (!*request || !strcmp(request, "help")) {
nsock_printf_nul(sd, "Manage subscriptions to NERD channels.\n"
"Valid commands:\n"
" list list available channels\n"
" subscribe <channel> subscribe to a channel\n"
" unsubscribe <channel> unsubscribe to a channel\n");
return 0;
}
if (!strcmp(request, "list")) {
unsigned int i;
for (i = 0; i < num_channels; i++) {
chan = channels[i];
nsock_printf(sd, "%-15s %s\n", chan->name, chan->description);
}
nsock_printf(sd, "%c", 0);
return 0;
}
chan_name = strchr(request, ' ');
if(!chan_name)
return 400;
*chan_name = 0;
chan_name++;
if(!strcmp(request, "subscribe"))
action = NERD_SUBSCRIBE;
else if(!strcmp(request, "unsubscribe"))
action = NERD_UNSUBSCRIBE;
else {
return 400;
}
/* might have a format-string */
if((fmt = strchr(chan_name, ':')))
*(fmt++) = 0;
chan = find_channel(chan_name);
if(!chan) {
return 400;
}
if(action == NERD_SUBSCRIBE)
subscribe(sd, chan, fmt);
else
unsubscribe(sd, chan);
return 0;
}
/* nebmod_init(), but loaded even if no modules are */
int nerd_init(void)
{
nerd_mod.deinit_func = nerd_deinit;
nerd_mod.filename = (char *)"NERD"; /* something to log */
if(qh_register_handler("nerd", "Nagios Event Radio Dispatcher - Subscriber Service", 0, nerd_qh_handler) < 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "nerd: Failed to register with query handler\n");
return ERROR;
}
neb_add_core_module(&nerd_mod);
chan_host_checks_id = nerd_mkchan("hostchecks",
"Host check results",
chan_host_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA));
chan_service_checks_id = nerd_mkchan("servicechecks",
"Service check results",
chan_service_checks, nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
chan_opath_checks_id = nerd_mkchan("opathchecks",
"Host and service checks in gource's log format",
chan_opath_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA) | nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
logit(NSLOG_INFO_MESSAGE, TRUE, "nerd: Fully initialized and ready to rock!\n");
return 0;
}

View File

@ -2,9 +2,7 @@
* *
* NETUTILS.C - Network connection utility functions for Nagios * NETUTILS.C - Network connection utility functions for Nagios
* *
* Copyright (c) 1999,2008 Ethan Galstad (egalstad@nagios.org)
* Portions Copyright (c) 1999-2008 Nagios Plugin development team * Portions Copyright (c) 1999-2008 Nagios Plugin development team
* Last Modified: 12-04-2008
* *
* License: * License:
* *
@ -29,7 +27,7 @@
/* connect to a TCP socket in nonblocking fashion */ /* connect to a TCP socket in nonblocking fashion */
int my_tcp_connect(char *host_name, int port, int *sd, int timeout) { int my_tcp_connect(const char *host_name, int port, int *sd, int timeout) {
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *res; struct addrinfo *res;
int result; int result;
@ -154,7 +152,7 @@ int my_tcp_connect(char *host_name, int port, int *sd, int timeout) {
/* based on Beej's sendall - thanks Beej! */ /* based on Beej's sendall - thanks Beej! */
int my_sendall(int s, char *buf, int *len, int timeout) { int my_sendall(int s, const char *buf, int *len, int timeout) {
int total_sent = 0; int total_sent = 0;
int bytes_left = 0; int bytes_left = 0;
int n; int n;

View File

@ -2,9 +2,6 @@
* *
* NOTIFICATIONS.C - Service and host notification functions for Nagios * NOTIFICATIONS.C - Service and host notification functions for Nagios
* *
* Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-04-2010
* *
* License: * License:
* *
@ -31,25 +28,37 @@
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/broker.h" #include "../include/broker.h"
#include "../include/neberrors.h" #include "../include/neberrors.h"
#include "../include/workers.h"
#include "../include/downtime.h"
extern notification *notification_list; /*** silly helpers ****/
extern contact *contact_list; static contact *find_contact_by_name_or_alias(const char *name)
extern serviceescalation *serviceescalation_list; {
extern hostescalation *hostescalation_list; contact *c = NULL;
extern time_t program_start; if (!name || !(c = find_contact(name)))
return c;
for (c = contact_list; c; c = c->next)
if (!strcmp(c->alias, name))
break;
extern int interval_length; return c;
extern int log_notifications; }
extern int enable_notifications; const char *notification_reason_name(unsigned int reason_type)
{
static const char *names[] = {
"NORMAL", "ACKNOWLEDGEMENT",
"FLAPPINGSTART", "FLAPPINGSTOP", "FLAPPINGDISABLED",
"DOWNTIMESTART", "DOWNTIMEEND", "DOWNTIMECANCELLED",
"CUSTOM"
};
extern int notification_timeout; if (reason_type < sizeof(names))
return names[reason_type];
extern unsigned long next_notification_id;
extern char *generic_summary;
return "(unknown)";
}
/******************************************************************/ /******************************************************************/
@ -78,7 +87,7 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
time(&current_time); time(&current_time);
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "** Service Notification Attempt ** Host: '%s', Service: '%s', Type: %d, Options: %d, Current State: %d, Last Notification: %s", svc->host_name, svc->description, type, options, svc->current_state, ctime(&svc->last_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 0, "** Service Notification Attempt ** Host: '%s', Service: '%s', Type: %s, Options: %d, Current State: %d, Last Notification: %s", svc->host_name, svc->description, notification_reason_name(type), options, svc->current_state, ctime(&svc->last_notification));
/* if we couldn't find the host, return an error */ /* if we couldn't find the host, return an error */
if((temp_host = svc->host_ptr) == NULL) { if((temp_host = svc->host_ptr) == NULL) {
@ -89,6 +98,14 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
/* check the viability of sending out a service notification */ /* check the viability of sending out a service notification */
if(check_service_notification_viability(svc, type, options) == ERROR) { if(check_service_notification_viability(svc, type, options) == ERROR) {
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "Notification viability test failed. No notification will be sent out.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 0, "Notification viability test failed. No notification will be sent out.\n");
/* Set next_notification time if we're in a downtime and
notification_interval = zero, otherwise if the service
doesn't recover after downtime ends, it will never send
the notification */
if (svc->notification_interval == 0.0) {
if (temp_host->scheduled_downtime_depth > 0 || svc->scheduled_downtime_depth > 0)
svc->next_notification = current_time;
}
return OK; return OK;
} }
@ -113,13 +130,11 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
end_time.tv_sec = 0L; end_time.tv_sec = 0L;
end_time.tv_usec = 0L; end_time.tv_usec = 0L;
neb_result = broker_notification_data(NEBTYPE_NOTIFICATION_START, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_NOTIFICATION, type, start_time, end_time, (void *)svc, not_author, not_data, escalated, 0, NULL); neb_result = broker_notification_data(NEBTYPE_NOTIFICATION_START, NEBFLAG_NONE, NEBATTR_NONE, SERVICE_NOTIFICATION, type, start_time, end_time, (void *)svc, not_author, not_data, escalated, 0, NULL);
if(NEBERROR_CALLBACKCANCEL == neb_result) { if(neb_result == NEBERROR_CALLBACKCANCEL || neb_result == NEBERROR_CALLBACKOVERRIDE) {
log_debug_info(DEBUGL_CHECKS, 0, "Service notification to %s;%s (id=%u) was blocked by a module\n",
svc->host_name, svc->description, svc->id);
free_notification_list(); free_notification_list();
return ERROR; return neb_result == NEBERROR_CALLBACKOVERRIDE ? OK : ERROR;
}
else if(NEBERROR_CALLBACKOVERRIDE == neb_result) {
free_notification_list();
return OK;
} }
#endif #endif
@ -128,23 +143,21 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
/* create the contact notification list for this service */ /* create the contact notification list for this service */
/* 2011-11-01 MF: /*
check viability before adding a contact * check viability before adding a contact to the notification
to the notification list, requires type * list and build up the $NOTIFICATIONRECIPIENTS$ macro while
this prevents us from running through all * we're at it.
the steps until notify_contact_of_host|service * This prevents us from running through all the steps again in
is reached. furthermore the $NOTIFICATIONRECIPIENTS$ * notify_contact_of_host|service.
macro only gets populated with actual recipients, * Furthermore the $NOTIFICATIONRECIPIENTS$ macro will contain
not all contacts assigned to that host|service. * only actual recipients (as the name implies), and not all
* contacts assigned to that host|service.
note: checks against timeperiod will happen now(), *
and not when the notification is actually being sent. * note: checks against timeperiod will happen now(),
* and not when the notification is actually being sent.
original patch by Opsview Team */
*/
create_notification_list_from_service(&mac, svc, options, &escalated, type); create_notification_list_from_service(&mac, svc, options, &escalated, type);
/* XXX: crazy indent */
/* we have contacts to notify... */ /* we have contacts to notify... */
if(notification_list != NULL) { if(notification_list != NULL) {
@ -154,14 +167,7 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
/* if this notification has an author, attempt to lookup the associated contact */ /* if this notification has an author, attempt to lookup the associated contact */
if(not_author != NULL) { if(not_author != NULL) {
temp_contact = find_contact_by_name_or_alias(not_author);
/* see if we can find the contact - first by name, then by alias */
if((temp_contact = find_contact(not_author)) == NULL) {
for(temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
if(!strcmp(temp_contact->alias, not_author))
break;
}
}
} }
/* get author and comment macros */ /* get author and comment macros */
@ -262,9 +268,13 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
*/ */
clear_summary_macros_r(&mac); clear_summary_macros_r(&mac);
clear_contact_macros_r(&mac); clear_contact_macros_r(&mac);
clear_contactgroup_macros_r(&mac);
clear_argv_macros_r(&mac); clear_argv_macros_r(&mac);
clear_host_macros_r(&mac); clear_host_macros_r(&mac);
clear_hostgroup_macros_r(&mac);
clear_service_macros_r(&mac); clear_service_macros_r(&mac);
clear_servicegroup_macros_r(&mac);
clear_datetime_macros_r(&mac);
if(type == NOTIFICATION_NORMAL) { if(type == NOTIFICATION_NORMAL) {
@ -280,12 +290,7 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
svc->last_notification = current_time; svc->last_notification = current_time;
/* update notifications flags */ /* update notifications flags */
if(svc->current_state == STATE_UNKNOWN) add_notified_on(svc, svc->current_state);
svc->notified_on_unknown = TRUE;
else if(svc->current_state == STATE_WARNING)
svc->notified_on_warning = TRUE;
else if(svc->current_state == STATE_CRITICAL)
svc->notified_on_critical = TRUE;
} }
/* we didn't end up notifying anyone */ /* we didn't end up notifying anyone */
@ -366,6 +371,22 @@ int check_service_notification_viability(service *svc, int type, int options) {
return ERROR; return ERROR;
} }
/* if all parents are bad (usually just one), we shouldn't notify */
if(svc->parents) {
int bad_parents = 0, total_parents = 0;
servicesmember *sm;
for(sm = svc->parents; sm; sm = sm->next) {
/* @todo: tweak this so it handles hard states and whatnot */
if(sm->service_ptr->current_state == STATE_OK)
bad_parents += !!sm->service_ptr->current_state;
total_parents++;
}
if(bad_parents == total_parents) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "This service has no good parents, so notification will be blocked.\n");
return ERROR;
}
}
/* if the service has no notification period, inherit one from the host */ /* if the service has no notification period, inherit one from the host */
temp_period = svc->notification_period_ptr; temp_period = svc->notification_period_ptr;
if(temp_period == NULL) { if(temp_period == NULL) {
@ -418,9 +439,9 @@ int check_service_notification_viability(service *svc, int type, int options) {
/****************************************/ /*****************************************/
/*** SPECIAL CASE FOR ACKNOWLEGEMENTS ***/ /*** SPECIAL CASE FOR ACKNOWLEDGEMENTS ***/
/****************************************/ /*****************************************/
/* acknowledgements only have to pass three general filters, although they have another test of their own... */ /* acknowledgements only have to pass three general filters, although they have another test of their own... */
if(type == NOTIFICATION_ACKNOWLEDGEMENT) { if(type == NOTIFICATION_ACKNOWLEDGEMENT) {
@ -444,7 +465,7 @@ int check_service_notification_viability(service *svc, int type, int options) {
if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) { if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) {
/* don't send a notification if we're not supposed to... */ /* don't send a notification if we're not supposed to... */
if(svc->notify_on_flapping == FALSE) { if(flag_isset(svc->notification_options, OPT_FLAPPING) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about FLAPPING events for this service.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about FLAPPING events for this service.\n");
return ERROR; return ERROR;
} }
@ -468,7 +489,7 @@ int check_service_notification_viability(service *svc, int type, int options) {
if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) { if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) {
/* don't send a notification if we're not supposed to... */ /* don't send a notification if we're not supposed to... */
if(svc->notify_on_downtime == FALSE) { if(flag_isset(svc->notification_options, OPT_DOWNTIME) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about DOWNTIME events for this service.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about DOWNTIME events for this service.\n");
return ERROR; return ERROR;
} }
@ -513,44 +534,24 @@ int check_service_notification_viability(service *svc, int type, int options) {
} }
/* see if we should notify about problems with this service */ /* see if we should notify about problems with this service */
if(svc->current_state == STATE_UNKNOWN && svc->notify_on_unknown == FALSE) { if(should_notify(svc) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about UNKNOWN states for this service.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about %s states for this service.\n", service_state_name(svc->current_state));
return ERROR; return ERROR;
} }
if(svc->current_state == STATE_WARNING && svc->notify_on_warning == FALSE) { if(svc->current_state == STATE_OK && svc->notified_on == 0) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about WARNING states for this service.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about this recovery.\n");
return ERROR; return ERROR;
} }
if(svc->current_state == STATE_CRITICAL && svc->notify_on_critical == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about CRITICAL states for this service.\n");
return ERROR;
}
if(svc->current_state == STATE_OK) {
if(svc->notify_on_recovery == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about RECOVERY states for this service.\n");
return ERROR;
}
if(!(svc->notified_on_unknown == TRUE || svc->notified_on_warning == TRUE || svc->notified_on_critical == TRUE)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about this recovery.\n");
return ERROR;
}
}
/* see if enough time has elapsed for first notification (Mathias Sundman) */ /* see if enough time has elapsed for first notification (Mathias Sundman) */
/* 10/02/07 don't place restrictions on recoveries or non-normal notifications, must use last time ok (or program start) in calculation */ /* 10/02/07 don't place restrictions on recoveries or non-normal notifications, must use last time ok (or program start) in calculation */
/* it is reasonable to assume that if the host was never up, the program start time should be used in this calculation */ /* it is reasonable to assume that if the service was never up, the program start time should be used in this calculation */
if(type == NOTIFICATION_NORMAL && svc->current_notification_number == 0 && svc->current_state != STATE_OK) { if(type == NOTIFICATION_NORMAL && svc->current_notification_number == 0 && svc->current_state != STATE_OK) {
/* determine the time to use of the first problem point */ first_problem_time = svc->last_time_ok > 0 ? svc->last_time_ok : program_start;
first_problem_time = svc->last_time_ok; /* not accurate, but its the earliest time we could use in the comparison */
if((svc->last_time_warning < first_problem_time) && (svc->last_time_warning > svc->last_time_ok))
first_problem_time = svc->last_time_warning;
if((svc->last_time_unknown < first_problem_time) && (svc->last_time_unknown > svc->last_time_ok))
first_problem_time = svc->last_time_unknown;
if((svc->last_time_critical < first_problem_time) && (svc->last_time_critical > svc->last_time_ok))
first_problem_time = svc->last_time_critical;
if(current_time < (time_t)((first_problem_time == (time_t)0L) ? program_start : first_problem_time) + (time_t)(svc->first_notification_delay * interval_length)) { if(current_time < first_problem_time + (time_t)(svc->first_notification_delay * interval_length)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Not enough time has elapsed since the service changed to a non-OK state, so we should not notify about this problem yet\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Not enough time has elapsed since the service changed to a non-OK state, so we should not notify about this problem yet\n");
return ERROR; return ERROR;
} }
@ -573,7 +574,7 @@ int check_service_notification_viability(service *svc, int type, int options) {
} }
/* if the host is down or unreachable, don't notify contacts about service failures */ /* if the host is down or unreachable, don't notify contacts about service failures */
if(temp_host->current_state != HOST_UP) { if(temp_host->current_state != STATE_UP && temp_host->state_type == HARD_STATE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "The host is either down or unreachable, so we won't notify contacts about this service.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "The host is either down or unreachable, so we won't notify contacts about this service.\n");
return ERROR; return ERROR;
} }
@ -597,6 +598,18 @@ int check_service_notification_viability(service *svc, int type, int options) {
return ERROR; return ERROR;
} }
/* if this service is currently in a flex downtime period, don't send the notification */
if(svc->pending_flex_downtime > 0 && is_service_in_pending_flex_downtime(svc) == TRUE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "This service is starting a flex downtime, so we won't send notifications.\n");
return ERROR;
}
/* if this host is currently in a flex downtime period, don't send the notification */
if(temp_host->pending_flex_downtime > 0 && is_host_in_pending_flex_downtime(temp_host) == TRUE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "The host this service is associated with is starting a flex downtime, so we won't send notifications.\n");
return ERROR;
}
return OK; return OK;
} }
@ -615,6 +628,12 @@ int check_contact_service_notification_viability(contact *cntct, service *svc, i
return OK; return OK;
} }
/* is this service not important enough? */
if(cntct->minimum_value > svc->hourly_value) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Contact's minimum_importance is higher than service's importance. Notification will be blocked\n");
return ERROR;
}
/* are notifications enabled? */ /* are notifications enabled? */
if(cntct->service_notifications_enabled == FALSE) { if(cntct->service_notifications_enabled == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Service notifications are disabled for this contact.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Service notifications are disabled for this contact.\n");
@ -642,7 +661,7 @@ int check_contact_service_notification_viability(contact *cntct, service *svc, i
if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) { if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) {
if(cntct->notify_on_service_flapping == FALSE) { if((cntct->service_notification_options & OPT_FLAPPING) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about FLAPPING service events.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about FLAPPING service events.\n");
return ERROR; return ERROR;
} }
@ -656,7 +675,7 @@ int check_contact_service_notification_viability(contact *cntct, service *svc, i
if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) { if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) {
if(cntct->notify_on_service_downtime == FALSE) { if((cntct->service_notification_options & OPT_DOWNTIME) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about DOWNTIME service events.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about DOWNTIME service events.\n");
return ERROR; return ERROR;
} }
@ -669,29 +688,19 @@ int check_contact_service_notification_viability(contact *cntct, service *svc, i
/*************************************/ /*************************************/
/* see if we should notify about problems with this service */ /* see if we should notify about problems with this service */
if(svc->current_state == STATE_UNKNOWN && cntct->notify_on_service_unknown == FALSE) { if(!(cntct->service_notification_options & (1 << svc->current_state))) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about UNKNOWN service states.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about %s service states.\n", service_state_name(svc->current_state));
return ERROR;
}
if(svc->current_state == STATE_WARNING && cntct->notify_on_service_warning == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about WARNING service states.\n");
return ERROR;
}
if(svc->current_state == STATE_CRITICAL && cntct->notify_on_service_critical == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about CRITICAL service states.\n");
return ERROR; return ERROR;
} }
if(svc->current_state == STATE_OK) { if(svc->current_state == STATE_OK) {
if(cntct->notify_on_service_recovery == FALSE) { if((cntct->service_notification_options & OPT_RECOVERY) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about RECOVERY service states.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about RECOVERY service states.\n");
return ERROR; return ERROR;
} }
if(!((svc->notified_on_unknown == TRUE && cntct->notify_on_service_unknown == TRUE) || (svc->notified_on_warning == TRUE && cntct->notify_on_service_warning == TRUE) || (svc->notified_on_critical == TRUE && cntct->notify_on_service_critical == TRUE))) { if(!(svc->notified_on & cntct->service_notification_options)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
return ERROR; return ERROR;
} }
@ -713,14 +722,11 @@ int notify_contact_of_service(nagios_macros *mac, contact *cntct, service *svc,
char *processed_command = NULL; char *processed_command = NULL;
char *temp_buffer = NULL; char *temp_buffer = NULL;
char *processed_buffer = NULL; char *processed_buffer = NULL;
int early_timeout = FALSE;
double exectime;
struct timeval start_time, end_time; struct timeval start_time, end_time;
struct timeval method_start_time, method_end_time; struct timeval method_start_time, method_end_time;
int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS;
int neb_result; int neb_result;
log_debug_info(DEBUGL_FUNCTIONS, 0, "notify_contact_of_service()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "notify_contact_of_service()\n");
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "** Notifying contact '%s'\n", cntct->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "** Notifying contact '%s'\n", cntct->name);
@ -817,12 +823,7 @@ int notify_contact_of_service(nagios_macros *mac, contact *cntct, service *svc,
} }
/* run the notification command */ /* run the notification command */
my_system_r(mac, processed_command, notification_timeout, &early_timeout, &exectime, NULL, 0); wproc_notify(cntct->name, svc->host_name, svc->description, processed_command, mac);
/* check to see if the notification command timed out */
if(early_timeout == TRUE) {
logit(NSLOG_SERVICE_NOTIFICATION | NSLOG_RUNTIME_WARNING, TRUE, "Warning: Contact '%s' service notification command '%s' timed out after %d seconds\n", cntct->name, processed_command, notification_timeout);
}
/* free memory */ /* free memory */
my_free(command_name); my_free(command_name);
@ -887,18 +888,12 @@ int is_valid_escalation_for_service_notification(service *svc, serviceescalation
if(se->last_notification != 0 && se->last_notification < notification_number) if(se->last_notification != 0 && se->last_notification < notification_number)
return FALSE; return FALSE;
/* skip this escalation if it has a timeperiod and the current time isn't valid */ /* skip this escalation if the state options don't match */
if(se->escalation_period != NULL && check_time_against_period(current_time, se->escalation_period_ptr) == ERROR) if(flag_isset(se->escalation_options, 1 << svc->current_state) == FALSE)
return FALSE; return FALSE;
/* skip this escalation if the state options don't match */ /* skip this escalation if it has a timeperiod and the current time isn't valid */
if(svc->current_state == STATE_OK && se->escalate_on_recovery == FALSE) if(se->escalation_period != NULL && check_time_against_period(current_time, se->escalation_period_ptr) == ERROR)
return FALSE;
else if(svc->current_state == STATE_WARNING && se->escalate_on_warning == FALSE)
return FALSE;
else if(svc->current_state == STATE_UNKNOWN && se->escalate_on_unknown == FALSE)
return FALSE;
else if(svc->current_state == STATE_CRITICAL && se->escalate_on_critical == FALSE)
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -907,13 +902,13 @@ int is_valid_escalation_for_service_notification(service *svc, serviceescalation
/* checks to see whether a service notification should be escalation */ /* checks to see whether a service notification should be escalation */
int should_service_notification_be_escalated(service *svc) { int should_service_notification_be_escalated(service *svc) {
serviceescalation *temp_se = NULL; objectlist *list;
void *ptr = NULL;
log_debug_info(DEBUGL_FUNCTIONS, 0, "should_service_notification_be_escalated()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "should_service_notification_be_escalated()\n");
/* search the service escalation list */ /* search the service escalation list */
for(temp_se = get_first_serviceescalation_by_service(svc->host_name, svc->description, &ptr); temp_se != NULL; temp_se = get_next_serviceescalation_by_service(svc->host_name, svc->description, &ptr)) { for (list = svc->escalation_list; list; list = list->next) {
serviceescalation *temp_se = (serviceescalation *)list->object_ptr;
/* we found a matching entry, so escalate this notification! */ /* we found a matching entry, so escalate this notification! */
if(is_valid_escalation_for_service_notification(svc, temp_se, NOTIFICATION_OPTION_NONE) == TRUE) { if(is_valid_escalation_for_service_notification(svc, temp_se, NOTIFICATION_OPTION_NONE) == TRUE) {
@ -936,7 +931,6 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
contactgroupsmember *temp_contactgroupsmember = NULL; contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL; contactgroup *temp_contactgroup = NULL;
int escalate_notification = FALSE; int escalate_notification = FALSE;
void *ptr = NULL;
log_debug_info(DEBUGL_FUNCTIONS, 0, "create_notification_list_from_service()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "create_notification_list_from_service()\n");
@ -958,11 +952,13 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
/* use escalated contacts for this notification */ /* use escalated contacts for this notification */
if(escalate_notification == TRUE || (options & NOTIFICATION_OPTION_BROADCAST)) { if(escalate_notification == TRUE || (options & NOTIFICATION_OPTION_BROADCAST)) {
objectlist *list;
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Adding contacts from service escalation(s) to notification list.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Adding contacts from service escalation(s) to notification list.\n");
/* search all the escalation entries for valid matches */ /* search all the escalation entries for valid matches */
for(temp_se = get_first_serviceescalation_by_service(svc->host_name, svc->description, &ptr); temp_se != NULL; temp_se = get_next_serviceescalation_by_service(svc->host_name, svc->description, &ptr)) { for(list = svc->escalation_list; list; list = list->next) {
temp_se = (serviceescalation *)list->object_ptr;
/* skip this entry if it isn't appropriate */ /* skip this entry if it isn't appropriate */
if(is_valid_escalation_for_service_notification(svc, temp_se, options) == FALSE) if(is_valid_escalation_for_service_notification(svc, temp_se, options) == FALSE)
@ -975,10 +971,10 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_service_notification_viability(temp_contact, svc, type, options) == OK) if (check_contact_service_notification_viability(temp_contact, svc, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n",temp_contact->name);
} }
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Adding members of contact groups from service escalation(s) to notification list.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Adding members of contact groups from service escalation(s) to notification list.\n");
@ -992,10 +988,10 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_service_notification_viability(temp_contact, svc, type, options) == OK) if (check_contact_service_notification_viability(temp_contact, svc, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n",temp_contact->name);
} }
} }
} }
@ -1011,10 +1007,10 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_service_notification_viability(temp_contact, svc, type, options) == OK) if (check_contact_service_notification_viability(temp_contact, svc, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n",temp_contact->name);
} }
/* add all contacts that belong to contactgroups for this service */ /* add all contacts that belong to contactgroups for this service */
@ -1025,11 +1021,11 @@ int create_notification_list_from_service(nagios_macros *mac, service *svc, int
for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_service_notification_viability(temp_contact, svc, type, options) == OK) if (check_contact_service_notification_viability(temp_contact, svc, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n",temp_contact->name);
} }
} }
} }
@ -1064,7 +1060,7 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
time(&current_time); time(&current_time);
gettimeofday(&start_time, NULL); gettimeofday(&start_time, NULL);
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "** Host Notification Attempt ** Host: '%s', Type: %d, Options: %d, Current State: %d, Last Notification: %s", hst->name, type, options, hst->current_state, ctime(&hst->last_host_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 0, "** Host Notification Attempt ** Host: '%s', Type: %s, Options: %d, Current State: %d, Last Notification: %s", hst->name, notification_reason_name(type), options, hst->current_state, ctime(&hst->last_notification));
/* check viability of sending out a host notification */ /* check viability of sending out a host notification */
@ -1094,36 +1090,31 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
end_time.tv_sec = 0L; end_time.tv_sec = 0L;
end_time.tv_usec = 0L; end_time.tv_usec = 0L;
neb_result = broker_notification_data(NEBTYPE_NOTIFICATION_START, NEBFLAG_NONE, NEBATTR_NONE, HOST_NOTIFICATION, type, start_time, end_time, (void *)hst, not_author, not_data, escalated, 0, NULL); neb_result = broker_notification_data(NEBTYPE_NOTIFICATION_START, NEBFLAG_NONE, NEBATTR_NONE, HOST_NOTIFICATION, type, start_time, end_time, (void *)hst, not_author, not_data, escalated, 0, NULL);
if(NEBERROR_CALLBACKCANCEL == neb_result) { if(neb_result == NEBERROR_CALLBACKCANCEL || neb_result == NEBERROR_CALLBACKOVERRIDE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "Host notification to %s (id=%u) was blocked by a module.\n", hst->name, hst->id);
free_notification_list(); free_notification_list();
return ERROR; return neb_result == NEBERROR_CALLBACKOVERRIDE ? OK : ERROR;
}
else if(NEBERROR_CALLBACKOVERRIDE == neb_result) {
free_notification_list();
return OK;
} }
#endif #endif
/* reset memory for local macro data */ /* reset memory for local macro data */
memset(&mac, 0, sizeof(mac)); memset(&mac, 0, sizeof(mac));
/* 2011-11-01 MF: /*
check viability before adding a contact * check viability before adding a contact to the notification
to the notification list, requires type * list and build up the $NOTIFICATIONRECIPIENTS$ macro while
this prevents us from running through all * we're at it.
the steps until notify_contact_of_host|service * This prevents us from running through all the steps again in
is reached. furthermore the $NOTIFICATIONRECIPIENTS$ * notify_contact_of_host|service.
macro only gets populated with actual recipients, * Furthermore the $NOTIFICATIONRECIPIENTS$ macro will contain
not all contacts assigned to that host|service. * only actual recipients (as the name implies), and not all
* contacts assigned to that host|service.
note: checks against timeperiod will happen now(), *
and not when the notification is actually being sent. * note: checks against timeperiod will happen now(),
* and not when the notification is actually being sent.
original patch by Opsview Team */
*/
create_notification_list_from_host(&mac, hst, options, &escalated, type); create_notification_list_from_host(&mac, hst, options, &escalated, type);
/* XXX: crazy indent */
/* there are contacts to be notified... */ /* there are contacts to be notified... */
if(notification_list != NULL) { if(notification_list != NULL) {
@ -1132,14 +1123,7 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
/* if this notification has an author, attempt to lookup the associated contact */ /* if this notification has an author, attempt to lookup the associated contact */
if(not_author != NULL) { if(not_author != NULL) {
temp_contact = find_contact_by_name_or_alias(not_author);
/* see if we can find the contact - first by name, then by alias */
if((temp_contact = find_contact(not_author)) == NULL) {
for(temp_contact = contact_list; temp_contact != NULL; temp_contact = temp_contact->next) {
if(!strcmp(temp_contact->alias, not_author))
break;
}
}
} }
/* get author and comment macros */ /* get author and comment macros */
@ -1243,8 +1227,11 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
*/ */
clear_summary_macros_r(&mac); clear_summary_macros_r(&mac);
clear_contact_macros_r(&mac); clear_contact_macros_r(&mac);
clear_contactgroup_macros_r(&mac);
clear_argv_macros_r(&mac); clear_argv_macros_r(&mac);
clear_host_macros_r(&mac); clear_host_macros_r(&mac);
clear_hostgroup_macros_r(&mac);
clear_datetime_macros_r(&mac);
if(type == NOTIFICATION_NORMAL) { if(type == NOTIFICATION_NORMAL) {
@ -1252,18 +1239,15 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
if(contacts_notified > 0) { if(contacts_notified > 0) {
/* calculate the next acceptable re-notification time */ /* calculate the next acceptable re-notification time */
hst->next_host_notification = get_next_host_notification_time(hst, current_time); hst->next_notification = get_next_host_notification_time(hst, current_time);
/* update the last notification time for this host (this is needed for scheduling the next problem notification) */ /* update the last notification time for this host (this is needed for scheduling the next problem notification) */
hst->last_host_notification = current_time; hst->last_notification = current_time;
/* update notifications flags */ /* update notifications flags */
if(hst->current_state == HOST_DOWN) add_notified_on(hst, hst->current_state);
hst->notified_on_down = TRUE;
else if(hst->current_state == HOST_UNREACHABLE)
hst->notified_on_unreachable = TRUE;
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "%d contacts were notified. Next possible notification time: %s", contacts_notified, ctime(&hst->next_host_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 0, "%d contacts were notified. Next possible notification time: %s", contacts_notified, ctime(&hst->next_notification));
} }
/* we didn't end up notifying anyone */ /* we didn't end up notifying anyone */
@ -1272,7 +1256,7 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
/* adjust current notification number */ /* adjust current notification number */
hst->current_notification_number--; hst->current_notification_number--;
log_debug_info(DEBUGL_NOTIFICATIONS, 0, "No contacts were notified. Next possible notification time: %s", ctime(&hst->next_host_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 0, "No contacts were notified. Next possible notification time: %s", ctime(&hst->next_notification));
} }
} }
@ -1343,13 +1327,13 @@ int check_host_notification_viability(host *hst, int type, int options) {
/* it looks like there is no notification time defined, so schedule next one far into the future (one year)... */ /* it looks like there is no notification time defined, so schedule next one far into the future (one year)... */
if(timeperiod_start == (time_t)0) if(timeperiod_start == (time_t)0)
hst->next_host_notification = (time_t)(current_time + (60 * 60 * 24 * 365)); hst->next_notification = (time_t)(current_time + (60 * 60 * 24 * 365));
/* else use the next valid notification time */ /* else use the next valid notification time */
else else
hst->next_host_notification = timeperiod_start; hst->next_notification = timeperiod_start;
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Next possible notification time: %s\n", ctime(&hst->next_host_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Next possible notification time: %s\n", ctime(&hst->next_notification));
} }
return ERROR; return ERROR;
@ -1377,9 +1361,9 @@ int check_host_notification_viability(host *hst, int type, int options) {
/****************************************/ /*****************************************/
/*** SPECIAL CASE FOR ACKNOWLEGEMENTS ***/ /*** SPECIAL CASE FOR ACKNOWLEDGEMENTS ***/
/****************************************/ /*****************************************/
/* acknowledgements only have to pass three general filters, although they have another test of their own... */ /* acknowledgements only have to pass three general filters, although they have another test of their own... */
if(type == NOTIFICATION_ACKNOWLEDGEMENT) { if(type == NOTIFICATION_ACKNOWLEDGEMENT) {
@ -1403,7 +1387,7 @@ int check_host_notification_viability(host *hst, int type, int options) {
if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) { if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) {
/* don't send a notification if we're not supposed to... */ /* don't send a notification if we're not supposed to... */
if(hst->notify_on_flapping == FALSE) { if(!(hst->notification_options & OPT_FLAPPING)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about FLAPPING events for this host.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about FLAPPING events for this host.\n");
return ERROR; return ERROR;
} }
@ -1427,7 +1411,7 @@ int check_host_notification_viability(host *hst, int type, int options) {
if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) { if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) {
/* don't send a notification if we're not supposed to... */ /* don't send a notification if we're not supposed to... */
if(hst->notify_on_downtime == FALSE) { if((hst->notification_options & OPT_DOWNTIME) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about DOWNTIME events for this host.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about DOWNTIME events for this host.\n");
return ERROR; return ERROR;
} }
@ -1466,21 +1450,17 @@ int check_host_notification_viability(host *hst, int type, int options) {
} }
/* see if we should notify about problems with this host */ /* see if we should notify about problems with this host */
if(hst->current_state == HOST_UNREACHABLE && hst->notify_on_unreachable == FALSE) { if((hst->notification_options & (1 << hst->current_state)) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about UNREACHABLE status for this host.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about %s status for this host.\n", host_state_name(hst->current_state));
return ERROR;
}
if(hst->current_state == HOST_DOWN && hst->notify_on_down == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about DOWN states for this host.\n");
return ERROR; return ERROR;
} }
if(hst->current_state == HOST_UP) { if(hst->current_state == HOST_UP) {
if(hst->notify_on_recovery == FALSE) { if((hst->notification_options & OPT_RECOVERY) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about RECOVERY states for this host.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about RECOVERY states for this host.\n");
return ERROR; return ERROR;
} }
if(!(hst->notified_on_down == TRUE || hst->notified_on_unreachable == TRUE)) { if(!hst->notified_on) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about this recovery.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "We shouldn't notify about this recovery.\n");
return ERROR; return ERROR;
} }
@ -1492,14 +1472,9 @@ int check_host_notification_viability(host *hst, int type, int options) {
/* it is reasonable to assume that if the host was never up, the program start time should be used in this calculation */ /* it is reasonable to assume that if the host was never up, the program start time should be used in this calculation */
if(type == NOTIFICATION_NORMAL && hst->current_notification_number == 0 && hst->current_state != HOST_UP) { if(type == NOTIFICATION_NORMAL && hst->current_notification_number == 0 && hst->current_state != HOST_UP) {
/* determine the time to use of the first problem point */ first_problem_time = hst->last_time_up > 0 ? hst->last_time_up : program_start;
first_problem_time = hst->last_time_up; /* not accurate, but its the earliest time we could use in the comparison */
if((hst->last_time_down < first_problem_time) && (hst->last_time_down > hst->last_time_up))
first_problem_time = hst->last_time_down;
if((hst->last_time_unreachable < first_problem_time) && (hst->last_time_unreachable > hst->last_time_unreachable))
first_problem_time = hst->last_time_unreachable;
if(current_time < (time_t)((first_problem_time == (time_t)0L) ? program_start : first_problem_time) + (time_t)(hst->first_notification_delay * interval_length)) { if(current_time < first_problem_time + (time_t)(hst->first_notification_delay * interval_length)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Not enough time has elapsed since the host changed to a non-UP state (or since program start), so we shouldn't notify about this problem yet.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Not enough time has elapsed since the host changed to a non-UP state (or since program start), so we shouldn't notify about this problem yet.\n");
return ERROR; return ERROR;
} }
@ -1528,9 +1503,9 @@ int check_host_notification_viability(host *hst, int type, int options) {
} }
/* check if its time to re-notify the contacts about the host... */ /* check if its time to re-notify the contacts about the host... */
if(current_time < hst->next_host_notification) { if(current_time < hst->next_notification) {
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Its not yet time to re-notify the contacts about this host problem...\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Its not yet time to re-notify the contacts about this host problem...\n");
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Next acceptable notification time: %s", ctime(&hst->next_host_notification)); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Next acceptable notification time: %s", ctime(&hst->next_notification));
return ERROR; return ERROR;
} }
@ -1558,6 +1533,12 @@ int check_contact_host_notification_viability(contact *cntct, host *hst, int typ
return ERROR; return ERROR;
} }
/* is this host important enough? */
if(cntct->minimum_value > hst->hourly_value + host_services_value(hst)) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Contact's minimum_importance is greater than the importance of the host and all its services. Notification will be blocked\n");
return ERROR;
}
/* see if the contact can be notified at this time */ /* see if the contact can be notified at this time */
if(check_time_against_period(time(NULL), cntct->host_notification_period_ptr) == ERROR) { if(check_time_against_period(time(NULL), cntct->host_notification_period_ptr) == ERROR) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "This contact shouldn't be notified at this time.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "This contact shouldn't be notified at this time.\n");
@ -1580,7 +1561,7 @@ int check_contact_host_notification_viability(contact *cntct, host *hst, int typ
if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) { if(type == NOTIFICATION_FLAPPINGSTART || type == NOTIFICATION_FLAPPINGSTOP || type == NOTIFICATION_FLAPPINGDISABLED) {
if(cntct->notify_on_host_flapping == FALSE) { if((cntct->host_notification_options & OPT_FLAPPING) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about FLAPPING host events.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about FLAPPING host events.\n");
return ERROR; return ERROR;
} }
@ -1595,7 +1576,7 @@ int check_contact_host_notification_viability(contact *cntct, host *hst, int typ
if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) { if(type == NOTIFICATION_DOWNTIMESTART || type == NOTIFICATION_DOWNTIMEEND || type == NOTIFICATION_DOWNTIMECANCELLED) {
if(cntct->notify_on_host_downtime == FALSE) { if(flag_isset(cntct->host_notification_options, OPT_DOWNTIME) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about DOWNTIME host events.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about DOWNTIME host events.\n");
return ERROR; return ERROR;
} }
@ -1609,30 +1590,16 @@ int check_contact_host_notification_viability(contact *cntct, host *hst, int typ
/*************************************/ /*************************************/
/* see if we should notify about problems with this host */ /* see if we should notify about problems with this host */
if(hst->current_state == HOST_DOWN && cntct->notify_on_host_down == FALSE) { if(flag_isset(cntct->host_notification_options, 1 << hst->current_state) == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about DOWN states.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about %s states.\n", host_state_name(hst->current_state));
return ERROR; return ERROR;
} }
if(hst->current_state == HOST_UNREACHABLE && cntct->notify_on_host_unreachable == FALSE) { if(hst->current_state == HOST_UP && hst->notified_on == 0) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about UNREACHABLE states,\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
return ERROR; return ERROR;
} }
if(hst->current_state == HOST_UP) {
if(cntct->notify_on_host_recovery == FALSE) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about RECOVERY states.\n");
return ERROR;
}
if(!((hst->notified_on_down == TRUE && cntct->notify_on_host_down == TRUE) || (hst->notified_on_unreachable == TRUE && cntct->notify_on_host_unreachable == TRUE))) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
return ERROR;
}
}
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "** Host notification viability for contact '%s' PASSED.\n", cntct->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "** Host notification viability for contact '%s' PASSED.\n", cntct->name);
return OK; return OK;
@ -1649,8 +1616,6 @@ int notify_contact_of_host(nagios_macros *mac, contact *cntct, host *hst, int ty
char *processed_buffer = NULL; char *processed_buffer = NULL;
char *raw_command = NULL; char *raw_command = NULL;
char *processed_command = NULL; char *processed_command = NULL;
int early_timeout = FALSE;
double exectime;
struct timeval start_time; struct timeval start_time;
struct timeval end_time; struct timeval end_time;
struct timeval method_start_time; struct timeval method_start_time;
@ -1755,12 +1720,9 @@ int notify_contact_of_host(nagios_macros *mac, contact *cntct, host *hst, int ty
} }
/* run the notification command */ /* run the notification command */
my_system_r(mac, processed_command, notification_timeout, &early_timeout, &exectime, NULL, 0); wproc_notify(cntct->name, hst->name, NULL, processed_command, mac);
/* check to see if the notification timed out */ /* @todo Handle nebmod stuff when getting results from workers */
if(early_timeout == TRUE) {
logit(NSLOG_HOST_NOTIFICATION | NSLOG_RUNTIME_WARNING, TRUE, "Warning: Contact '%s' host notification command '%s' timed out after %d seconds\n", cntct->name, processed_command, notification_timeout);
}
/* free memory */ /* free memory */
my_free(command_name); my_free(command_name);
@ -1825,16 +1787,12 @@ int is_valid_escalation_for_host_notification(host *hst, hostescalation *he, int
if(he->last_notification != 0 && he->last_notification < notification_number) if(he->last_notification != 0 && he->last_notification < notification_number)
return FALSE; return FALSE;
/* skip this escalation if it has a timeperiod and the current time isn't valid */ /* skip this escalation if the state options don't match */
if(he->escalation_period != NULL && check_time_against_period(current_time, he->escalation_period_ptr) == ERROR) if(flag_isset(he->escalation_options, 1 << hst->current_state) == FALSE)
return FALSE; return FALSE;
/* skip this escalation if the state options don't match */ /* skip this escalation if it has a timeperiod and the current time isn't valid */
if(hst->current_state == HOST_UP && he->escalate_on_recovery == FALSE) if(he->escalation_period != NULL && check_time_against_period(current_time, he->escalation_period_ptr) == ERROR)
return FALSE;
else if(hst->current_state == HOST_DOWN && he->escalate_on_down == FALSE)
return FALSE;
else if(hst->current_state == HOST_UNREACHABLE && he->escalate_on_unreachable == FALSE)
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -1844,8 +1802,7 @@ int is_valid_escalation_for_host_notification(host *hst, hostescalation *he, int
/* checks to see whether a host notification should be escalation */ /* checks to see whether a host notification should be escalation */
int should_host_notification_be_escalated(host *hst) { int should_host_notification_be_escalated(host *hst) {
hostescalation *temp_he = NULL; objectlist *list;
void *ptr = NULL;
log_debug_info(DEBUGL_FUNCTIONS, 0, "should_host_notification_be_escalated()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "should_host_notification_be_escalated()\n");
@ -1853,8 +1810,8 @@ int should_host_notification_be_escalated(host *hst) {
return FALSE; return FALSE;
/* search the host escalation list */ /* search the host escalation list */
for(temp_he = get_first_hostescalation_by_host(hst->name, &ptr); temp_he != NULL; temp_he = get_next_hostescalation_by_host(hst->name, &ptr)) { for (list = hst->escalation_list; list; list = list->next) {
hostescalation *temp_he = (hostescalation *)list->object_ptr;
/* we found a matching entry, so escalate this notification! */ /* we found a matching entry, so escalate this notification! */
if(is_valid_escalation_for_host_notification(hst, temp_he, NOTIFICATION_OPTION_NONE) == TRUE) if(is_valid_escalation_for_host_notification(hst, temp_he, NOTIFICATION_OPTION_NONE) == TRUE)
return TRUE; return TRUE;
@ -1874,7 +1831,6 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
contactgroupsmember *temp_contactgroupsmember = NULL; contactgroupsmember *temp_contactgroupsmember = NULL;
contactgroup *temp_contactgroup = NULL; contactgroup *temp_contactgroup = NULL;
int escalate_notification = FALSE; int escalate_notification = FALSE;
void *ptr = NULL;
log_debug_info(DEBUGL_FUNCTIONS, 0, "create_notification_list_from_host()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "create_notification_list_from_host()\n");
@ -1895,11 +1851,13 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
/* use escalated contacts for this notification */ /* use escalated contacts for this notification */
if(escalate_notification == TRUE || (options & NOTIFICATION_OPTION_BROADCAST)) { if(escalate_notification == TRUE || (options & NOTIFICATION_OPTION_BROADCAST)) {
objectlist *list;
log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Adding contacts from host escalation(s) to notification list.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 1, "Adding contacts from host escalation(s) to notification list.\n");
/* check all the host escalation entries */ /* check all the host escalation entries */
for(temp_he = get_first_hostescalation_by_host(hst->name, &ptr); temp_he != NULL; temp_he = get_next_hostescalation_by_host(hst->name, &ptr)) { for(list = hst->escalation_list; list; list = list->next) {
temp_he = (hostescalation *)list->object_ptr;
/* see if this escalation if valid for this notification */ /* see if this escalation if valid for this notification */
if(is_valid_escalation_for_host_notification(hst, temp_he, options) == FALSE) if(is_valid_escalation_for_host_notification(hst, temp_he, options) == FALSE)
@ -1912,7 +1870,7 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_host_notification_viability(temp_contact, hst, type, options) == OK) if (check_contact_host_notification_viability(temp_contact, hst, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name);
@ -1928,11 +1886,11 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_host_notification_viability(temp_contact, hst, type, options) == OK) if (check_contact_host_notification_viability(temp_contact, hst, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name);
} }
} }
} }
@ -1949,11 +1907,11 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
for(temp_contactsmember = hst->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { for(temp_contactsmember = hst->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_host_notification_viability(temp_contact, hst, type, options) == OK) if (check_contact_host_notification_viability(temp_contact, hst, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name);
} }
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Adding members of contact groups for host to notification list.\n"); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Adding members of contact groups for host to notification list.\n");
@ -1967,11 +1925,11 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) {
if((temp_contact = temp_contactsmember->contact_ptr) == NULL) if((temp_contact = temp_contactsmember->contact_ptr) == NULL)
continue; continue;
/* check now if the contact can be notified */ /* check now if the contact can be notified */
if(check_contact_host_notification_viability(temp_contact, hst, type, options) == OK) if (check_contact_host_notification_viability(temp_contact, hst, type, options) == OK)
add_notification(mac, temp_contact); add_notification(mac, temp_contact);
else else
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Not adding contact '%s'\n", temp_contact->name);
} }
} }
} }
@ -1991,7 +1949,7 @@ int create_notification_list_from_host(nagios_macros *mac, host *hst, int option
time_t get_next_service_notification_time(service *svc, time_t offset) { time_t get_next_service_notification_time(service *svc, time_t offset) {
time_t next_notification = 0L; time_t next_notification = 0L;
double interval_to_use = 0.0; double interval_to_use = 0.0;
serviceescalation *temp_se = NULL; objectlist *list;
int have_escalated_interval = FALSE; int have_escalated_interval = FALSE;
log_debug_info(DEBUGL_FUNCTIONS, 0, "get_next_service_notification_time()\n"); log_debug_info(DEBUGL_FUNCTIONS, 0, "get_next_service_notification_time()\n");
@ -2004,7 +1962,8 @@ time_t get_next_service_notification_time(service *svc, time_t offset) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Default interval: %f\n", interval_to_use); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Default interval: %f\n", interval_to_use);
/* search all the escalation entries for valid matches for this service (at its current notification number) */ /* search all the escalation entries for valid matches for this service (at its current notification number) */
for(temp_se = serviceescalation_list; temp_se != NULL; temp_se = temp_se->next) { for(list = svc->escalation_list; list; list = list->next) {
serviceescalation *temp_se = (serviceescalation *)list->object_ptr;
/* interval < 0 means to use non-escalated interval */ /* interval < 0 means to use non-escalated interval */
if(temp_se->notification_interval < 0.0) if(temp_se->notification_interval < 0.0)
@ -2049,7 +2008,7 @@ time_t get_next_service_notification_time(service *svc, time_t offset) {
time_t get_next_host_notification_time(host *hst, time_t offset) { time_t get_next_host_notification_time(host *hst, time_t offset) {
time_t next_notification = 0L; time_t next_notification = 0L;
double interval_to_use = 0.0; double interval_to_use = 0.0;
hostescalation *temp_he = NULL; objectlist *list;
int have_escalated_interval = FALSE; int have_escalated_interval = FALSE;
@ -2063,7 +2022,8 @@ time_t get_next_host_notification_time(host *hst, time_t offset) {
log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Default interval: %f\n", interval_to_use); log_debug_info(DEBUGL_NOTIFICATIONS, 2, "Default interval: %f\n", interval_to_use);
/* check all the host escalation entries for valid matches for this host (at its current notification number) */ /* check all the host escalation entries for valid matches for this host (at its current notification number) */
for(temp_he = hostescalation_list; temp_he != NULL; temp_he = temp_he->next) { for(list = hst->escalation_list; list; list = list->next) {
hostescalation *temp_he = (hostescalation *)list->object_ptr;
/* interval < 0 means to use non-escalated interval */ /* interval < 0 means to use non-escalated interval */
if(temp_he->notification_interval < 0.0) if(temp_he->notification_interval < 0.0)

View File

@ -2,8 +2,6 @@
* *
* PERFDATA.C - Performance data routines for Nagios * PERFDATA.C - Performance data routines for Nagios
* *
* Copyright (c) 2000-2004 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 11-29-2004
* *
* License: * License:
* *
@ -30,16 +28,7 @@
#include "../include/objects.h" #include "../include/objects.h"
#include "../include/perfdata.h" #include "../include/perfdata.h"
#include "../include/macros.h" #include "../include/macros.h"
/***** IMPLEMENTATION-SPECIFIC HEADER FILES *****/
#ifdef USE_XPDDEFAULT
#include "../xdata/xpddefault.h" #include "../xdata/xpddefault.h"
#endif
extern int process_performance_data;
/******************************************************************/ /******************************************************************/
@ -47,25 +36,15 @@ extern int process_performance_data;
/******************************************************************/ /******************************************************************/
/* initializes performance data */ /* initializes performance data */
int initialize_performance_data(char *config_file) { int initialize_performance_data(const char *cfgfile) {
return xpddefault_initialize_performance_data(cfgfile);
#ifdef USE_XPDDEFAULT
xpddefault_initialize_performance_data(config_file);
#endif
return OK;
} }
/* cleans up performance data */ /* cleans up performance data */
int cleanup_performance_data(char *config_file) { int cleanup_performance_data(void) {
return xpddefault_cleanup_performance_data();
#ifdef USE_XPDDEFAULT
xpddefault_cleanup_performance_data(config_file);
#endif
return OK;
} }
@ -87,9 +66,7 @@ int update_service_performance_data(service *svc) {
return OK; return OK;
/* process the performance data! */ /* process the performance data! */
#ifdef USE_XPDDEFAULT
xpddefault_update_service_performance_data(svc); xpddefault_update_service_performance_data(svc);
#endif
return OK; return OK;
} }
@ -108,9 +85,7 @@ int update_host_performance_data(host *hst) {
return OK; return OK;
/* process the performance data! */ /* process the performance data! */
#ifdef USE_XPDDEFAULT
xpddefault_update_host_performance_data(hst); xpddefault_update_host_performance_data(hst);
#endif
return OK; return OK;
} }

430
base/query-handler.c Normal file
View File

@ -0,0 +1,430 @@
#include "include/config.h"
#include "include/nagios.h"
#include "lib/libnagios.h"
#include "lib/nsock.h"
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
/* A registered handler */
struct query_handler {
const char *name; /* also "address" of this handler. Must be unique */
const char *description; /* short description of this handler */
unsigned int options;
qh_handler handler;
struct query_handler *prev_qh, *next_qh;
};
static struct query_handler *qhandlers;
static int qh_listen_sock = -1; /* the listening socket */
static unsigned int qh_running;
unsigned int qh_max_running = 0; /* defaults to unlimited */
static dkhash_table *qh_table;
/* the echo service. stupid, but useful for testing */
static int qh_echo(int sd, char *buf, unsigned int len)
{
if (!strcmp(buf, "help")) {
nsock_printf_nul(sd,
"Query handler that simply echoes back what you send it.");
return 0;
}
(void)write(sd, buf, len);
return 0;
}
static struct query_handler *qh_find_handler(const char *name)
{
return (struct query_handler *)dkhash_get(qh_table, name, NULL);
}
/* subset of http error codes */
const char *qh_strerror(int code)
{
if (code < 0)
return "Low-level system error";
if (code == 100)
return "Continue";
if (code == 101)
return "Switching protocols";
if (code < 300)
return "OK";
if (code < 400)
return "Redirected (possibly deprecated address)";
switch (code) {
/* client errors */
case 400: return "Bad request";
case 401: return "Unauthorized";
case 403: return "Forbidden (disabled by config)";
case 404: return "Not found";
case 405: return "Method not allowed";
case 406: return "Not acceptable";
case 407: return "Proxy authentication required";
case 408: return "Request timed out";
case 409: return "Conflict";
case 410: return "Gone";
case 411: return "Length required";
case 412: return "Precondition failed";
case 413: return "Request too large";
case 414: return "Request-URI too long";
/* server errors */
case 500: return "Internal server error";
case 501: return "Not implemented";
case 502: return "Bad gateway";
case 503: return "Service unavailable";
case 504: return "Gateway timeout";
case 505: return "Version not supported";
}
return "Unknown error";
}
static int qh_input(int sd, int events, void *ioc_)
{
iocache *ioc = (iocache *)ioc_;
/* input on main socket, so accept one */
if(sd == qh_listen_sock) {
struct sockaddr sa;
socklen_t slen = 0;
int nsd;
memset(&sa, 0, sizeof(sa)); /* shut valgrind up */
nsd = accept(sd, &sa, &slen);
if(qh_max_running && qh_running >= qh_max_running) {
nsock_printf(nsd, "503: Server full");
close(nsd);
return 0;
}
if(!(ioc = iocache_create(16384))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to create iocache for inbound request\n");
nsock_printf(nsd, "500: Internal server error");
close(nsd);
return 0;
}
/*
* @todo: Stash the iocache and the socket in some
* addressable list so we can release them on deinit
*/
if(iobroker_register(nagios_iobs, nsd, ioc, qh_input) < 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to register input socket %d with I/O broker: %s\n", nsd, strerror(errno));
iocache_destroy(ioc);
close(nsd);
return 0;
}
/* make it non-blocking, but leave kernel buffers unchanged */
worker_set_sockopts(nsd, 0);
qh_running++;
return 0;
}
else {
int result;
unsigned long len;
unsigned int query_len = 0;
char *buf, *space;
struct query_handler *qh;
char *handler = NULL, *query = NULL;
result = iocache_read(ioc, sd);
/* disconnect? */
if(result == 0 || (result < 0 && errno == EPIPE)) {
iocache_destroy(ioc);
iobroker_close(nagios_iobs, sd);
qh_running--;
return 0;
}
/*
* A request looks like this: '[@|#]<qh>[<SP>][<query>]\0'.
* That is, optional '#' (oneshot) or '@' (keepalive),
* followed by the name of a registered handler, followed by
* an optional space and an optional query. If the handler
* has no "default" handler, a query is required or an error
* will be thrown.
*/
/* Use data up to the first nul byte */
buf = iocache_use_delim(ioc, "\0", 1, &len);
if(!buf)
return 0;
/* Identify handler part and any magic query bytes */
if (*buf == '@' || *buf == '#') {
handler = buf + 1;
}
/* Locate query (if any) */
if((space = strchr(buf, ' '))) {
*space = 0;
query = space + 1;
query_len = len - ((unsigned long)query - (unsigned long)buf);
} else {
query = "";
query_len = 0;
}
/* locate the handler */
if(!(qh = qh_find_handler(handler))) {
/* not found. that's a 404 */
nsock_printf(sd, "404: %s: No such handler", handler);
iobroker_close(nagios_iobs, sd);
iocache_destroy(ioc);
return 0;
}
/* strip trailing newlines */
while (query_len > 0 && (query[query_len - 1] == 0 || query[query_len - 1] == '\n'))
query[--query_len] = 0;
/* now pass the query to the handler */
if ((result = qh->handler(sd, query, query_len)) >= 100) {
nsock_printf_nul(sd, "%d: %s", result, qh_strerror(result));
}
if(result >= 300 || *buf == '#') {
/* error code or one-shot query */
iobroker_close(nagios_iobs, sd);
iocache_destroy(ioc);
return 0;
}
/* check for magic handler codes */
switch (result) {
case QH_CLOSE: /* oneshot handler */
case -1: /* general error */
iobroker_close(nagios_iobs, sd);
/* fallthrough */
case QH_TAKEOVER: /* handler takes over */
case 101: /* switch protocol (takeover + message) */
iocache_destroy(ioc);
break;
}
}
return 0;
}
int qh_deregister_handler(const char *name)
{
struct query_handler *qh, *next, *prev;
if (!(qh = dkhash_remove(qh_table, name, NULL)))
return 0;
next = qh->next_qh;
prev = qh->prev_qh;
if (next)
next->prev_qh = prev;
if (prev)
prev->next_qh = next;
else
qhandlers = next;
free(qh);
return 0;
}
int qh_register_handler(const char *name, const char *description, unsigned int options, qh_handler handler)
{
struct query_handler *qh;
int result;
if(!name)
return -1;
if(!handler) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to register handler '%s': No handler function specified\n", name);
return -1;
}
if(strlen(name) > 128) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to register handler '%s': Name too long\n", name);
return -ENAMETOOLONG;
}
/* names must be unique */
if(qh_find_handler(name)) {
logit(NSLOG_RUNTIME_WARNING, TRUE, "qh: Handler '%s' registered more than once\n", name);
return -1;
}
if (!(qh = calloc(1, sizeof(*qh)))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to allocate memory for handler '%s'\n", name);
return -errno;
}
qh->name = name;
qh->description = description;
qh->handler = handler;
qh->options = options;
qh->next_qh = qhandlers;
if (qhandlers)
qhandlers->prev_qh = qh;
qhandlers = qh;
result = dkhash_insert(qh_table, qh->name, NULL, qh);
if(result < 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE,
"qh: Failed to insert query handler '%s' (%p) into hash table %p (%d): %s\n",
name, qh, qh_table, result, strerror(errno));
free(qh);
return result;
}
return 0;
}
void qh_deinit(const char *path)
{
struct query_handler *qh, *next;
for(qh = qhandlers; qh; qh = next) {
next = qh->next_qh;
qh_deregister_handler(qh->name);
}
dkhash_destroy(qh_table);
qh_table = NULL;
qhandlers = NULL;
if(!path)
return;
unlink(path);
}
static int qh_help(int sd, char *buf, unsigned int len)
{
struct query_handler *qh;
if (!*buf || !strcmp(buf, "help")) {
nsock_printf_nul(sd,
" help <name> show help for handler <name>\n"
" help list list registered handlers\n");
return 0;
}
if (!strcmp(buf, "list")) {
for (qh = qhandlers; qh; qh = qh->next_qh) {
nsock_printf(sd, "%-10s %s\n", qh->name, qh->description ? qh->description : "(No description available)");
}
nsock_printf(sd, "%c", 0);
return 0;
}
if (!(qh = qh_find_handler(buf))) {
nsock_printf_nul(sd, "No handler named '%s' is registered\n", buf);
} else if (qh->handler(sd, "help", 4) > 200) {
nsock_printf_nul(sd, "The handler %s doesn't have any help yet.", buf);
}
return 0;
}
static int qh_core(int sd, char *buf, unsigned int len)
{
char *space;
if (!*buf || !strcmp(buf, "help")) {
nsock_printf_nul(sd, "Query handler for manipulating nagios core.\n"
"Available commands:\n"
" loadctl Print information about current load control settings\n"
" loadctl <options> Configure nagios load control.\n"
" The options are the same parameters and format as\n"
" returned above.\n"
" squeuestats scheduling queue statistics\n"
);
return 0;
}
if ((space = memchr(buf, ' ', len)))
*(space++) = 0;
if (!space && !strcmp(buf, "loadctl")) {
nsock_printf_nul
(sd, "jobs_max=%u;jobs_min=%u;"
"jobs_running=%u;jobs_limit=%u;"
"load=%.2f;"
"backoff_limit=%.2f;backoff_change=%u;"
"rampup_limit=%.2f;rampup_change=%u;"
"nproc_limit=%u;nofile_limit=%u;"
"options=%u;changes=%u;",
loadctl.jobs_max, loadctl.jobs_min,
loadctl.jobs_running, loadctl.jobs_limit,
loadctl.load[0],
loadctl.backoff_limit, loadctl.backoff_change,
loadctl.rampup_limit, loadctl.rampup_change,
loadctl.nproc_limit, loadctl.nofile_limit,
loadctl.options, loadctl.changes);
return 0;
}
if (!space && !strcmp(buf, "squeuestats"))
return dump_event_stats(sd);
if (space) {
len -= (unsigned long)space - (unsigned long)buf;
if (!strcmp(buf, "loadctl")) {
return set_loadctl_options(space, len) == OK ? 200 : 400;
}
}
/* No matching command found */
return 404;
}
int qh_init(const char *path)
{
int result, old_umask;
if(qh_listen_sock >= 0)
iobroker_close(nagios_iobs, qh_listen_sock);
if(!path) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: query_socket is NULL. What voodoo is this?\n");
return ERROR;
}
old_umask = umask(0117);
errno = 0;
qh_listen_sock = nsock_unix(path, NSOCK_TCP | NSOCK_UNLINK);
umask(old_umask);
if(qh_listen_sock < 0) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to init socket '%s'. %s: %s\n",
path, nsock_strerror(qh_listen_sock), strerror(errno));
return ERROR;
}
/* plugins shouldn't have this socket */
(void)fcntl(qh_listen_sock, F_SETFD, FD_CLOEXEC);
/* most likely overkill, but it's small, so... */
if(!(qh_table = dkhash_create(1024))) {
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to create hash table\n");
close(qh_listen_sock);
return ERROR;
}
errno = 0;
result = iobroker_register(nagios_iobs, qh_listen_sock, NULL, qh_input);
if(result < 0) {
dkhash_destroy(qh_table);
close(qh_listen_sock);
logit(NSLOG_RUNTIME_ERROR, TRUE, "qh: Failed to register socket with io broker: %s; errno=%d: %s\n", iobroker_strerror(result), errno, strerror(errno));
return ERROR;
}
logit(NSLOG_INFO_MESSAGE, FALSE, "qh: Socket '%s' successfully initialized\n", path);
/* now register our the in-core handlers */
if(!qh_register_handler("core", "Nagios Core control and info", 0, qh_core))
logit(NSLOG_INFO_MESSAGE, FALSE, "qh: core query handler registered\n");
qh_register_handler("echo", "The Echo Service - What You Put Is What You Get", 0, qh_echo);
qh_register_handler("help", "Help for the query handler", 0, qh_help);
return 0;
}

View File

@ -2,8 +2,6 @@
* *
* SEHANDLERS.C - Service and host event and state handlers for Nagios * SEHANDLERS.C - Service and host event and state handlers for Nagios
* *
* Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-05-2010
* *
* License: * License:
* *
@ -31,38 +29,12 @@
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/perfdata.h" #include "../include/perfdata.h"
#include "../include/broker.h" #include "../include/broker.h"
#include "../include/workers.h"
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
#include "../include/neberrors.h" #include "../include/neberrors.h"
#endif #endif
extern int enable_event_handlers;
extern int obsess_over_services;
extern int obsess_over_hosts;
extern int log_event_handlers;
extern unsigned long next_event_id;
extern unsigned long next_problem_id;
extern int event_handler_timeout;
extern int ocsp_timeout;
extern int ochp_timeout;
extern char *global_host_event_handler;
extern char *global_service_event_handler;
extern command *global_host_event_handler_ptr;
extern command *global_service_event_handler_ptr;
extern char *ocsp_command;
extern char *ochp_command;
extern command *ocsp_command_ptr;
extern command *ochp_command_ptr;
extern time_t program_start;
/******************************************************************/ /******************************************************************/
/************* OBSESSIVE COMPULSIVE HANDLER FUNCTIONS *************/ /************* OBSESSIVE COMPULSIVE HANDLER FUNCTIONS *************/
/******************************************************************/ /******************************************************************/
@ -73,8 +45,6 @@ int obsessive_compulsive_service_check_processor(service *svc) {
char *raw_command = NULL; char *raw_command = NULL;
char *processed_command = NULL; char *processed_command = NULL;
host *temp_host = NULL; host *temp_host = NULL;
int early_timeout = FALSE;
double exectime = 0.0;
int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS;
nagios_macros mac; nagios_macros mac;
@ -84,9 +54,7 @@ int obsessive_compulsive_service_check_processor(service *svc) {
return ERROR; return ERROR;
/* bail out if we shouldn't be obsessing */ /* bail out if we shouldn't be obsessing */
if(obsess_over_services == FALSE) if(obsess_over_services == FALSE || svc->obsess == FALSE)
return OK;
if(svc->obsess_over_service == FALSE)
return OK; return OK;
/* if there is no valid command, exit */ /* if there is no valid command, exit */
@ -121,16 +89,11 @@ int obsessive_compulsive_service_check_processor(service *svc) {
log_debug_info(DEBUGL_CHECKS, 2, "Processed obsessive compulsive service processor command line: %s\n", processed_command); log_debug_info(DEBUGL_CHECKS, 2, "Processed obsessive compulsive service processor command line: %s\n", processed_command);
/* run the command */ /* run the command through a worker */
my_system_r(&mac, processed_command, ocsp_timeout, &early_timeout, &exectime, NULL, 0); wproc_run_service_job(WPJOB_OCSP, ocsp_timeout, svc, processed_command, &mac);
clear_volatile_macros_r(&mac);
/* check to see if the command timed out */
if(early_timeout == TRUE)
logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCSP command '%s' for service '%s' on host '%s' timed out after %d seconds\n", processed_command, svc->description, svc->host_name, ocsp_timeout);
/* free memory */ /* free memory */
clear_volatile_macros_r(&mac);
my_free(processed_command); my_free(processed_command);
return OK; return OK;
@ -142,8 +105,6 @@ int obsessive_compulsive_service_check_processor(service *svc) {
int obsessive_compulsive_host_check_processor(host *hst) { int obsessive_compulsive_host_check_processor(host *hst) {
char *raw_command = NULL; char *raw_command = NULL;
char *processed_command = NULL; char *processed_command = NULL;
int early_timeout = FALSE;
double exectime = 0.0;
int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS;
nagios_macros mac; nagios_macros mac;
@ -153,9 +114,7 @@ int obsessive_compulsive_host_check_processor(host *hst) {
return ERROR; return ERROR;
/* bail out if we shouldn't be obsessing */ /* bail out if we shouldn't be obsessing */
if(obsess_over_hosts == FALSE) if(obsess_over_hosts == FALSE || hst->obsess == FALSE)
return OK;
if(hst->obsess_over_host == FALSE)
return OK; return OK;
/* if there is no valid command, exit */ /* if there is no valid command, exit */
@ -185,15 +144,11 @@ int obsessive_compulsive_host_check_processor(host *hst) {
log_debug_info(DEBUGL_CHECKS, 2, "Processed obsessive compulsive host processor command line: %s\n", processed_command); log_debug_info(DEBUGL_CHECKS, 2, "Processed obsessive compulsive host processor command line: %s\n", processed_command);
/* run the command */ /* run the command through a worker */
my_system_r(&mac, processed_command, ochp_timeout, &early_timeout, &exectime, NULL, 0); wproc_run_host_job(WPJOB_OCHP, ochp_timeout, hst, processed_command, &mac);
clear_volatile_macros_r(&mac);
/* check to see if the command timed out */
if(early_timeout == TRUE)
logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCHP command '%s' for host '%s' timed out after %d seconds\n", processed_command, hst->name, ochp_timeout);
/* free memory */ /* free memory */
clear_volatile_macros_r(&mac);
my_free(processed_command); my_free(processed_command);
return OK; return OK;
@ -245,9 +200,6 @@ int handle_service_event(service *svc) {
run_service_event_handler(&mac, svc); run_service_event_handler(&mac, svc);
clear_volatile_macros_r(&mac); clear_volatile_macros_r(&mac);
/* check for external commands - the event handler may have given us some directives... */
check_for_external_commands();
return OK; return OK;
} }
@ -328,8 +280,9 @@ int run_global_service_event_handler(nagios_macros *mac, service *svc) {
} }
#endif #endif
/* run the command */ /* run the command through a worker */
result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); /* XXX FIXME make base/workers.c handle the eventbroker stuff below */
result = wproc_run(WPJOB_GLOBAL_SVC_EVTHANDLER, processed_command, event_handler_timeout, mac);
/* check to see if the event handler timed out */ /* check to see if the event handler timed out */
if(early_timeout == TRUE) if(early_timeout == TRUE)
@ -427,8 +380,9 @@ int run_service_event_handler(nagios_macros *mac, service *svc) {
} }
#endif #endif
/* run the command */ /* run the command through a worker */
result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); /* XXX FIXME make base/workers.c handle the eventbroker stuff below */
result = wproc_run(WPJOB_SVC_EVTHANDLER, processed_command, event_handler_timeout, mac);
/* check to see if the event handler timed out */ /* check to see if the event handler timed out */
if(early_timeout == TRUE) if(early_timeout == TRUE)
@ -492,9 +446,6 @@ int handle_host_event(host *hst) {
if(hst->event_handler != NULL) if(hst->event_handler != NULL)
run_host_event_handler(&mac, hst); run_host_event_handler(&mac, hst);
/* check for external commands - the event handler may have given us some directives... */
check_for_external_commands();
return OK; return OK;
} }
@ -573,8 +524,9 @@ int run_global_host_event_handler(nagios_macros *mac, host *hst) {
} }
#endif #endif
/* run the command */ /* run the command through a worker */
result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); /* XXX FIXME make base/workers.c handle the eventbroker stuff below */
wproc_run(WPJOB_GLOBAL_HOST_EVTHANDLER, processed_command, event_handler_timeout, mac);
/* check for a timeout in the execution of the event handler command */ /* check for a timeout in the execution of the event handler command */
if(early_timeout == TRUE) if(early_timeout == TRUE)
@ -670,8 +622,8 @@ int run_host_event_handler(nagios_macros *mac, host *hst) {
} }
#endif #endif
/* run the command */ /* run the command through a worker */
result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); result = wproc_run(WPJOB_HOST_EVTHANDLER, processed_command, event_handler_timeout, mac);
/* check to see if the event handler timed out */ /* check to see if the event handler timed out */
if(early_timeout == TRUE) if(early_timeout == TRUE)
@ -695,6 +647,3 @@ int run_host_event_handler(nagios_macros *mac, host *hst) {
return OK; return OK;
} }

View File

@ -2,8 +2,6 @@
* *
* SRETENTION.C - State retention routines for Nagios * SRETENTION.C - State retention routines for Nagios
* *
* Copyright (c) 1999-2006 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-18-2006
* *
* License: * License:
* *
@ -31,19 +29,7 @@
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/sretention.h" #include "../include/sretention.h"
#include "../include/broker.h" #include "../include/broker.h"
extern int retain_state_information;
/**** IMPLEMENTATION SPECIFIC HEADER FILES ****/
#ifdef USE_XRDDEFAULT
#include "../xdata/xrddefault.h" /* default routines */ #include "../xdata/xrddefault.h" /* default routines */
#endif
/******************************************************************/ /******************************************************************/
@ -52,29 +38,15 @@ extern int retain_state_information;
/* initializes retention data at program start */ /* initializes retention data at program start */
int initialize_retention_data(char *config_file) { int initialize_retention_data(const char *cfgfile) {
int result = OK; return xrddefault_initialize_retention_data(cfgfile);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XRDDEFAULT
result = xrddefault_initialize_retention_data(config_file);
#endif
return result;
} }
/* cleans up retention data before program termination */ /* cleans up retention data before program termination */
int cleanup_retention_data(char *config_file) { int cleanup_retention_data(void) {
int result = OK; return xrddefault_cleanup_retention_data();
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XRDDEFAULT
result = xrddefault_cleanup_retention_data(config_file);
#endif
return result;
} }
@ -91,10 +63,7 @@ int save_state_information(int autosave) {
broker_retention_data(NEBTYPE_RETENTIONDATA_STARTSAVE, NEBFLAG_NONE, NEBATTR_NONE, NULL); broker_retention_data(NEBTYPE_RETENTIONDATA_STARTSAVE, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif #endif
/********* IMPLEMENTATION-SPECIFIC OUTPUT FUNCTION ********/
#ifdef USE_XRDDEFAULT
result = xrddefault_save_state_information(); result = xrddefault_save_state_information();
#endif
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
/* send data to event broker */ /* send data to event broker */
@ -112,7 +81,6 @@ int save_state_information(int autosave) {
/* reads in initial host and state information */ /* reads in initial host and state information */
int read_initial_state_information(void) { int read_initial_state_information(void) {
int result = OK; int result = OK;
@ -125,10 +93,7 @@ int read_initial_state_information(void) {
broker_retention_data(NEBTYPE_RETENTIONDATA_STARTLOAD, NEBFLAG_NONE, NEBATTR_NONE, NULL); broker_retention_data(NEBTYPE_RETENTIONDATA_STARTLOAD, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif #endif
/********* IMPLEMENTATION-SPECIFIC INPUT FUNCTION ********/
#ifdef USE_XRDDEFAULT
result = xrddefault_read_state_information(); result = xrddefault_read_state_information();
#endif
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
/* send data to event broker */ /* send data to event broker */
@ -140,6 +105,3 @@ int read_initial_state_information(void) {
return OK; return OK;
} }

File diff suppressed because it is too large Load Diff

1162
base/workers.c Normal file

File diff suppressed because it is too large Load Diff

98
base/wp-phash.c Normal file
View File

@ -0,0 +1,98 @@
#define WPRES_type 4
#define WPRES_outerr 6
#define WPRES_timeout 7
#define WPRES_ru_nswap 8
#define WPRES_error_msg 9
#define WPRES_error_code 10
#define WPRES_ru_nsignals 11
#define WPRES_command 12
#define WPRES_ru_majflt 14
#define WPRES_start 15
#define WPRES_outstd 16
#define WPRES_ru_stime 18
#define WPRES_exited_ok 19
#define WPRES_ru_inblock 20
#define WPRES_job_id 21
#define WPRES_ru_minflt 24
#define WPRES_ru_oublock 25
#define WPRES_wait_status 26
#define WPRES_runtime 27
#define WPRES_stop 29
#define WPRES_ru_utime 33
/* C code produced by gperf version 3.0.4 */
/* Command-line: gperf -H wp_phash wproc-strings */
/* Computed positions: -k'4-5' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
#endif
static inline unsigned int
wp_phash(register const char *str, register unsigned int len)
{
/* the last 136 entries have been cut, as we don't need them */
static unsigned char asso_values[256] =
{
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 5, 34, 0, 34, 34,
34, 0, 34, 34, 34, 10, 34, 34, 34, 5,
0, 0, 25, 34, 0, 0, 10, 15, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
34, 34, 34, 34, 34, 34,
};
register int hval = len;
switch (hval) {
default:
hval += asso_values[(unsigned char)str[4]];
/*FALLTHROUGH*/
case 4:
hval += asso_values[(unsigned char)str[3]];
break;
}
return hval;
}

320
base/wpres-phash.h Normal file
View File

@ -0,0 +1,320 @@
/* C code produced by gperf version 3.0.3 */
/* Command-line: gperf -S 1 -t -H wpres_key_phash -N wpres_get_key wpres.gperf */
/* Computed positions: -k'4-5,7' */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
/* The character set is not based on ISO-646. */
error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
#endif
#line 1 "wpres.gperf"
enum {
WPRES_job_id,
WPRES_type,
WPRES_command,
WPRES_timeout,
WPRES_wait_status,
WPRES_start,
WPRES_stop,
WPRES_outstd,
WPRES_outerr,
WPRES_exited_ok,
WPRES_error_msg,
WPRES_error_code,
WPRES_runtime,
WPRES_ru_utime,
WPRES_ru_stime,
WPRES_ru_maxrss,
WPRES_ru_ixrss,
WPRES_ru_idrss,
WPRES_ru_isrss,
WPRES_ru_minflt,
WPRES_ru_majflt,
WPRES_ru_nswap,
WPRES_ru_inblock,
WPRES_ru_oublock,
WPRES_ru_msgsnd,
WPRES_ru_msgrcv,
WPRES_ru_nsignals,
WPRES_ru_nvcsw,
WPRES_ru_nivcsw,
};
#include <string.h> /* for strcmp() */
#line 35 "wpres.gperf"
struct wpres_key {
const char *name;
int code;
};
#define TOTAL_KEYWORDS 29
#define MIN_WORD_LENGTH 4
#define MAX_WORD_LENGTH 11
#define MIN_HASH_VALUE 4
#define MAX_HASH_VALUE 64
/* maximum key range = 61, duplicates = 0 */
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
wpres_key_phash (str, len)
register const char *str;
register unsigned int len;
{
static unsigned char asso_values[] =
{
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 15, 65, 25, 65, 3,
10, 0, 30, 0, 65, 0, 65, 65, 0, 0,
0, 20, 5, 65, 0, 5, 0, 0, 30, 65,
15, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
65, 65, 65, 65, 65, 65
};
register int hval = len;
switch (hval)
{
default:
hval += asso_values[(unsigned char)str[6]];
/*FALLTHROUGH*/
case 6:
case 5:
hval += asso_values[(unsigned char)str[4]];
/*FALLTHROUGH*/
case 4:
hval += asso_values[(unsigned char)str[3]];
break;
}
return hval;
}
#ifdef __GNUC__
__inline
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
struct wpres_key *
wpres_get_key (str, len)
register const char *str;
register unsigned int len;
{
static struct wpres_key wordlist[] =
{
#line 41 "wpres.gperf"
{"type", WPRES_type},
#line 45 "wpres.gperf"
{"start", WPRES_start},
#line 48 "wpres.gperf"
{"outerr", WPRES_outerr},
#line 52 "wpres.gperf"
{"runtime", WPRES_runtime},
#line 53 "wpres.gperf"
{"ru_utime", WPRES_ru_utime},
#line 46 "wpres.gperf"
{"stop", WPRES_stop},
#line 62 "wpres.gperf"
{"ru_inblock", WPRES_ru_inblock},
#line 47 "wpres.gperf"
{"outstd", WPRES_outstd},
#line 68 "wpres.gperf"
{"ru_nivcsw", WPRES_ru_nivcsw},
#line 54 "wpres.gperf"
{"ru_stime", WPRES_ru_stime},
#line 65 "wpres.gperf"
{"ru_msgrcv", WPRES_ru_msgrcv},
#line 66 "wpres.gperf"
{"ru_nsignals", WPRES_ru_nsignals},
#line 58 "wpres.gperf"
{"ru_isrss", WPRES_ru_isrss},
#line 64 "wpres.gperf"
{"ru_msgsnd", WPRES_ru_msgsnd},
#line 40 "wpres.gperf"
{"job_id", WPRES_job_id},
#line 57 "wpres.gperf"
{"ru_idrss", WPRES_ru_idrss},
#line 49 "wpres.gperf"
{"exited_ok", WPRES_exited_ok},
#line 44 "wpres.gperf"
{"wait_status", WPRES_wait_status},
#line 43 "wpres.gperf"
{"timeout", WPRES_timeout},
#line 56 "wpres.gperf"
{"ru_ixrss", WPRES_ru_ixrss},
#line 50 "wpres.gperf"
{"error_msg", WPRES_error_msg},
#line 63 "wpres.gperf"
{"ru_oublock", WPRES_ru_oublock},
#line 51 "wpres.gperf"
{"error_code", WPRES_error_code},
#line 55 "wpres.gperf"
{"ru_maxrss", WPRES_ru_maxrss},
#line 61 "wpres.gperf"
{"ru_nswap", WPRES_ru_nswap},
#line 59 "wpres.gperf"
{"ru_minflt", WPRES_ru_minflt},
#line 42 "wpres.gperf"
{"command", WPRES_command},
#line 67 "wpres.gperf"
{"ru_nvcsw", WPRES_ru_nvcsw},
#line 60 "wpres.gperf"
{"ru_majflt", WPRES_ru_majflt}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = wpres_key_phash (str, len);
if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
{
register struct wpres_key *resword;
switch (key - 4)
{
case 0:
resword = &wordlist[0];
goto compare;
case 1:
resword = &wordlist[1];
goto compare;
case 2:
resword = &wordlist[2];
goto compare;
case 3:
resword = &wordlist[3];
goto compare;
case 4:
resword = &wordlist[4];
goto compare;
case 5:
resword = &wordlist[5];
goto compare;
case 6:
resword = &wordlist[6];
goto compare;
case 7:
resword = &wordlist[7];
goto compare;
case 8:
resword = &wordlist[8];
goto compare;
case 9:
resword = &wordlist[9];
goto compare;
case 10:
resword = &wordlist[10];
goto compare;
case 12:
resword = &wordlist[11];
goto compare;
case 14:
resword = &wordlist[12];
goto compare;
case 15:
resword = &wordlist[13];
goto compare;
case 17:
resword = &wordlist[14];
goto compare;
case 19:
resword = &wordlist[15];
goto compare;
case 20:
resword = &wordlist[16];
goto compare;
case 22:
resword = &wordlist[17];
goto compare;
case 23:
resword = &wordlist[18];
goto compare;
case 24:
resword = &wordlist[19];
goto compare;
case 25:
resword = &wordlist[20];
goto compare;
case 26:
resword = &wordlist[21];
goto compare;
case 29:
resword = &wordlist[22];
goto compare;
case 30:
resword = &wordlist[23];
goto compare;
case 34:
resword = &wordlist[24];
goto compare;
case 35:
resword = &wordlist[25];
goto compare;
case 38:
resword = &wordlist[26];
goto compare;
case 39:
resword = &wordlist[27];
goto compare;
case 60:
resword = &wordlist[28];
goto compare;
}
return 0;
compare:
{
register const char *s = resword->name;
if (*str == *s && !strcmp (str + 1, s + 1))
return resword;
}
}
}
return 0;
}

68
base/wpres.gperf Normal file
View File

@ -0,0 +1,68 @@
%{
enum {
WPRES_job_id,
WPRES_type,
WPRES_command,
WPRES_timeout,
WPRES_wait_status,
WPRES_start,
WPRES_stop,
WPRES_outstd,
WPRES_outerr,
WPRES_exited_ok,
WPRES_error_msg,
WPRES_error_code,
WPRES_runtime,
WPRES_ru_utime,
WPRES_ru_stime,
WPRES_ru_maxrss,
WPRES_ru_ixrss,
WPRES_ru_idrss,
WPRES_ru_isrss,
WPRES_ru_minflt,
WPRES_ru_majflt,
WPRES_ru_nswap,
WPRES_ru_inblock,
WPRES_ru_oublock,
WPRES_ru_msgsnd,
WPRES_ru_msgrcv,
WPRES_ru_nsignals,
WPRES_ru_nvcsw,
WPRES_ru_nivcsw,
};
#include <string.h> /* for strcmp() */
%}
struct wpres_key {
const char *name;
int code;
};
%%
job_id, WPRES_job_id
type, WPRES_type
command, WPRES_command
timeout, WPRES_timeout
wait_status, WPRES_wait_status
start, WPRES_start
stop, WPRES_stop
outstd, WPRES_outstd
outerr, WPRES_outerr
exited_ok, WPRES_exited_ok
error_msg, WPRES_error_msg
error_code, WPRES_error_code
runtime, WPRES_runtime
ru_utime, WPRES_ru_utime
ru_stime, WPRES_ru_stime
ru_maxrss, WPRES_ru_maxrss
ru_ixrss, WPRES_ru_ixrss
ru_idrss, WPRES_ru_idrss
ru_isrss, WPRES_ru_isrss
ru_minflt, WPRES_ru_minflt
ru_majflt, WPRES_ru_majflt
ru_nswap, WPRES_ru_nswap
ru_inblock, WPRES_ru_inblock
ru_oublock, WPRES_ru_oublock
ru_msgsnd, WPRES_ru_msgsnd
ru_msgrcv, WPRES_ru_msgrcv
ru_nsignals, WPRES_ru_nsignals
ru_nvcsw, WPRES_ru_nvcsw
ru_nivcsw, WPRES_ru_nivcsw

View File

@ -1,7 +1,6 @@
############################### ###############################
# Makefile for Nagios CGIs # Makefile for Nagios CGIs
# #
# Last Modified: 10-30-2008
############################### ###############################
@ -9,6 +8,7 @@
SRC_COMMON=../common SRC_COMMON=../common
SRC_INCLUDE=../include SRC_INCLUDE=../include
SRC_XDATA=../xdata SRC_XDATA=../xdata
SRC_LIB=../lib
prefix=@prefix@ prefix=@prefix@
exec_prefix=@exec_prefix@ exec_prefix=@exec_prefix@
@ -26,7 +26,8 @@ CGIEXTRAS=@CGIEXTRAS@
CP=@CP@ CP=@CP@
CC=@CC@ CC=@CC@
CFLAGS=-Wall @CFLAGS@ @DEFS@ -DNSCGI CFLAGS=-Wall -I.. @CFLAGS@ @DEFS@ -DNSCGI
JSONFLAGS=-DJSON_NAGIOS_4X
# Compiler flags for optimization (overrides default) # Compiler flags for optimization (overrides default)
#CFLAGS=-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSCGI #CFLAGS=-O3 -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -DHAVE_CONFIG_H -DNSCGI
@ -39,20 +40,7 @@ CFLAGS=-Wall @CFLAGS@ @DEFS@ -DNSCGI
LDFLAGS=@LDFLAGS@ LDFLAGS=@LDFLAGS@
LIBS=@LIBS@ LIBS=@LIBS@
CGIS=avail.cgi cmd.cgi config.cgi extinfo.cgi history.cgi notifications.cgi outages.cgi showlog.cgi status.cgi statuswml.cgi summary.cgi tac.cgi $(CGIEXTRAS) CGIS=archivejson.cgi avail.cgi cmd.cgi config.cgi extinfo.cgi history.cgi notifications.cgi objectjson.cgi outages.cgi showlog.cgi status.cgi statusjson.cgi statuswml.cgi summary.cgi tac.cgi $(CGIEXTRAS)
# External data I/O code and headers
XSDC=@XSDC@
XSDH=@XSDH@
XCDC=@XCDC@
XCDH=@XCDH@
XODC=@XODC@
XODH=@XODH@
XDDC=@XDDC@
XDDH=@XDDH@
# Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@
# Object functions # Object functions
ODATALIBS=objects-cgi.o xobjects-cgi.o ODATALIBS=objects-cgi.o xobjects-cgi.o
@ -75,9 +63,9 @@ DDATAHDRS=
DDATADEPS=$(DDATALIBS) DDATADEPS=$(DDATALIBS)
# Common CGI functions (includes object and status functions) # Common CGI functions (includes object and status functions)
CGILIBS=$(SRC_COMMON)/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o skiplist.o $(SNPRINTF_O) $(ODATALIBS) $(SDATALIBS) CGILIBS=$(SRC_COMMON)/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o $(SNPRINTF_O) $(ODATALIBS) $(SDATALIBS) $(SRC_LIB)/libnagios.a
CGIHDRS=$(SRC_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/locations.h CGIHDRS=$(SRC_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/locations.h
CGIDEPS=$(CGILIBS) $(ODATADEPS) $(SDATADEPS) CGIDEPS=$(CGILIBS) $(ODATADEPS) $(SDATADEPS) $(SRC_LIB)/libnagios.a
MATHLIBS=-lm MATHLIBS=-lm
@ -91,8 +79,8 @@ $(CGILIBS): $(CGIHDRS)
######## REQUIRED LIBRARIES ########## ######## REQUIRED LIBRARIES ##########
skiplist.o: $(SRC_COMMON)/skiplist.c $(SRC_INCLUDE)/skiplist.h $(SRC_LIB)/libnagios.a:
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/skiplist.c $(MAKE) -C $(SRC_LIB)
macros-cgi.o: $(SRC_COMMON)/macros.c $(SRC_INCLUDE)/macros.h macros-cgi.o: $(SRC_COMMON)/macros.c $(SRC_INCLUDE)/macros.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/macros.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/macros.c
@ -100,27 +88,21 @@ macros-cgi.o: $(SRC_COMMON)/macros.c $(SRC_INCLUDE)/macros.h
objects-cgi.o: $(SRC_COMMON)/objects.c $(SRC_INCLUDE)/objects.h objects-cgi.o: $(SRC_COMMON)/objects.c $(SRC_INCLUDE)/objects.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/objects.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/objects.c
xobjects-cgi.o: $(SRC_XDATA)/$(XODC) $(SRC_XDATA)/$(XODH) xobjects-cgi.o: $(SRC_XDATA)/xodtemplate.c $(SRC_XDATA)/xodtemplate.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XODC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xodtemplate.c
statusdata-cgi.o: $(SRC_COMMON)/statusdata.c $(SRC_INCLUDE)/statusdata.h statusdata-cgi.o: $(SRC_COMMON)/statusdata.c $(SRC_INCLUDE)/statusdata.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/statusdata.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/statusdata.c
xstatusdata-cgi.o: $(SRC_XDATA)/$(XSDC) $(SRC_XDATA)/$(XSDH) xstatusdata-cgi.o: $(SRC_XDATA)/xsddefault.c $(SRC_XDATA)/xsddefault.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XSDC) $(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/xsddefault.c
comments-cgi.o: $(SRC_COMMON)/comments.c $(SRC_INCLUDE)/comments.h comments-cgi.o: $(SRC_COMMON)/comments.c $(SRC_INCLUDE)/comments.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/comments.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/comments.c
xcomments-cgi.o: $(SRC_XDATA)/$(XCDC) $(SRC_XDATA)/$(XCDH)
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XCDC)
downtime-cgi.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h downtime-cgi.o: $(SRC_COMMON)/downtime.c $(SRC_INCLUDE)/downtime.h
$(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c $(CC) $(CFLAGS) -c -o $@ $(SRC_COMMON)/downtime.c
xdowntime-cgi.o: $(SRC_XDATA)/$(XDDC) $(SRC_XDATA)/$(XDDH)
$(CC) $(CFLAGS) -c -o $@ $(SRC_XDATA)/$(XDDC)
$(SRC_COMMON)/shared.o: $(SRC_COMMON)/shared.c $(SRC_COMMON)/shared.o: $(SRC_COMMON)/shared.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
@ -183,6 +165,24 @@ trends.cgi: trends.c $(CGIDEPS)
histogram.cgi: histogram.c $(CGIDEPS) histogram.cgi: histogram.c $(CGIDEPS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ histogram.c $(CGILIBS) $(GDLIBS) $(LIBS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ histogram.c $(CGILIBS) $(GDLIBS) $(LIBS)
########## JSON CGIS ##########
jsonutils.o: jsonutils.c $(SRC_INCLUDE)/jsonutils.h
$(CC) $(CFLAGS) $(JSONFLAGS) -c -o $@ jsonutils.c
archiveutils.o: archiveutils.c $(SRC_INCLUDE)/archiveutils.h
$(CC) $(CFLAGS) $(JSONFLAGS) -c -o $@ archiveutils.c
archivejson.cgi: archivejson.c $(CGIDEPS) archiveutils.o jsonutils.o $(SRC_INCLUDE)/archivejson.h
$(CC) $(CFLAGS) $(JSONFLAGS) $(LDFLAGS) -o $@ archivejson.c $(CGILIBS) archiveutils.o jsonutils.o $(LIBS)
objectjson.cgi: objectjson.c $(CGIDEPS) jsonutils.o $(SRC_INCLUDE)/objectjson.h
$(CC) $(CFLAGS) $(JSONFLAGS) $(LDFLAGS) -o $@ objectjson.c $(CGILIBS) jsonutils.o $(LIBS)
statusjson.cgi: statusjson.c $(CGIDEPS) jsonutils.o $(SRC_INCLUDE)/statusjson.h
$(CC) $(CFLAGS) $(JSONFLAGS) $(LDFLAGS) -o $@ statusjson.c $(CGILIBS) jsonutils.o $(LIBS)
clean: clean:
rm -f $(CGIS) rm -f $(CGIS)
rm -f *.o core gmon.out rm -f *.o core gmon.out
@ -212,3 +212,4 @@ strip-post-install:
done done
.PHONY: libnagios

4622
cgi/archivejson.c Normal file

File diff suppressed because it is too large Load Diff

1650
cgi/archiveutils.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@
* *
* AVAIL.C - Nagios Availability CGI * AVAIL.C - Nagios Availability CGI
* *
* Copyright (c) 2000-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-05-2010
* *
* License: * License:
* *
@ -37,14 +35,6 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern host *host_list;
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
extern service *service_list;
extern timeperiod *timeperiod_list;
extern int log_rotation_method;
#ifndef max #ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b)) #define max(a,b) (((a) > (b)) ? (a) : (b))
#endif #endif
@ -232,14 +222,14 @@ void write_log_entries(avail_subject *);
void get_running_average(double *, double, int); void get_running_average(double *, double, int);
void host_report_url(char *, char *); void host_report_url(const char *, const char *);
void service_report_url(char *, char *, char *); void service_report_url(const char *, const char *, const char *);
void compute_report_times(void); void compute_report_times(void);
int convert_host_state_to_archived_state(int); int convert_host_state_to_archived_state(int);
int convert_service_state_to_archived_state(int); int convert_service_state_to_archived_state(int);
void add_global_archived_state(int, int, time_t, char *); void add_global_archived_state(int, int, time_t, const char *);
void add_archived_state(int, int, time_t, char *, avail_subject *); void add_archived_state(int, int, time_t, const char *, avail_subject *);
void add_scheduled_downtime(int, time_t, avail_subject *); void add_scheduled_downtime(int, time_t, avail_subject *);
void free_availability_data(void); void free_availability_data(void);
void free_archived_state_list(archived_state *); void free_archived_state_list(archived_state *);
@ -267,7 +257,6 @@ int output_format = HTML_OUTPUT;
int main(int argc, char **argv) { int main(int argc, char **argv) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
char start_timestring[MAX_DATETIME_LENGTH]; char start_timestring[MAX_DATETIME_LENGTH];
char end_timestring[MAX_DATETIME_LENGTH]; char end_timestring[MAX_DATETIME_LENGTH];
@ -288,41 +277,7 @@ int main(int argc, char **argv) {
/* reset internal CGI variables */ /* reset internal CGI variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, READ_ALL_STATUS_DATA);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
/* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
if(result == ERROR) {
document_header(FALSE);
status_data_error();
document_footer();
return ERROR;
}
/* initialize time period to last 24 hours */ /* initialize time period to last 24 hours */
time(&current_time); time(&current_time);
@ -489,7 +444,10 @@ int main(int argc, char **argv) {
printf("<div align=center class='reportRange'>%s to %s</div>\n", start_timestring, end_timestring); printf("<div align=center class='reportRange'>%s to %s</div>\n", start_timestring, end_timestring);
get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds); get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds);
printf("<div align=center class='reportDuration'>Duration: %dd %dh %dm %ds</div>\n", days, hours, minutes, seconds); printf("<div align=center class='reportDuration'>Duration: %dd %dh %dm %ds", days, hours, minutes, seconds);
if (current_timeperiod)
printf("<br>(using timeperiod %s)", current_timeperiod->name);
printf("</div>\n");
} }
printf("</td>\n"); printf("</td>\n");
@ -1078,7 +1036,7 @@ void document_header(int use_stylesheet) {
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
if(output_format == HTML_OUTPUT) if(output_format == HTML_OUTPUT)
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
else { else {
printf("Content-type: text/csv\r\n\r\n"); printf("Content-type: text/csv\r\n\r\n");
return; return;
@ -1141,7 +1099,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -1635,7 +1592,7 @@ int process_cgivars(void) {
} }
for(temp_timeperiod = timeperiod_list; temp_timeperiod != NULL; temp_timeperiod = temp_timeperiod->next) { for(temp_timeperiod = timeperiod_list; temp_timeperiod != NULL; temp_timeperiod = temp_timeperiod->next) {
if(!strcmp(url_encode(temp_timeperiod->name), variables[x])) { if(!strcmp(temp_timeperiod->name, variables[x])) {
current_timeperiod = temp_timeperiod; current_timeperiod = temp_timeperiod;
break; break;
} }
@ -1679,7 +1636,6 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
int have_some_real_data = FALSE; int have_some_real_data = FALSE;
hoststatus *hststatus = NULL; hoststatus *hststatus = NULL;
servicestatus *svcstatus = NULL; servicestatus *svcstatus = NULL;
int first_real_state = AS_NO_DATA;
time_t initial_assumed_time; time_t initial_assumed_time;
int initial_assumed_state = AS_NO_DATA; int initial_assumed_state = AS_NO_DATA;
int error; int error;
@ -1710,11 +1666,11 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
if(subject->type == HOST_SUBJECT) { if(subject->type == HOST_SUBJECT) {
if(hststatus != NULL) { if(hststatus != NULL) {
if(hststatus->status == HOST_DOWN) if(hststatus->status == SD_HOST_DOWN)
subject->last_known_state = AS_HOST_DOWN; subject->last_known_state = AS_HOST_DOWN;
else if(hststatus->status == HOST_UNREACHABLE) else if(hststatus->status == SD_HOST_UNREACHABLE)
subject->last_known_state = AS_HOST_UNREACHABLE; subject->last_known_state = AS_HOST_UNREACHABLE;
else if(hststatus->status == HOST_UP) else if(hststatus->status == SD_HOST_UP)
subject->last_known_state = AS_HOST_UP; subject->last_known_state = AS_HOST_UP;
else else
subject->last_known_state = AS_NO_DATA; subject->last_known_state = AS_NO_DATA;
@ -1723,9 +1679,6 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
/* add a dummy archived state item, so something can get graphed */ /* add a dummy archived state item, so something can get graphed */
add_archived_state(subject->last_known_state, AS_HARD_STATE, t1, "Current Host State Assumed (Faked Log Entry)", subject); add_archived_state(subject->last_known_state, AS_HARD_STATE, t1, "Current Host State Assumed (Faked Log Entry)", subject);
/* use the current state as the last known real state */
first_real_state = subject->last_known_state;
} }
} }
} }
@ -1747,9 +1700,6 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
/* add a dummy archived state item, so something can get graphed */ /* add a dummy archived state item, so something can get graphed */
add_archived_state(subject->last_known_state, AS_HARD_STATE, t1, "Current Service State Assumed (Faked Log Entry)", subject); add_archived_state(subject->last_known_state, AS_HARD_STATE, t1, "Current Service State Assumed (Faked Log Entry)", subject);
/* use the current state as the last known real state */
first_real_state = subject->last_known_state;
} }
} }
} }
@ -1805,13 +1755,13 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
} }
else { else {
switch(hststatus->status) { switch(hststatus->status) {
case HOST_DOWN: case SD_HOST_DOWN:
initial_assumed_state = AS_HOST_DOWN; initial_assumed_state = AS_HOST_DOWN;
break; break;
case HOST_UNREACHABLE: case SD_HOST_UNREACHABLE:
initial_assumed_state = AS_HOST_UNREACHABLE; initial_assumed_state = AS_HOST_UNREACHABLE;
break; break;
case HOST_UP: case SD_HOST_UP:
initial_assumed_state = AS_HOST_UP; initial_assumed_state = AS_HOST_UP;
break; break;
default: default:
@ -1981,10 +1931,9 @@ void compute_subject_availability(avail_subject *subject, time_t current_time) {
/* computes availability times */ /* computes availability times */
void compute_subject_availability_times(int first_state, int last_state, time_t real_start_time, time_t start_time, time_t end_time, avail_subject *subject, archived_state *as) { void compute_subject_availability_times(int first_state, int last_state, time_t real_start_time, time_t start_time, time_t end_time, avail_subject *subject, archived_state *as) {
int start_state; int start_state;
int end_state;
unsigned long state_duration; unsigned long state_duration;
struct tm *t; struct tm *t;
unsigned long midnight_today; time_t midnight_today;
int weekday; int weekday;
timerange *temp_timerange; timerange *temp_timerange;
unsigned long temp_duration; unsigned long temp_duration;
@ -2116,12 +2065,6 @@ void compute_subject_availability_times(int first_state, int last_state, time_t
subject->last_known_state = first_state; subject->last_known_state = first_state;
} }
/* special case if last entry was program stop */
if(last_state == AS_PROGRAM_END)
end_state = first_state;
else
end_state = last_state;
/* save "processed state" info */ /* save "processed state" info */
as->processed_state = start_state; as->processed_state = start_state;
@ -2166,8 +2109,8 @@ void compute_subject_downtime(avail_subject *subject, time_t current_time) {
archived_state *temp_sd; archived_state *temp_sd;
time_t start_time; time_t start_time;
time_t end_time; time_t end_time;
int host_downtime_depth = 0; int host_downtime_state = 0;
int service_downtime_depth = 0; int service_downtime_state = 0;
int process_chunk = FALSE; int process_chunk = FALSE;
#ifdef DEBUG2 #ifdef DEBUG2
@ -2209,20 +2152,20 @@ void compute_subject_downtime(avail_subject *subject, time_t current_time) {
break; break;
if(temp_sd->entry_type == AS_HOST_DOWNTIME_START) if(temp_sd->entry_type == AS_HOST_DOWNTIME_START)
host_downtime_depth++; host_downtime_state = 1;
else if(temp_sd->entry_type == AS_HOST_DOWNTIME_END) else if(temp_sd->entry_type == AS_HOST_DOWNTIME_END)
host_downtime_depth--; host_downtime_state = 0;
else if(temp_sd->entry_type == AS_SVC_DOWNTIME_START) else if(temp_sd->entry_type == AS_SVC_DOWNTIME_START)
service_downtime_depth++; service_downtime_state = 1;
else if(temp_sd->entry_type == AS_SVC_DOWNTIME_END) else if(temp_sd->entry_type == AS_SVC_DOWNTIME_END)
service_downtime_depth--; service_downtime_state = 0;
else else
continue; continue;
process_chunk = FALSE; process_chunk = FALSE;
if(temp_sd->entry_type == AS_HOST_DOWNTIME_START || temp_sd->entry_type == AS_SVC_DOWNTIME_START) if(temp_sd->entry_type == AS_HOST_DOWNTIME_START || temp_sd->entry_type == AS_SVC_DOWNTIME_START)
process_chunk = TRUE; process_chunk = TRUE;
else if(subject->type == SERVICE_SUBJECT && (host_downtime_depth > 0 || service_downtime_depth > 0)) else if(subject->type == SERVICE_SUBJECT && (host_downtime_state == 1 || service_downtime_state == 1))
process_chunk = TRUE; process_chunk = TRUE;
/* process this specific "chunk" of scheduled downtime */ /* process this specific "chunk" of scheduled downtime */
@ -2257,10 +2200,9 @@ void compute_subject_downtime(avail_subject *subject, time_t current_time) {
/* computes downtime times */ /* computes downtime times */
void compute_subject_downtime_times(time_t start_time, time_t end_time, avail_subject *subject, archived_state *sd) { void compute_subject_downtime_times(time_t start_time, time_t end_time, avail_subject *subject, archived_state *sd) {
archived_state *temp_as = NULL; archived_state *temp_as = NULL;
time_t part_start_time = 0L;
time_t part_subject_state = 0L; time_t part_subject_state = 0L;
int saved_status = 0; int saved_status = 0;
int saved_stamp = 0; time_t saved_stamp = 0;
int count = 0; int count = 0;
archived_state *temp_before = NULL; archived_state *temp_before = NULL;
archived_state *last = NULL; archived_state *last = NULL;
@ -2302,7 +2244,6 @@ void compute_subject_downtime_times(time_t start_time, time_t end_time, avail_su
} }
/* initialize values */ /* initialize values */
part_start_time = start_time;
if(temp_as == NULL) if(temp_as == NULL)
part_subject_state = AS_NO_DATA; part_subject_state = AS_NO_DATA;
else if(temp_as->processed_state == AS_PROGRAM_START || temp_as->processed_state == AS_PROGRAM_END || temp_as->processed_state == AS_NO_DATA) { else if(temp_as->processed_state == AS_PROGRAM_START || temp_as->processed_state == AS_PROGRAM_END || temp_as->processed_state == AS_NO_DATA) {
@ -2364,6 +2305,11 @@ void compute_subject_downtime_times(time_t start_time, time_t end_time, avail_su
} }
saved_status = temp_as->entry_type; saved_status = temp_as->entry_type;
saved_stamp = temp_as->time_stamp; saved_stamp = temp_as->time_stamp;
/* check if first time is before schedule downtime */
if(saved_stamp < start_time)
saved_stamp = start_time;
} }
} }
@ -2436,11 +2382,11 @@ void compute_subject_downtime_part_times(time_t start_time, time_t end_time, int
/* convert current host state to archived state value */ /* convert current host state to archived state value */
int convert_host_state_to_archived_state(int current_status) { int convert_host_state_to_archived_state(int current_status) {
if(current_status == HOST_UP) if(current_status == SD_HOST_UP)
return AS_HOST_UP; return AS_HOST_UP;
if(current_status == HOST_DOWN) if(current_status == SD_HOST_DOWN)
return AS_HOST_DOWN; return AS_HOST_DOWN;
if(current_status == HOST_UNREACHABLE) if(current_status == SD_HOST_UNREACHABLE)
return AS_HOST_UNREACHABLE; return AS_HOST_UNREACHABLE;
return AS_NO_DATA; return AS_NO_DATA;
@ -2472,7 +2418,7 @@ void create_subject_list(void) {
servicesmember *temp_sgmember; servicesmember *temp_sgmember;
host *temp_host; host *temp_host;
service *temp_service; service *temp_service;
char *last_host_name = ""; const char *last_host_name = "";
/* we're displaying one or more hosts */ /* we're displaying one or more hosts */
if(display_type == DISPLAY_HOST_AVAIL && host_name && strcmp(host_name, "")) { if(display_type == DISPLAY_HOST_AVAIL && host_name && strcmp(host_name, "")) {
@ -2681,7 +2627,7 @@ avail_subject *find_subject(int type, char *hn, char *sd) {
/* adds an archived state entry to all subjects */ /* adds an archived state entry to all subjects */
void add_global_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info) { void add_global_archived_state(int entry_type, int state_type, time_t time_stamp, const char *state_info) {
avail_subject *temp_subject; avail_subject *temp_subject;
for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next) for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next)
@ -2694,7 +2640,7 @@ void add_global_archived_state(int entry_type, int state_type, time_t time_stamp
/* adds an archived state entry to a specific subject */ /* adds an archived state entry to a specific subject */
void add_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info, avail_subject *subject) { void add_archived_state(int entry_type, int state_type, time_t time_stamp, const char *state_info, avail_subject *subject) {
archived_state *last_as = NULL; archived_state *last_as = NULL;
archived_state *temp_as = NULL; archived_state *temp_as = NULL;
archived_state *new_as = NULL; archived_state *new_as = NULL;
@ -3240,10 +3186,10 @@ void write_log_entries(avail_subject *subject) {
char start_date_time[MAX_DATETIME_LENGTH]; char start_date_time[MAX_DATETIME_LENGTH];
char end_date_time[MAX_DATETIME_LENGTH]; char end_date_time[MAX_DATETIME_LENGTH];
char duration[20]; char duration[20];
char *bgclass = ""; const char *bgclass = "";
char *ebgclass = ""; const char *ebgclass = "";
char *entry_type = ""; const char *entry_type = "";
char *state_type = ""; const char *state_type = "";
int days; int days;
int hours; int hours;
int minutes; int minutes;
@ -3473,7 +3419,7 @@ void display_specific_hostgroup_availability(hostgroup *hg) {
int current_subject = 0; int current_subject = 0;
char *bgclass = ""; const char *bgclass = "";
int odd = 1; int odd = 1;
host *temp_host; host *temp_host;
@ -3633,7 +3579,7 @@ void display_specific_servicegroup_availability(servicegroup *sg) {
int current_subject = 0; int current_subject = 0;
char *bgclass = ""; const char *bgclass = "";
int odd = 1; int odd = 1;
host *temp_host; host *temp_host;
service *temp_service; service *temp_service;
@ -3886,8 +3832,6 @@ void display_host_availability(void) {
char time_indeterminate_scheduled_string[48]; char time_indeterminate_scheduled_string[48];
char time_indeterminate_unscheduled_string[48]; char time_indeterminate_unscheduled_string[48];
double percent_time_indeterminate_scheduled = 0.0;
double percent_time_indeterminate_unscheduled = 0.0;
char time_indeterminate_notrunning_string[48]; char time_indeterminate_notrunning_string[48];
char time_indeterminate_nodata_string[48]; char time_indeterminate_nodata_string[48];
double percent_time_indeterminate_notrunning = 0.0; double percent_time_indeterminate_notrunning = 0.0;
@ -3912,7 +3856,7 @@ void display_host_availability(void) {
int current_subject = 0; int current_subject = 0;
char *bgclass = ""; const char *bgclass = "";
int odd = 1; int odd = 1;
/* calculate total time during period based on timeperiod used for reporting */ /* calculate total time during period based on timeperiod used for reporting */
@ -3996,8 +3940,6 @@ void display_host_availability(void) {
percent_time_unreachable_scheduled = (double)(((double)temp_subject->scheduled_time_unreachable * 100.0) / (double)total_time); percent_time_unreachable_scheduled = (double)(((double)temp_subject->scheduled_time_unreachable * 100.0) / (double)total_time);
percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled; percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled;
percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time); percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_scheduled = (double)(((double)temp_subject->scheduled_time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_unscheduled = percent_time_indeterminate - percent_time_indeterminate_scheduled;
percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time); percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time);
percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time); percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time);
if(time_determinate > 0) { if(time_determinate > 0) {
@ -4019,7 +3961,11 @@ void display_host_availability(void) {
printf("<p align='center'>\n"); printf("<p align='center'>\n");
printf("<a href='%s?host=%s", TRENDS_CGI, url_encode(host_name)); printf("<a href='%s?host=%s", TRENDS_CGI, url_encode(host_name));
printf("&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d'>", t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives); printf("&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d'>", t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives);
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<img src='%s?createimage&smallimage&host=%s", TRENDS_CGI, url_encode(host_name)); printf("<img src='%s?createimage&smallimage&host=%s", TRENDS_CGI, url_encode(host_name));
#else
printf("<img src='%s?createimage&smallimage&host=%s", LEGACY_TRENDS_CGI, url_encode(host_name));
#endif
printf("&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d' border=1 alt='Host State Trends' title='Host State Trends' width='500' height='20'>", t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives); printf("&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d' border=1 alt='Host State Trends' title='Host State Trends' width='500' height='20'>", t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives);
printf("</a><br>\n"); printf("</a><br>\n");
printf("</p>\n"); printf("</p>\n");
@ -4216,8 +4162,6 @@ void display_host_availability(void) {
percent_time_unreachable_scheduled = 0.0; percent_time_unreachable_scheduled = 0.0;
percent_time_unreachable_unscheduled = 0.0; percent_time_unreachable_unscheduled = 0.0;
percent_time_indeterminate = 0.0; percent_time_indeterminate = 0.0;
percent_time_indeterminate_scheduled = 0.0;
percent_time_indeterminate_unscheduled = 0.0;
percent_time_indeterminate_notrunning = 0.0; percent_time_indeterminate_notrunning = 0.0;
percent_time_indeterminate_nodata = 0.0; percent_time_indeterminate_nodata = 0.0;
percent_time_up_known = 0.0; percent_time_up_known = 0.0;
@ -4241,8 +4185,6 @@ void display_host_availability(void) {
percent_time_unreachable_scheduled = (double)(((double)temp_subject->scheduled_time_unreachable * 100.0) / (double)total_time); percent_time_unreachable_scheduled = (double)(((double)temp_subject->scheduled_time_unreachable * 100.0) / (double)total_time);
percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled; percent_time_unreachable_unscheduled = percent_time_unreachable - percent_time_unreachable_scheduled;
percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time); percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_scheduled = (double)(((double)temp_subject->scheduled_time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_unscheduled = percent_time_indeterminate - percent_time_indeterminate_scheduled;
percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time); percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time);
percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time); percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time);
if(time_determinate > 0) { if(time_determinate > 0) {
@ -4386,15 +4328,13 @@ void display_service_availability(void) {
char time_indeterminate_scheduled_string[48]; char time_indeterminate_scheduled_string[48];
char time_indeterminate_unscheduled_string[48]; char time_indeterminate_unscheduled_string[48];
double percent_time_indeterminate_scheduled = 0.0;
double percent_time_indeterminate_unscheduled = 0.0;
char time_indeterminate_notrunning_string[48]; char time_indeterminate_notrunning_string[48];
char time_indeterminate_nodata_string[48]; char time_indeterminate_nodata_string[48];
double percent_time_indeterminate_notrunning = 0.0; double percent_time_indeterminate_notrunning = 0.0;
double percent_time_indeterminate_nodata = 0.0; double percent_time_indeterminate_nodata = 0.0;
int odd = 1; int odd = 1;
char *bgclass = ""; const char *bgclass = "";
char last_host[128] = ""; char last_host[128] = "";
@ -4477,7 +4417,7 @@ void display_service_availability(void) {
percent_time_ok_scheduled = (double)(((double)temp_subject->scheduled_time_ok * 100.0) / (double)total_time); percent_time_ok_scheduled = (double)(((double)temp_subject->scheduled_time_ok * 100.0) / (double)total_time);
percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled; percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled;
percent_time_warning = (double)(((double)temp_subject->time_warning * 100.0) / (double)total_time); percent_time_warning = (double)(((double)temp_subject->time_warning * 100.0) / (double)total_time);
percent_time_warning_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time); percent_time_warning_scheduled = (double)(((double)temp_subject->scheduled_time_warning * 100.0) / (double)total_time);
percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled; percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled;
percent_time_unknown = (double)(((double)temp_subject->time_unknown * 100.0) / (double)total_time); percent_time_unknown = (double)(((double)temp_subject->time_unknown * 100.0) / (double)total_time);
percent_time_unknown_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time); percent_time_unknown_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time);
@ -4486,8 +4426,6 @@ void display_service_availability(void) {
percent_time_critical_scheduled = (double)(((double)temp_subject->scheduled_time_critical * 100.0) / (double)total_time); percent_time_critical_scheduled = (double)(((double)temp_subject->scheduled_time_critical * 100.0) / (double)total_time);
percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled; percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled;
percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time); percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_scheduled = (double)(((double)temp_subject->scheduled_time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_unscheduled = percent_time_indeterminate - percent_time_indeterminate_scheduled;
percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time); percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time);
percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time); percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time);
if(time_determinate > 0) { if(time_determinate > 0) {
@ -4511,7 +4449,11 @@ void display_service_availability(void) {
printf("<p align='center'>\n"); printf("<p align='center'>\n");
printf("<a href='%s?host=%s", TRENDS_CGI, url_encode(host_name)); printf("<a href='%s?host=%s", TRENDS_CGI, url_encode(host_name));
printf("&service=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives); printf("&service=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives);
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<img src='%s?createimage&smallimage&host=%s", TRENDS_CGI, url_encode(host_name)); printf("<img src='%s?createimage&smallimage&host=%s", TRENDS_CGI, url_encode(host_name));
#else
printf("<img src='%s?createimage&smallimage&host=%s", LEGACY_TRENDS_CGI, url_encode(host_name));
#endif
printf("&service=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d' border=1 alt='Service State Trends' title='Service State Trends' width='500' height='20'>", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives); printf("&service=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d' border=1 alt='Service State Trends' title='Service State Trends' width='500' height='20'>", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives);
printf("</a><br>\n"); printf("</a><br>\n");
printf("</p>\n"); printf("</p>\n");
@ -4547,10 +4489,7 @@ void display_service_availability(void) {
printf("<tr CLASS='dataEven'><td CLASS='dataEven' rowspan=3>Undetermined</td>"); printf("<tr CLASS='dataEven'><td CLASS='dataEven' rowspan=3>Undetermined</td>");
/*
printf("<td CLASS='dataEven'>Unscheduled</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n",time_indeterminate_unscheduled_string,percent_time_indeterminate_unscheduled);
printf("<tr CLASS='dataEven'><td CLASS='dataEven'>Scheduled</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n",time_indeterminate_scheduled_string,percent_time_indeterminate_scheduled);
*/
printf("<td CLASS='dataEven'>Nagios Not Running</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_notrunning_string, percent_time_indeterminate_notrunning); printf("<td CLASS='dataEven'>Nagios Not Running</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_notrunning_string, percent_time_indeterminate_notrunning);
printf("<tr CLASS='dataEven'><td CLASS='dataEven'>Insufficient Data</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_nodata_string, percent_time_indeterminate_nodata); printf("<tr CLASS='dataEven'><td CLASS='dataEven'>Insufficient Data</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_nodata_string, percent_time_indeterminate_nodata);
printf("<tr CLASS='dataEven'><td CLASS='dataEven'>Total</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_string, percent_time_indeterminate); printf("<tr CLASS='dataEven'><td CLASS='dataEven'>Total</td><td CLASS='dataEven'>%s</td><td CLASS='dataEven'>%2.3f%%</td><td CLASS='dataEven'></td></tr>\n", time_indeterminate_string, percent_time_indeterminate);
@ -4626,8 +4565,6 @@ void display_service_availability(void) {
percent_time_critical_scheduled = 0.0; percent_time_critical_scheduled = 0.0;
percent_time_critical_unscheduled = 0.0; percent_time_critical_unscheduled = 0.0;
percent_time_indeterminate = 0.0; percent_time_indeterminate = 0.0;
percent_time_indeterminate_scheduled = 0.0;
percent_time_indeterminate_unscheduled = 0.0;
percent_time_indeterminate_notrunning = 0.0; percent_time_indeterminate_notrunning = 0.0;
percent_time_indeterminate_nodata = 0.0; percent_time_indeterminate_nodata = 0.0;
percent_time_ok_known = 0.0; percent_time_ok_known = 0.0;
@ -4648,7 +4585,7 @@ void display_service_availability(void) {
percent_time_ok_scheduled = (double)(((double)temp_subject->scheduled_time_ok * 100.0) / (double)total_time); percent_time_ok_scheduled = (double)(((double)temp_subject->scheduled_time_ok * 100.0) / (double)total_time);
percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled; percent_time_ok_unscheduled = percent_time_ok - percent_time_ok_scheduled;
percent_time_warning = (double)(((double)temp_subject->time_warning * 100.0) / (double)total_time); percent_time_warning = (double)(((double)temp_subject->time_warning * 100.0) / (double)total_time);
percent_time_warning_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time); percent_time_warning_scheduled = (double)(((double)temp_subject->scheduled_time_warning * 100.0) / (double)total_time);
percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled; percent_time_warning_unscheduled = percent_time_warning - percent_time_warning_scheduled;
percent_time_unknown = (double)(((double)temp_subject->time_unknown * 100.0) / (double)total_time); percent_time_unknown = (double)(((double)temp_subject->time_unknown * 100.0) / (double)total_time);
percent_time_unknown_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time); percent_time_unknown_scheduled = (double)(((double)temp_subject->scheduled_time_unknown * 100.0) / (double)total_time);
@ -4657,8 +4594,6 @@ void display_service_availability(void) {
percent_time_critical_scheduled = (double)(((double)temp_subject->scheduled_time_critical * 100.0) / (double)total_time); percent_time_critical_scheduled = (double)(((double)temp_subject->scheduled_time_critical * 100.0) / (double)total_time);
percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled; percent_time_critical_unscheduled = percent_time_critical - percent_time_critical_scheduled;
percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time); percent_time_indeterminate = (double)(((double)time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_scheduled = (double)(((double)temp_subject->scheduled_time_indeterminate * 100.0) / (double)total_time);
percent_time_indeterminate_unscheduled = percent_time_indeterminate - percent_time_indeterminate_scheduled;
percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time); percent_time_indeterminate_notrunning = (double)(((double)temp_subject->time_indeterminate_notrunning * 100.0) / (double)total_time);
percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time); percent_time_indeterminate_nodata = (double)(((double)temp_subject->time_indeterminate_nodata * 100.0) / (double)total_time);
if(time_determinate > 0) { if(time_determinate > 0) {
@ -4754,7 +4689,7 @@ void display_service_availability(void) {
void host_report_url(char *hn, char *label) { void host_report_url(const char *hn, const char *label) {
printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(hn)); printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(hn));
printf("&show_log_entries"); printf("&show_log_entries");
@ -4778,7 +4713,7 @@ void host_report_url(char *hn, char *label) {
} }
void service_report_url(char *hn, char *sd, char *label) { void service_report_url(const char *hn, const char *sd, const char *label) {
printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(hn)); printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(hn));
printf("&service=%s", url_encode(sd)); printf("&service=%s", url_encode(sd));
@ -4796,6 +4731,8 @@ void service_report_url(char *hn, char *sd, char *label) {
printf("&showscheduleddowntime=%s", (show_scheduled_downtime == TRUE) ? "yes" : "no"); printf("&showscheduleddowntime=%s", (show_scheduled_downtime == TRUE) ? "yes" : "no");
if(current_timeperiod != NULL) if(current_timeperiod != NULL)
printf("&rpttimeperiod=%s", url_encode(current_timeperiod->name)); printf("&rpttimeperiod=%s", url_encode(current_timeperiod->name));
if(include_soft_states == TRUE)
printf("&includesoftstates=%s", (include_soft_states == TRUE) ? "yes" : "no");
printf("'>%s</a>", label); printf("'>%s</a>", label);
return; return;
@ -4814,7 +4751,7 @@ void get_running_average(double *running_average, double new_value, int current_
/* used in reports where a timeperiod is selected */ /* used in reports where a timeperiod is selected */
unsigned long calculate_total_time(time_t start_time, time_t end_time) { unsigned long calculate_total_time(time_t start_time, time_t end_time) {
struct tm *t; struct tm *t;
unsigned long midnight_today; time_t midnight_today;
int weekday; int weekday;
unsigned long total_time; unsigned long total_time;
timerange *temp_timerange; timerange *temp_timerange;
@ -4835,7 +4772,7 @@ unsigned long calculate_total_time(time_t start_time, time_t end_time) {
t->tm_min = 0; t->tm_min = 0;
t->tm_hour = 0; t->tm_hour = 0;
t->tm_isdst = -1; t->tm_isdst = -1;
midnight_today = (unsigned long)mktime(t); midnight_today = mktime(t);
weekday = t->tm_wday; weekday = t->tm_wday;
total_time = 0; total_time = 0;

View File

@ -2,8 +2,6 @@
* *
* CGIAUTH.C - Authorization utilities for Nagios CGIs * CGIAUTH.C - Authorization utilities for Nagios CGIs
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 11-30-2008
* *
* License: * License:
* *
@ -31,9 +29,6 @@
extern char main_config_file[MAX_FILENAME_LENGTH]; extern char main_config_file[MAX_FILENAME_LENGTH];
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
extern int use_authentication; extern int use_authentication;
extern int use_ssl_authentication; extern int use_ssl_authentication;

View File

@ -2,9 +2,6 @@
* *
* CGIUTILS.C - Common utilities for Nagios CGIs * CGIUTILS.C - Common utilities for Nagios CGIs
* *
* Copyright (c) 2010 Nagios Core Development Team and Community Contributors
* Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-05-2010
* *
* License: * License:
* *
@ -28,6 +25,7 @@
#include "../include/objects.h" #include "../include/objects.h"
#include "../include/statusdata.h" #include "../include/statusdata.h"
#include "../include/downtime.h"
#include "../include/cgiutils.h" #include "../include/cgiutils.h"
char main_config_file[MAX_FILENAME_LENGTH]; char main_config_file[MAX_FILENAME_LENGTH];
@ -56,14 +54,11 @@ char *normal_sound = NULL;
char *statusmap_background_image = NULL; char *statusmap_background_image = NULL;
char *statuswrl_include = NULL; char *statuswrl_include = NULL;
char *illegal_output_chars = NULL;
char *notes_url_target = NULL; char *notes_url_target = NULL;
char *action_url_target = NULL; char *action_url_target = NULL;
char *ping_syntax = NULL; char *ping_syntax = NULL;
char nagios_check_command[MAX_INPUT_BUFFER] = "";
char nagios_process_info[MAX_INPUT_BUFFER] = ""; char nagios_process_info[MAX_INPUT_BUFFER] = "";
int nagios_process_state = STATE_OK; int nagios_process_state = STATE_OK;
@ -71,24 +66,12 @@ int enable_splunk_integration = FALSE;
char *splunk_url = NULL; char *splunk_url = NULL;
int lock_author_names = TRUE; int lock_author_names = TRUE;
extern time_t program_start; int navbar_search_addresses = TRUE;
extern int nagios_pid; int navbar_search_aliases = TRUE;
extern int daemon_mode;
extern int enable_notifications;
extern int execute_service_checks;
extern int accept_passive_service_checks;
extern int enable_event_handlers;
extern int obsess_over_services;
extern int enable_failure_prediction;
extern int process_performance_data;
extern time_t last_command_check;
extern time_t last_log_rotation;
int check_external_commands = 0; int ack_no_sticky = FALSE;
int ack_no_send = FALSE;
int date_format = DATE_FORMAT_US; int tac_cgi_hard_only = FALSE;
int log_rotation_method = LOG_ROTATION_NONE;
time_t this_scheduled_log_rotation = 0L; time_t this_scheduled_log_rotation = 0L;
time_t last_scheduled_log_rotation = 0L; time_t last_scheduled_log_rotation = 0L;
@ -96,8 +79,6 @@ time_t next_scheduled_log_rotation = 0L;
int use_authentication = TRUE; int use_authentication = TRUE;
int interval_length = 60;
int show_context_help = FALSE; int show_context_help = FALSE;
int use_pending_states = TRUE; int use_pending_states = TRUE;
@ -120,13 +101,6 @@ int color_transparency_index_r = 255;
int color_transparency_index_g = 255; int color_transparency_index_g = 255;
int color_transparency_index_b = 255; int color_transparency_index_b = 255;
extern hostgroup *hostgroup_list;
extern contactgroup *contactgroup_list;
extern command *command_list;
extern timeperiod *timeperiod_list;
extern contact *contact_list;
extern serviceescalation *serviceescalation_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
@ -135,15 +109,6 @@ lifo *lifo_list = NULL;
char encoded_url_string[2][MAX_INPUT_BUFFER]; // 2 to be able use url_encode twice char encoded_url_string[2][MAX_INPUT_BUFFER]; // 2 to be able use url_encode twice
char *encoded_html_string = NULL; char *encoded_html_string = NULL;
#ifdef HAVE_TZNAME
#ifdef CYGWIN
extern char *_tzname[2] __declspec(dllimport);
#else
extern char *tzname[2];
#endif
#endif
/* /*
* These function stubs allow us to compile a lot of the * These function stubs allow us to compile a lot of the
@ -160,6 +125,31 @@ int log_debug_info(int leve, int verbosity, const char *fmt, ...) {
return 0; return 0;
} }
/*** helpers ****/
/*
* find a command with arguments still attached
* if we're unsuccessful, the buffer pointed to by 'name' is modified
* to have only the real command name (everything up until the first '!')
*/
static command *find_bang_command(char *name)
{
char *bang;
command *cmd;
if (!name)
return NULL;
bang = strchr(name, '!');
if (!bang)
return find_command(name);
*bang = 0;
cmd = find_command(name);
*bang = '!';
return cmd;
}
/********************************************************** /**********************************************************
***************** CLEANUP FUNCTIONS ********************** ***************** CLEANUP FUNCTIONS **********************
**********************************************************/ **********************************************************/
@ -186,7 +176,6 @@ void reset_cgi_vars(void) {
strcat(log_archive_path, "/"); strcat(log_archive_path, "/");
strcpy(command_file, get_cmd_file_location()); strcpy(command_file, get_cmd_file_location());
strcpy(nagios_check_command, "");
strcpy(nagios_process_info, ""); strcpy(nagios_process_info, "");
nagios_process_state = STATE_OK; nagios_process_state = STATE_OK;
@ -252,7 +241,7 @@ void free_memory(void) {
**********************************************************/ **********************************************************/
/* read the CGI config file location from an environment variable */ /* read the CGI config file location from an environment variable */
char * get_cgi_config_location(void) { const char *get_cgi_config_location(void) {
static char *cgiloc = NULL; static char *cgiloc = NULL;
if(!cgiloc) { if(!cgiloc) {
@ -266,7 +255,7 @@ char * get_cgi_config_location(void) {
/* read the command file location from an environment variable */ /* read the command file location from an environment variable */
char * get_cmd_file_location(void) { const char *get_cmd_file_location(void) {
static char *cmdloc = NULL; static char *cmdloc = NULL;
if(!cmdloc) { if(!cmdloc) {
@ -279,11 +268,12 @@ char * get_cmd_file_location(void) {
/*read the CGI configuration file */ /*read the CGI configuration file */
int read_cgi_config_file(char *filename) { int read_cgi_config_file(const char *filename) {
char *input = NULL; char *input = NULL;
mmapfile *thefile; mmapfile *thefile;
char *var = NULL; char *var = NULL;
char *val = NULL; char *val = NULL;
char *p = NULL;
if((thefile = mmap_fopen(filename)) == NULL) if((thefile = mmap_fopen(filename)) == NULL)
@ -321,12 +311,6 @@ int read_cgi_config_file(char *filename) {
else if(!strcmp(var, "use_authentication")) else if(!strcmp(var, "use_authentication"))
use_authentication = (atoi(val) > 0) ? TRUE : FALSE; use_authentication = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "nagios_check_command")) {
strncpy(nagios_check_command, val, sizeof(nagios_check_command));
nagios_check_command[sizeof(nagios_check_command) - 1] = '\x0';
strip(nagios_check_command);
}
else if(!strcmp(var, "refresh_rate")) else if(!strcmp(var, "refresh_rate"))
refresh_rate = atoi(val); refresh_rate = atoi(val);
@ -446,8 +430,23 @@ int read_cgi_config_file(char *filename) {
else if(!strcmp(var, "use_ssl_authentication")) else if(!strcmp(var, "use_ssl_authentication"))
use_ssl_authentication = (atoi(val) > 0) ? TRUE : FALSE; use_ssl_authentication = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "navbar_search_addresses"))
navbar_search_addresses = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "navbar_search_aliases"))
navbar_search_aliases = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "ack_no_sticky"))
ack_no_sticky = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "ack_no_send"))
ack_no_send = (atoi(val) > 0) ? TRUE : FALSE;
else if(!strcmp(var, "tac_cgi_hard_only"))
tac_cgi_hard_only = (atoi(val) > 0) ? TRUE : FALSE;
} }
for(p = illegal_output_chars; p && *p; p++)
illegal_output_char_map[(int)*p] = 1;
/* free memory and close the file */ /* free memory and close the file */
free(input); free(input);
mmap_fclose(thefile); mmap_fclose(thefile);
@ -461,11 +460,12 @@ int read_cgi_config_file(char *filename) {
/* read the main configuration file */ /* read the main configuration file */
int read_main_config_file(char *filename) { int read_main_config_file(const char *filename) {
char *input = NULL; char *input = NULL;
char *temp_buffer; char *temp_buffer;
mmapfile *thefile; mmapfile *thefile;
config_file_dir = nspath_absolute_dirname(filename, NULL);
if((thefile = mmap_fopen(filename)) == NULL) if((thefile = mmap_fopen(filename)) == NULL)
return ERROR; return ERROR;
@ -490,11 +490,22 @@ int read_main_config_file(char *filename) {
else if(strstr(input, "log_file=") == input) { else if(strstr(input, "log_file=") == input) {
temp_buffer = strtok(input, "="); temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0"); temp_buffer = strtok(NULL, "\x0");
strncpy(log_file, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(log_file)); strncpy(log_file, (temp_buffer == NULL) ? "" : nspath_absolute(temp_buffer, config_file_dir),sizeof(log_file) - 1);
log_file[sizeof(log_file) - 1] = '\x0'; log_file[sizeof(log_file) - 1] = '\x0';
strip(log_file); strip(log_file);
} }
else if(strstr(input, "object_cache_file=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
object_cache_file = nspath_absolute(temp_buffer, config_file_dir);
}
else if(strstr(input, "status_file=") == input) {
temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\x0");
status_file = nspath_absolute(temp_buffer, config_file_dir);
}
else if(strstr(input, "log_archive_path=") == input) { else if(strstr(input, "log_archive_path=") == input) {
temp_buffer = strtok(input, "="); temp_buffer = strtok(input, "=");
temp_buffer = strtok(NULL, "\n"); temp_buffer = strtok(NULL, "\n");
@ -560,18 +571,90 @@ int read_main_config_file(char *filename) {
/* read all object definitions */ /* read all object definitions */
int read_all_object_configuration_data(char *config_file, int options) { int read_all_object_configuration_data(const char *cfgfile, int options) {
int result = OK; int result = OK;
host *temp_host = NULL;
host *parent_host = NULL;
hostsmember *temp_hostsmember = NULL;
service *temp_service = NULL;
service *parent_service = NULL;
servicesmember *temp_servicesmember = NULL;
/* read in all external config data of the desired type(s) */ /* read in all external config data of the desired type(s) */
result = read_object_config_data(config_file, options, FALSE, FALSE); result = read_object_config_data(cfgfile, options);
/* Resolve objects in the host object */
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {
/* Find the command object for the check command */
temp_host->check_command_ptr =
find_bang_command(temp_host->check_command);
/* Find the command object for the event handler */
temp_host->event_handler_ptr =
find_bang_command(temp_host->event_handler);
/* Resolve host child->parent relationships */
for(temp_hostsmember = temp_host->parent_hosts;
temp_hostsmember != NULL;
temp_hostsmember = temp_hostsmember->next) {
if((parent_host = find_host(temp_hostsmember->host_name)) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE,
"Error: '%s' is not a valid parent for host '%s'!",
temp_hostsmember->host_name, temp_host->name);
}
/* save the parent host pointer for later */
temp_hostsmember->host_ptr = parent_host;
/* add a reverse (child) link to make searches faster later on */
if(add_child_link_to_host(parent_host, temp_host) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE,
"Error: Failed to add '%s' as a child host of '%s'",
temp_host->name, parent_host->name);
}
}
}
/* Resolve objects in the service object */
for(temp_service = service_list; temp_service != NULL;
temp_service = temp_service->next) {
/* Find the command object for the check command */
temp_service->check_command_ptr =
find_bang_command(temp_service->check_command);
/* Find the command object for the event handler */
temp_service->event_handler_ptr =
find_bang_command(temp_service->event_handler);
/* Resolve service child->parent relationships */
for(temp_servicesmember = temp_service->parents;
temp_servicesmember != NULL;
temp_servicesmember = temp_servicesmember->next) {
/* Find the parent service */
if((parent_service = find_service(temp_servicesmember->host_name,
temp_servicesmember->service_description)) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE,
"Error: '%s:%s' is not a valid parent for service '%s:%s'!",
temp_servicesmember->host_name,
temp_servicesmember->service_description,
temp_service->host_name, temp_service->description);
}
/* add a reverse (child) link to make searches faster later on */
if(add_child_link_to_service(parent_service,
temp_service) == NULL) {
logit(NSLOG_CONFIG_ERROR, TRUE,
"Error: Failed to add '%s:%s' as a child service of '%s:%s'",
temp_service->host_name, temp_service->description,
parent_service->host_name, parent_service->description);
}
}
}
return result; return result;
} }
/* read all status data */ /* read all status data */
int read_all_status_data(char *config_file, int options) { int read_all_status_data(const char *status_file_name, int options) {
int result = OK; int result = OK;
/* don't duplicate things we've already read in */ /* don't duplicate things we've already read in */
@ -586,8 +669,11 @@ int read_all_status_data(char *config_file, int options) {
if(options <= 0) if(options <= 0)
return OK; return OK;
/* Initialize the downtime data */
initialize_downtime_data();
/* read in all external status data */ /* read in all external status data */
result = read_status_data(config_file, options); result = read_status_data(status_file_name, options);
/* mark what items we've read in... */ /* mark what items we've read in... */
if(options & READ_PROGRAM_STATUS) if(options & READ_PROGRAM_STATUS)
@ -601,6 +687,51 @@ int read_all_status_data(char *config_file, int options) {
} }
void cgi_init(void (*doc_header)(int), void (*doc_footer)(void), int object_options, int status_options) {
int result;
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
doc_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
doc_footer();
exit(EXIT_FAILURE);
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
doc_header(FALSE);
main_config_file_error(main_config_file);
doc_footer();
exit(EXIT_FAILURE);
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, object_options);
if(result == ERROR) {
doc_header(FALSE);
object_data_error();
doc_footer();
exit(EXIT_FAILURE);
}
/* read all status data */
result = read_all_status_data(status_file, status_options);
if(result == ERROR) {
doc_header(FALSE);
status_data_error();
doc_footer();
free_memory();
exit(EXIT_FAILURE);
}
}
/********************************************************** /**********************************************************
******************* LIFO FUNCTIONS *********************** ******************* LIFO FUNCTIONS ***********************
**********************************************************/ **********************************************************/
@ -727,7 +858,7 @@ char *unescape_newlines(char *rawbuf) {
} }
/* unescape backslashes and other stuff */ /* unescape backslashes and other stuff */
if(rawbuf[x + 1] != '\x0') { else if(rawbuf[x + 1] != '\x0') {
rawbuf[y++] = rawbuf[x + 1]; rawbuf[y++] = rawbuf[x + 1];
x++; x++;
} }
@ -816,9 +947,9 @@ void get_time_string(time_t *raw_time, char *buffer, int buffer_length, int type
int month = 0; int month = 0;
int day = 0; int day = 0;
int year = 0; int year = 0;
char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; const char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *tzone = ""; const char *tzone = "";
if(raw_time == NULL) if(raw_time == NULL)
time(&t); time(&t);
@ -902,7 +1033,7 @@ void get_interval_time_string(double time_units, char *buffer, int buffer_length
/* encodes a string in proper URL format */ /* encodes a string in proper URL format */
char *url_encode(char *input) { const char *url_encode(const char *input) {
int len, output_len; int len, output_len;
int x, y; int x, y;
char temp_expansion[4]; char temp_expansion[4];
@ -916,7 +1047,7 @@ char *url_encode(char *input) {
return str; return str;
len = (int)strlen(input); len = (int)strlen(input);
output_len = (int)sizeof(encoded_url_string[0]); output_len = (int)sizeof(encoded_url_string[i]);
str[0] = '\x0'; str[0] = '\x0';
@ -944,19 +1075,57 @@ char *url_encode(char *input) {
else { else {
str[y] = '\x0'; str[y] = '\x0';
if((int)strlen(str) < (output_len - 3)) { if((int)strlen(str) < (output_len - 3)) {
sprintf(temp_expansion, "%%%02X", (unsigned char)input[x]); sprintf(temp_expansion, "%%%02X", (unsigned int)(input[x] & 0xFF));
strcat(str, temp_expansion); strcat(str, temp_expansion);
y += 3; y += 3;
} }
} }
} }
str[sizeof(encoded_url_string[0]) - 1] = '\x0'; str[sizeof(encoded_url_string[i]) - 1] = '\x0';
i = !i;
return str; return str;
} }
static char * copy_wc_to_output(wchar_t wc, char *outstp, int output_max) {
int wctomb_result;
char mbtemp[ 10];
wctomb_result = wctomb(mbtemp, wc);
if(( wctomb_result > 0) &&
((( outstp - encoded_html_string) + wctomb_result) < output_max)) {
strncpy( outstp, mbtemp, wctomb_result);
outstp += wctomb_result;
}
return outstp;
}
static char * encode_character(wchar_t wc, char *outstp, int output_max) {
char temp_expansion[11];
sprintf(temp_expansion, "&#%u;", (unsigned int)wc);
if(((outstp - encoded_html_string) + strlen(temp_expansion)) <
(unsigned int)output_max) {
strncpy(outstp, temp_expansion, strlen( temp_expansion));
outstp += strlen( temp_expansion);
}
return outstp;
}
#define WHERE_OUTSIDE_TAG 0 /* Not in an HTML tag */
#define WHERE_IN_TAG_NAME 1 /* In HTML tag name (either opening
or closing tag) */
#define WHERE_IN_TAG_OUTSIDE_ATTRIBUTE 2 /* In HTML tag, but before or after
an attribute. Should be <, > or
space */
#define WHERE_IN_TAG_IN_ATTRIBUTE_NAME 3 /* In the attribute name */
#define WHERE_IN_TAG_AT_EQUALS 4 /* At the equals sign between the
attribute name and value */
#define WHERE_IN_TAG_IN_ATTRIBUTE_VALUE 5 /* In the attribute value */
#define WHERE_IN_COMMENT 6 /* In an HTML comment */
/* escapes a string used in HTML */ /* escapes a string used in HTML */
char * html_encode(char *input, int escape_newlines) { char * html_encode(char *input, int escape_newlines) {
@ -965,114 +1134,206 @@ char * html_encode(char *input, int escape_newlines) {
char *outstp; char *outstp;
wchar_t *wcinput; wchar_t *wcinput;
wchar_t *inwcp; wchar_t *inwcp;
wchar_t *tagname = L"";
size_t mbstowcs_result; size_t mbstowcs_result;
char mbtemp[ 10];
int wctomb_result;
int x; int x;
char temp_expansion[10]; int where_in_tag = WHERE_OUTSIDE_TAG; /* Location in HTML tag */
wchar_t attr_value_start = (wchar_t)0; /* character that starts the
attribute value */
int tag_depth = 0; /* depth of nested HTML tags */
/* we need up to six times the space to do the conversion */ /* we need up to six times the space to do the conversion */
len = (int)strlen(input); len = (int)strlen(input);
output_max = len * 6; output_max = len * 6;
if((outstp = encoded_html_string = (char *)malloc(output_max + 1)) == NULL) if(( outstp = encoded_html_string = (char *)malloc(output_max + 1)) == NULL)
return ""; return "";
strcpy(encoded_html_string, ""); strcpy(encoded_html_string, "");
/* Convert the string to a wide character string */ /* Convert the string to a wide character string */
if((wcinput = malloc(len * sizeof(wchar_t))) == NULL) { if(( wcinput = malloc( len * sizeof( wchar_t))) == NULL) {
return ""; return "";
} }
if((mbstowcs_result = mbstowcs(wcinput, input, len)) < 0) { if((mbstowcs_result = mbstowcs( wcinput, input, len)) == (size_t)-1) {
free(wcinput); free( wcinput);
return ""; return "";
} }
/* Process all converted characters */ /* Process all converted characters */
for(x = 0, inwcp = wcinput; x < mbstowcs_result && '\0' != *inwcp; x++, inwcp++) { for( x = 0, inwcp = wcinput; x < (int)mbstowcs_result && '\0' != *inwcp;
x++, inwcp++) {
/* Most ASCII characters don't get encoded */ /* Most ASCII characters don't get encoded */
if((*inwcp >= 0x20 && *inwcp <= 0x7e) && if(( *inwcp >= 0x20 && *inwcp <= 0x7e) &&
(!('"' == *inwcp || '&' == *inwcp || '\'' == *inwcp || ( !( '"' == *inwcp || '&' == *inwcp || '\'' == *inwcp ||
'<' == *inwcp || '>' == *inwcp))) { '<' == *inwcp || '>' == *inwcp))) {
wctomb_result = wctomb(mbtemp, *inwcp); outstp = copy_wc_to_output(*inwcp, outstp, output_max);
if((wctomb_result > 0) && switch(where_in_tag) {
(((outstp - encoded_html_string) + wctomb_result) < output_max)) { case WHERE_IN_TAG_NAME:
strncpy(outstp, mbtemp, wctomb_result); switch(*inwcp) {
outstp += wctomb_result; case 0x20:
where_in_tag = WHERE_IN_TAG_OUTSIDE_ATTRIBUTE;
*inwcp = 0;
break;
case '!':
where_in_tag = WHERE_IN_COMMENT;
break;
}
break;
case WHERE_IN_TAG_OUTSIDE_ATTRIBUTE:
if(*inwcp != 0x20) {
where_in_tag = WHERE_IN_TAG_IN_ATTRIBUTE_NAME;
}
break;
case WHERE_IN_TAG_IN_ATTRIBUTE_NAME:
if(*inwcp == '=') {
where_in_tag = WHERE_IN_TAG_AT_EQUALS;
}
break;
case WHERE_IN_TAG_AT_EQUALS:
if(*inwcp != 0x20) {
attr_value_start = *inwcp;
where_in_tag = WHERE_IN_TAG_IN_ATTRIBUTE_VALUE;
}
break;
case WHERE_IN_TAG_IN_ATTRIBUTE_VALUE:
if((*inwcp == 0x20) && (attr_value_start != '"') &&
(attr_value_start != '\'')) {
where_in_tag = WHERE_IN_TAG_OUTSIDE_ATTRIBUTE;
}
break;
}
}
/* Special handling for quotes */
else if(FALSE == escape_html_tags &&
('"' == *inwcp || '\'' == *inwcp)) {
switch(where_in_tag) {
case WHERE_OUTSIDE_TAG:
if(tag_depth >0) {
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
}
else {
outstp = encode_character(*inwcp, outstp, output_max);
}
break;
case WHERE_IN_COMMENT:
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
break;
case WHERE_IN_TAG_AT_EQUALS:
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
attr_value_start = *inwcp;
where_in_tag = WHERE_IN_TAG_IN_ATTRIBUTE_VALUE;
break;
case WHERE_IN_TAG_IN_ATTRIBUTE_VALUE:
if(*(inwcp-1) == '\\') {
/* This covers the case where the quote is backslash
escaped. */
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
}
else if(attr_value_start == *inwcp) {
/* If the quote is the same type of quote that started
the attribute value and it is not backslash
escaped, it signals the end of the attribute value */
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
where_in_tag = WHERE_IN_TAG_OUTSIDE_ATTRIBUTE;
}
else {
/* If we encounter an quote that did not start the
attribute value and is not backslash escaped,
use it as is */
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
}
break;
default:
if (tag_depth > 0 && !wcscmp(tagname, L"script"))
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
else
outstp = encode_character(*inwcp, outstp, output_max);
break;
} }
} }
/* newlines turn to <BR> tags */ /* newlines turn to <BR> tags */
else if(escape_newlines == TRUE && '\n' == *inwcp) { else if(escape_newlines == TRUE && '\n' == *inwcp) {
strncpy(outstp, "<BR>", 4); strncpy( outstp, "<BR>", 4);
outstp += 4; outstp += 4;
} }
else if(escape_newlines == TRUE && '\\' == *inwcp && '\n' == *(inwcp + 1)) { else if(escape_newlines == TRUE && '\\' == *inwcp && '\n' == *( inwcp + 1)) {
strncpy(outstp, "<BR>", 4); strncpy( outstp, "<BR>", 4);
outstp += 4; outstp += 4;
inwcp++; /* needed so loop skips two wide characters */ inwcp++; /* needed so loop skips two wide characters */
} }
/* TODO - strip all but allowed HTML tags out... */ /* TODO - strip all but allowed HTML tags out... */
else if(('<' == *inwcp) && (FALSE == escape_html_tags)) {
else if('<' == *inwcp) { switch(where_in_tag) {
case WHERE_OUTSIDE_TAG:
if(escape_html_tags == FALSE) { outstp = copy_wc_to_output(*inwcp, outstp, output_max);
wctomb_result = wctomb(mbtemp, *inwcp); where_in_tag = WHERE_IN_TAG_NAME;
if((wctomb_result > 0) && switch(*(inwcp+1)) {
(((outstp - encoded_html_string) + wctomb_result) < output_max)) { case '/':
strncpy(outstp, mbtemp, wctomb_result); tag_depth--;
outstp += wctomb_result; break;
} case '!':
} break;
else { default:
if(((outstp - encoded_html_string) + 4) < output_max) { tag_depth++;
strncpy(outstp, "&lt;", 4); tagname = inwcp + 1;
outstp += 4; break;
} }
break;
default:
if (tag_depth > 0 && !wcscmp(tagname, L"script"))
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
else
outstp = encode_character(*inwcp, outstp, output_max);
break;
} }
} }
else if('>' == *inwcp) { else if(('>' == *inwcp) && (FALSE == escape_html_tags)) {
if(escape_html_tags == FALSE) { switch(where_in_tag) {
wctomb_result = wctomb(mbtemp, *inwcp); case WHERE_IN_TAG_NAME:
if((wctomb_result > 0) && case WHERE_IN_TAG_OUTSIDE_ATTRIBUTE:
(((outstp - encoded_html_string) + wctomb_result) < output_max)) { case WHERE_IN_COMMENT:
strncpy(outstp, mbtemp, wctomb_result); case WHERE_IN_TAG_IN_ATTRIBUTE_NAME:
outstp += wctomb_result; outstp = copy_wc_to_output(*inwcp, outstp, output_max);
where_in_tag = WHERE_OUTSIDE_TAG;
*inwcp = 0;
break;
case WHERE_IN_TAG_IN_ATTRIBUTE_VALUE:
if((attr_value_start != '"') && (attr_value_start != '\'')) {
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
where_in_tag = WHERE_OUTSIDE_TAG;
} }
} else {
else { outstp = encode_character(*inwcp, outstp, output_max);
if(((outstp - encoded_html_string) + 4) < output_max) {
strncpy(outstp, "&gt;", 4);
outstp += 4;
} }
break;
default:
if (tag_depth > 0 && !wcscmp(tagname, L"script"))
outstp = copy_wc_to_output(*inwcp, outstp, output_max);
else
outstp = encode_character(*inwcp, outstp, output_max);
break;
} }
} }
/* When not escaping HTML tags, don't encode quotes or ampersands /* check_multi puts out a '&ndash' so don't encode the '&' in that case */
(left and right carets are handled above */ else if (*inwcp == '&' && escape_html_tags == FALSE) {
else if((escape_html_tags == FALSE) && ('"' == *inwcp || if (tag_depth > 0 && !wcsncmp(inwcp, L"&ndash", 6))
'&' == *inwcp || '\'' == *inwcp)) { outstp = copy_wc_to_output(*inwcp, outstp, output_max);
wctomb_result = wctomb(mbtemp, *inwcp); else
if((wctomb_result > 0) && outstp = encode_character(*inwcp, outstp, output_max);
(((outstp - encoded_html_string) + wctomb_result) < output_max)) {
strncpy(outstp, mbtemp, wctomb_result);
outstp += wctomb_result;
}
} }
/* for simplicity, all other chars represented by their numeric value */ /* for simplicity, all other chars represented by their numeric value */
else { else {
sprintf(temp_expansion, "&#%u;", *(unsigned int *)inwcp); outstp = encode_character(*inwcp, outstp, output_max);
if(((outstp - encoded_html_string) + strlen(temp_expansion)) <
output_max) {
strncpy(outstp, temp_expansion, strlen(temp_expansion));
outstp += strlen(temp_expansion);
}
} }
} }
@ -1094,7 +1355,7 @@ void strip_html_brackets(char *buffer) {
if(buffer == NULL || buffer[0] == '\x0') if(buffer == NULL || buffer[0] == '\x0')
return; return;
/* remove all occurances in string */ /* remove all occurrences in string */
z = (int)strlen(buffer); z = (int)strlen(buffer);
for(x = 0, y = 0; x < z; x++) { for(x = 0, y = 0; x < z; x++) {
if(buffer[x] == '<' || buffer[x] == '>') if(buffer[x] == '<' || buffer[x] == '>')
@ -1108,7 +1369,7 @@ void strip_html_brackets(char *buffer) {
/* escape string for html form usage */ /* escape string for html form usage */
char *escape_string(char *input) { char *escape_string(const char *input) {
int len; int len;
int output_max; int output_max;
wchar_t wctemp[1]; wchar_t wctemp[1];
@ -1116,49 +1377,49 @@ char *escape_string(char *input) {
char mbtemp[ 10]; char mbtemp[ 10];
int wctomb_result; int wctomb_result;
char *stp; char *stp;
char temp_expansion[10]; char temp_expansion[11];
/* If they don't give us anything to do... */ /* If they don't give us anything to do... */
if(NULL == input) { if( NULL == input) {
return ""; return "";
} }
/* We need up to six times the space to do the conversion */ /* We need up to six times the space to do the conversion */
len = (int)strlen(input); len = (int)strlen(input);
output_max = len * 6; output_max = len * 6;
if((stp = encoded_html_string = (char *)malloc(output_max + 1)) == NULL) if(( stp = encoded_html_string = (char *)malloc(output_max + 1)) == NULL)
return ""; return "";
strcpy(encoded_html_string, ""); strcpy(encoded_html_string, "");
/* Get the first multibyte character in the input string */ /* Get the first multibyte character in the input string */
mbtowc_result = mbtowc(wctemp, input, MB_CUR_MAX); mbtowc_result = mbtowc( wctemp, input, MB_CUR_MAX);
/* Process all characters until a null character is found */ /* Process all characters until a null character is found */
while(0 != mbtowc_result) { /* 0 indicates a null character was found */ while( 0 != mbtowc_result) { /* 0 indicates a null character was found */
if((size_t) - 2 == mbtowc_result) { if(( size_t)-2 == mbtowc_result) {
/* No complete multibyte character found - try at next memory /* No complete multibyte character found - try at next memory
address */ address */
input++; input++;
} }
else if(((size_t) - 1 == mbtowc_result) && (EILSEQ == errno)) { else if((( size_t)-1 == mbtowc_result) && ( EILSEQ == errno)) {
/* Invalid multibyte character found - try at next memory address */ /* Invalid multibyte character found - try at next memory address */
input++; input++;
} }
/* Alpha-numeric characters and a few other characters don't get /* Alpha-numeric characters and a few other characters don't get
encoded */ encoded */
else if((*wctemp >= '0' && *wctemp <= '9') || else if(( *wctemp >= '0' && *wctemp <= '9') ||
(*wctemp >= 'A' && *wctemp <= 'Z') || ( *wctemp >= 'A' && *wctemp <= 'Z') ||
(*wctemp >= 'a' && *wctemp <= 'z') || ( *wctemp >= 'a' && *wctemp <= 'z') ||
' ' == *wctemp || '-' == *wctemp || '.' == *wctemp || ' ' == *wctemp || '-' == *wctemp || '.' == *wctemp ||
'_' == *wctemp || ':' == *wctemp) { '_' == *wctemp || ':' == *wctemp) {
wctomb_result = wctomb(mbtemp, wctemp[0]); wctomb_result = wctomb( mbtemp, wctemp[0]);
if((wctomb_result > 0) && if(( wctomb_result > 0) &&
(((stp - encoded_html_string) + wctomb_result) < output_max)) { ((( stp - encoded_html_string) + wctomb_result) < output_max)) {
strncpy(stp, mbtemp, wctomb_result); strncpy( stp, mbtemp, wctomb_result);
stp += wctomb_result; stp += wctomb_result;
} }
input += mbtowc_result; input += mbtowc_result;
@ -1166,17 +1427,17 @@ char *escape_string(char *input) {
/* Encode everything else (this may be excessive) */ /* Encode everything else (this may be excessive) */
else { else {
sprintf(temp_expansion, "&#%u;", (unsigned int)wctemp[ 0]); sprintf( temp_expansion, "&#%u;", ( unsigned int)wctemp[ 0]);
if(((stp - encoded_html_string) + strlen(temp_expansion)) < if((( stp - encoded_html_string) + strlen( temp_expansion)) <
output_max) { (unsigned int)output_max) {
strncpy(stp, temp_expansion, strlen(temp_expansion)); strncpy( stp, temp_expansion, strlen( temp_expansion));
stp += strlen(temp_expansion); stp += strlen( temp_expansion);
} }
input += mbtowc_result; input += mbtowc_result;
} }
/* Read the next character */ /* Read the next character */
mbtowc_result = mbtowc(wctemp, input, MB_CUR_MAX); mbtowc_result = mbtowc( wctemp, input, MB_CUR_MAX);
} }
/* Null terminate the encoded string */ /* Null terminate the encoded string */
@ -1348,13 +1609,13 @@ void determine_log_rotation_times(int archive) {
*************** COMMON HTML FUNCTIONS ******************** *************** COMMON HTML FUNCTIONS ********************
**********************************************************/ **********************************************************/
void display_info_table(char *title, int refresh, authdata *current_authdata) { void display_info_table(const char *title, int refresh, authdata *current_authdata) {
time_t current_time; time_t current_time;
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
int result; int result;
/* read program status */ /* read program status */
result = read_all_status_data(get_cgi_config_location(), READ_PROGRAM_STATUS); result = read_all_status_data(status_file, READ_PROGRAM_STATUS);
printf("<TABLE CLASS='infoBox' BORDER=1 CELLSPACING=0 CELLPADDING=0>\n"); printf("<TABLE CLASS='infoBox' BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
printf("<TR><TD CLASS='infoBox'>\n"); printf("<TR><TD CLASS='infoBox'>\n");
@ -1367,7 +1628,7 @@ void display_info_table(char *title, int refresh, authdata *current_authdata) {
if(refresh == TRUE) if(refresh == TRUE)
printf("Updated every %d seconds<br>\n", refresh_rate); printf("Updated every %d seconds<br>\n", refresh_rate);
printf("Nagios&reg; Core&trade; %s - <A HREF='http://www.nagios.org' TARGET='_new' CLASS='homepageURL'>www.nagios.org</A><BR>\n", PROGRAM_VERSION); printf("Nagios&reg; Core&trade; %s - <A HREF='https://www.nagios.org' TARGET='_new' CLASS='homepageURL'>www.nagios.org</A><BR>\n", PROGRAM_VERSION);
if(current_authdata != NULL) if(current_authdata != NULL)
printf("Logged in as <i>%s</i><BR>\n", (!strcmp(current_authdata->username, "")) ? "?" : current_authdata->username); printf("Logged in as <i>%s</i><BR>\n", (!strcmp(current_authdata->username, "")) ? "?" : current_authdata->username);
@ -1563,12 +1824,11 @@ void print_extra_servicegroup_url(char *group_name, char *url) {
/* include user-defined SSI footers or headers */ /* include user-defined SSI footers or headers */
void include_ssi_files(char *cgi_name, int type) { void include_ssi_files(const char *cgi_name, int type) {
char common_ssi_file[MAX_INPUT_BUFFER]; char common_ssi_file[MAX_INPUT_BUFFER];
char cgi_ssi_file[MAX_INPUT_BUFFER]; char cgi_ssi_file[MAX_INPUT_BUFFER];
char raw_cgi_name[MAX_INPUT_BUFFER]; char raw_cgi_name[MAX_INPUT_BUFFER];
char *stripped_cgi_name; char *stripped_cgi_name;
int x;
/* common header or footer */ /* common header or footer */
snprintf(common_ssi_file, sizeof(common_ssi_file) - 1, "%scommon-%s.ssi", physical_ssi_path, (type == SSI_HEADER) ? "header" : "footer"); snprintf(common_ssi_file, sizeof(common_ssi_file) - 1, "%scommon-%s.ssi", physical_ssi_path, (type == SSI_HEADER) ? "header" : "footer");
@ -1582,14 +1842,14 @@ void include_ssi_files(char *cgi_name, int type) {
cgi_ssi_file[sizeof(cgi_ssi_file) - 1] = '\x0'; cgi_ssi_file[sizeof(cgi_ssi_file) - 1] = '\x0';
if(type == SSI_HEADER) { if(type == SSI_HEADER) {
printf("\n<!-- Produced by Nagios (http://www.nagios.org). Copyright (c) 1999-2007 Ethan Galstad. -->\n"); printf("\n<!-- Produced by Nagios (https://www.nagios.org). Copyright (c) 1999-2007 Ethan Galstad. -->\n");
include_ssi_file(common_ssi_file); include_ssi_file(common_ssi_file);
include_ssi_file(cgi_ssi_file); include_ssi_file(cgi_ssi_file);
} }
else { else {
include_ssi_file(cgi_ssi_file); include_ssi_file(cgi_ssi_file);
include_ssi_file(common_ssi_file); include_ssi_file(common_ssi_file);
printf("\n<!-- Produced by Nagios (http://www.nagios.org). Copyright (c) 1999-2007 Ethan Galstad. -->\n"); printf("\n<!-- Produced by Nagios (https://www.nagios.org). Copyright (c) 1999-2007 Ethan Galstad. -->\n");
} }
return; return;
@ -1598,7 +1858,7 @@ void include_ssi_files(char *cgi_name, int type) {
/* include user-defined SSI footer or header */ /* include user-defined SSI footer or header */
void include_ssi_file(char *filename) { void include_ssi_file(const char *filename) {
char buffer[MAX_INPUT_BUFFER]; char buffer[MAX_INPUT_BUFFER];
FILE *fp; FILE *fp;
struct stat stat_result; struct stat stat_result;
@ -1660,7 +1920,7 @@ void include_ssi_file(char *filename) {
/* displays an error if CGI config file could not be read */ /* displays an error if CGI config file could not be read */
void cgi_config_file_error(char *config_file) { void cgi_config_file_error(const char *config_file) {
printf("<H1>Whoops!</H1>\n"); printf("<H1>Whoops!</H1>\n");
@ -1680,7 +1940,7 @@ void cgi_config_file_error(char *config_file) {
printf("</P>\n"); printf("</P>\n");
printf("<P>\n"); printf("<P>\n");
printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='http://www.nagios.org'>http://www.nagios.org</a>.\n"); printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='https://www.nagios.org'>https://www.nagios.org</a>.\n");
printf("</P>\n"); printf("</P>\n");
return; return;
@ -1689,7 +1949,7 @@ void cgi_config_file_error(char *config_file) {
/* displays an error if main config file could not be read */ /* displays an error if main config file could not be read */
void main_config_file_error(char *config_file) { void main_config_file_error(const char *config_file) {
printf("<H1>Whoops!</H1>\n"); printf("<H1>Whoops!</H1>\n");
@ -1709,7 +1969,7 @@ void main_config_file_error(char *config_file) {
printf("</P>\n"); printf("</P>\n");
printf("<P>\n"); printf("<P>\n");
printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='http://www.nagios.org'>http://www.nagios.org</a>.\n"); printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='https://www.nagios.org'>https://www.nagios.org</a>.\n");
printf("</P>\n"); printf("</P>\n");
return; return;
@ -1737,7 +1997,7 @@ void object_data_error(void) {
printf("</P>\n"); printf("</P>\n");
printf("<P>\n"); printf("<P>\n");
printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='http://www.nagios.org'>http://www.nagios.org</a>.\n"); printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='https://www.nagios.org'>https://www.nagios.org</a>.\n");
printf("</P>\n"); printf("</P>\n");
return; return;
@ -1769,7 +2029,7 @@ void status_data_error(void) {
printf("</P>\n"); printf("</P>\n");
printf("<P>\n"); printf("<P>\n");
printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='http://www.nagios.org'>http://www.nagios.org</a>.\n"); printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at <a href='https://www.nagios.org'>https://www.nagios.org</a>.\n");
printf("</P>\n"); printf("</P>\n");
return; return;
@ -1779,8 +2039,8 @@ void status_data_error(void) {
/* displays context-sensitive help window */ /* displays context-sensitive help window */
void display_context_help(char *chid) { void display_context_help(const char *chid) {
char *icon = CONTEXT_HELP_ICON1; const char *icon = CONTEXT_HELP_ICON1;
if(show_context_help == FALSE) if(show_context_help == FALSE)
return; return;
@ -1858,7 +2118,7 @@ void strip_splunk_query_terms(char *buffer) {
if(buffer == NULL || buffer[0] == '\x0') if(buffer == NULL || buffer[0] == '\x0')
return; return;
/* remove all occurances in string */ /* remove all occurrences in string */
z = (int)strlen(buffer); z = (int)strlen(buffer);
for(x = 0, y = 0; x < z; x++) { for(x = 0, y = 0; x < z; x++) {
if(buffer[x] == '\'' || buffer[x] == '\"' || buffer[x] == ';' || buffer[x] == ':' || buffer[x] == ',' || buffer[x] == '-' || buffer[x] == '=') if(buffer[x] == '\'' || buffer[x] == '\"' || buffer[x] == ';' || buffer[x] == ':' || buffer[x] == ',' || buffer[x] == '-' || buffer[x] == '=')
@ -1870,5 +2130,3 @@ void strip_splunk_query_terms(char *buffer) {
return; return;
} }

149
cgi/cmd.c
View File

@ -2,8 +2,6 @@
* *
* CMD.C - Nagios Command CGI * CMD.C - Nagios Command CGI
* *
* Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-28-2010
* *
* License: * License:
* *
@ -37,23 +35,17 @@ extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char command_file[MAX_FILENAME_LENGTH]; extern char command_file[MAX_FILENAME_LENGTH];
extern char comment_file[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int nagios_process_state; extern int nagios_process_state;
extern int check_external_commands;
extern int use_authentication; extern int use_authentication;
extern int lock_author_names; extern int lock_author_names;
extern scheduled_downtime *scheduled_downtime_list; extern int ack_no_sticky;
extern comment *comment_list; extern int ack_no_send;
extern int date_format;
#define MAX_AUTHOR_LENGTH 64 #define MAX_AUTHOR_LENGTH 64
#define MAX_COMMENT_LENGTH 1024 #define MAX_COMMENT_LENGTH 1024
@ -70,6 +62,7 @@ char *comment_author = "";
char *comment_data = ""; char *comment_data = "";
char *start_time_string = ""; char *start_time_string = "";
char *end_time_string = ""; char *end_time_string = "";
char *cookie_form_id = NULL, *form_id = NULL;
unsigned long comment_id = 0; unsigned long comment_id = 0;
unsigned long downtime_id = 0; unsigned long downtime_id = 0;
@ -119,6 +112,10 @@ int string_to_time(char *, time_t *);
int main(void) { int main(void) {
int result = OK; int result = OK;
int formid_ok = OK;
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* get the arguments passed in the URL */ /* get the arguments passed in the URL */
process_cgivars(); process_cgivars();
@ -219,7 +216,15 @@ int main(void) {
free_object_data(); free_object_data();
return OK; return OK;
}
if (cookie_form_id && *cookie_form_id) {
formid_ok = ERROR;
if (form_id && *form_id) {
if (!strcmp(form_id, cookie_form_id))
formid_ok = OK;
} }
}
/* if no command was specified... */ /* if no command was specified... */
if(command_type == CMD_NONE) { if(command_type == CMD_NONE) {
@ -234,8 +239,12 @@ int main(void) {
request_command_data(command_type); request_command_data(command_type);
/* the user wants to commit the command */ /* the user wants to commit the command */
else if(command_mode == CMDMODE_COMMIT) else if(command_mode == CMDMODE_COMMIT) {
commit_command_data(command_type); if (formid_ok == ERROR) /* we're expecting an id but it wasn't there... */
printf("<p>Error: Invalid form id!</p>\n");
else
commit_command_data(command_type);
}
document_footer(); document_footer();
@ -264,7 +273,7 @@ void document_header(int use_stylesheet) {
else { else {
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
printf("<html>\n"); printf("<html>\n");
printf("<head>\n"); printf("<head>\n");
@ -321,7 +330,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -654,8 +662,30 @@ int process_cgivars(void) {
else if(!strcmp(variables[x], "broadcast_notification")) else if(!strcmp(variables[x], "broadcast_notification"))
broadcast_notification = NOTIFICATION_OPTION_BROADCAST; broadcast_notification = NOTIFICATION_OPTION_BROADCAST;
/* we found the cookie form id */
else if (!strcmp(variables[x], "NagFormId")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
cookie_form_id = (char*)strdup(variables[x]);
} }
/* we found the form id on the form */
else if (!strcmp(variables[x], "nagFormId")) {
x++;
if (variables[x] == NULL) {
error = TRUE;
break;
}
form_id = (char*)strdup(variables[x]);
}
}
/* free memory allocated to the CGI variables */ /* free memory allocated to the CGI variables */
free_cgivars(variables); free_cgivars(variables);
@ -666,7 +696,7 @@ int process_cgivars(void) {
void request_command_data(int cmd) { void request_command_data(int cmd) {
time_t t; time_t t;
char start_time[MAX_DATETIME_LENGTH]; char start_time_str[MAX_DATETIME_LENGTH];
char buffer[MAX_INPUT_BUFFER]; char buffer[MAX_INPUT_BUFFER];
contact *temp_contact; contact *temp_contact;
scheduled_downtime *temp_downtime; scheduled_downtime *temp_downtime;
@ -851,11 +881,6 @@ void request_command_data(int cmd) {
printf("cancel scheduled downtime for a particular %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "host" : "service"); printf("cancel scheduled downtime for a particular %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "host" : "service");
break; break;
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
printf("%s failure prediction for hosts and service", (cmd == CMD_ENABLE_FAILURE_PREDICTION) ? "enable" : "disable");
break;
case CMD_ENABLE_PERFORMANCE_DATA: case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA: case CMD_DISABLE_PERFORMANCE_DATA:
printf("%s performance data processing for hosts and services", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "enable" : "disable"); printf("%s performance data processing for hosts and services", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "enable" : "disable");
@ -926,6 +951,11 @@ void request_command_data(int cmd) {
printf("schedule downtime for all services in a particular servicegroup"); printf("schedule downtime for all services in a particular servicegroup");
break; break;
case CMD_CLEAR_HOST_FLAPPING_STATE:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("clear flapping state for a %s", (cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION: case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION: case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
printf("send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service"); printf("send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
@ -950,6 +980,8 @@ void request_command_data(int cmd) {
printf("<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=1 CLASS='optBox'>\n"); printf("<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=1 CLASS='optBox'>\n");
printf("<TR><TD CLASS='optBoxItem'>\n"); printf("<TR><TD CLASS='optBoxItem'>\n");
printf("<form method='post' action='%s'>\n", COMMAND_CGI); printf("<form method='post' action='%s'>\n", COMMAND_CGI);
if (cookie_form_id && *cookie_form_id)
printf("<INPUT TYPE='hidden' NAME='nagFormId' VALUE='%s'\n", cookie_form_id);
printf("<TABLE CELLSPACING=0 CELLPADDING=0 CLASS='optBox'>\n"); printf("<TABLE CELLSPACING=0 CELLPADDING=0 CLASS='optBox'>\n");
printf("<tr><td><INPUT TYPE='HIDDEN' NAME='cmd_typ' VALUE='%d'><INPUT TYPE='HIDDEN' NAME='cmd_mod' VALUE='%d'></td></tr>\n", cmd, CMDMODE_COMMIT); printf("<tr><td><INPUT TYPE='HIDDEN' NAME='cmd_typ' VALUE='%d'><INPUT TYPE='HIDDEN' NAME='cmd_mod' VALUE='%d'></td></tr>\n", cmd, CMDMODE_COMMIT);
@ -963,10 +995,10 @@ void request_command_data(int cmd) {
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) { if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) {
printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>"); printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='sticky_ack' CHECKED>"); printf("<INPUT TYPE='checkbox' NAME='sticky_ack' %s>", (ack_no_sticky == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>"); printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='send_notification' CHECKED>"); printf("<INPUT TYPE='checkbox' NAME='send_notification' %s>", (ack_no_send == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
} }
printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? " Comment" : ""); printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? " Comment" : "");
@ -989,10 +1021,10 @@ void request_command_data(int cmd) {
printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc)); printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) { if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) {
printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>"); printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='sticky_ack' CHECKED>"); printf("<INPUT TYPE='checkbox' NAME='sticky_ack' %s>", (ack_no_sticky == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>"); printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
printf("<INPUT TYPE='checkbox' NAME='send_notification' CHECKED>"); printf("<INPUT TYPE='checkbox' NAME='send_notification' %s>", (ack_no_send == TRUE) ? "" : "CHECKED");
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
} }
printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? " Comment" : ""); printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? " Comment" : "");
@ -1068,6 +1100,7 @@ void request_command_data(int cmd) {
case CMD_DISABLE_SVC_FLAP_DETECTION: case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC: case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC: case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>"); printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name)); printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
@ -1096,6 +1129,7 @@ void request_command_data(int cmd) {
case CMD_DISABLE_PASSIVE_HOST_CHECKS: case CMD_DISABLE_PASSIVE_HOST_CHECKS:
case CMD_START_OBSESSING_OVER_HOST: case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST: case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_CLEAR_HOST_FLAPPING_STATE:
printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>"); printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name)); printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
printf("</b></td></tr>\n"); printf("</b></td></tr>\n");
@ -1125,8 +1159,6 @@ void request_command_data(int cmd) {
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS: case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION: case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION: case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA: case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA: case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS: case CMD_START_EXECUTING_HOST_CHECKS:
@ -1199,15 +1231,15 @@ void request_command_data(int cmd) {
if(temp_downtime->type != HOST_DOWNTIME) if(temp_downtime->type != HOST_DOWNTIME)
continue; continue;
printf("<option value='%lu'>", temp_downtime->downtime_id); printf("<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME); get_time_string(&temp_downtime->start_time, start_time_str, sizeof(start_time_str), SHORT_DATE_TIME);
printf("ID: %lu, Host '%s' starting @ %s\n", temp_downtime->downtime_id, temp_downtime->host_name, start_time); printf("ID: %lu, Host '%s' starting @ %s\n", temp_downtime->downtime_id, temp_downtime->host_name, start_time_str);
} }
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) { for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if(temp_downtime->type != SERVICE_DOWNTIME) if(temp_downtime->type != SERVICE_DOWNTIME)
continue; continue;
printf("<option value='%lu'>", temp_downtime->downtime_id); printf("<option value='%lu'>", temp_downtime->downtime_id);
get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME); get_time_string(&temp_downtime->start_time, start_time_str, sizeof(start_time_str), SHORT_DATE_TIME);
printf("ID: %lu, Service '%s' on host '%s' starting @ %s \n", temp_downtime->downtime_id, temp_downtime->service_description, temp_downtime->host_name, start_time); printf("ID: %lu, Service '%s' on host '%s' starting @ %s \n", temp_downtime->downtime_id, temp_downtime->service_description, temp_downtime->host_name, start_time_str);
} }
printf("</select>\n"); printf("</select>\n");
@ -1418,7 +1450,7 @@ void commit_command_data(int cmd) {
service *temp_service; service *temp_service;
host *temp_host; host *temp_host;
hostgroup *temp_hostgroup; hostgroup *temp_hostgroup;
comment *temp_comment; nagios_comment *temp_comment;
scheduled_downtime *temp_downtime; scheduled_downtime *temp_downtime;
servicegroup *temp_servicegroup = NULL; servicegroup *temp_servicegroup = NULL;
contact *temp_contact = NULL; contact *temp_contact = NULL;
@ -1565,6 +1597,7 @@ void commit_command_data(int cmd) {
case CMD_DISABLE_SVC_FLAP_DETECTION: case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_START_OBSESSING_OVER_SVC: case CMD_START_OBSESSING_OVER_SVC:
case CMD_STOP_OBSESSING_OVER_SVC: case CMD_STOP_OBSESSING_OVER_SVC:
case CMD_CLEAR_SVC_FLAPPING_STATE:
/* make sure we have author name and comment data... */ /* make sure we have author name and comment data... */
if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) { if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
@ -1629,8 +1662,6 @@ void commit_command_data(int cmd) {
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS: case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION: case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION: case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA: case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA: case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS: case CMD_START_EXECUTING_HOST_CHECKS:
@ -1671,6 +1702,7 @@ void commit_command_data(int cmd) {
case CMD_SCHEDULE_HOST_CHECK: case CMD_SCHEDULE_HOST_CHECK:
case CMD_START_OBSESSING_OVER_HOST: case CMD_START_OBSESSING_OVER_HOST:
case CMD_STOP_OBSESSING_OVER_HOST: case CMD_STOP_OBSESSING_OVER_HOST:
case CMD_CLEAR_HOST_FLAPPING_STATE:
/* make sure we have author name and comment data... */ /* make sure we have author name and comment data... */
if(cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) { if(cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) {
@ -1886,7 +1918,7 @@ void commit_command_data(int cmd) {
if(result == OK) { if(result == OK) {
if(content_type == WML_CONTENT) if(content_type == WML_CONTENT)
printf("<p>Your command was submitted sucessfully...</p>\n"); printf("<p>Your command was submitted successfully...</p>\n");
else { else {
printf("<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>\n"); printf("<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>\n");
printf("Note: It may take a while before the command is actually processed.<BR><BR>\n"); printf("Note: It may take a while before the command is actually processed.<BR><BR>\n");
@ -1909,31 +1941,34 @@ void commit_command_data(int cmd) {
__attribute__((format(printf, 2, 3))) __attribute__((format(printf, 2, 3)))
static int cmd_submitf(int id, const char *fmt, ...) { static int cmd_submitf(int id, const char *fmt, ...) {
char cmd[MAX_EXTERNAL_COMMAND_LENGTH]; char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
const char *command; const char *command_name;
int len, len2; int len;
int len2;
va_list ap; va_list ap;
command = extcmd_get_name(id); command_name = extcmd_get_name(id);
/* /*
* We disallow sending 'CHANGE' commands from the cgi's * We disallow sending 'CHANGE' commands from the cgi's
* until we do proper session handling to prevent cross-site * until we do proper session handling to prevent cross-site
* request forgery * request forgery
*/ */
if(!command || (strlen(command) > 6 && !memcmp("CHANGE", command, 6))) if(!command_name || (strlen(command_name) > 6 && !memcmp("CHANGE", command_name, 6)))
return ERROR; return ERROR;
len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command); len = snprintf(cmd, sizeof(cmd), "[%lu] %s;", time(NULL), command_name);
if(len < 0) if(len < 0 || len >= sizeof(cmd))
return ERROR; return ERROR;
if(fmt) { if(fmt) {
va_start(ap, fmt); va_start(ap, fmt);
len2 = vsnprintf(&cmd[len], sizeof(cmd) - len - 1, fmt, ap); len2 = vsnprintf(cmd + len, sizeof(cmd) - len, fmt, ap);
va_end(ap); va_end(ap);
if(len2 < 0) len += len2;
if(len2 < 0 || len >= sizeof(cmd))
return ERROR; return ERROR;
} }
cmd[len] = 0; /* 0 <= len < sizeof(cmd) */
return write_command_to_file(cmd); return write_command_to_file(cmd);
} }
@ -1985,8 +2020,6 @@ int commit_command(int cmd) {
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS: case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION: case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION: case CMD_DISABLE_FLAP_DETECTION:
case CMD_ENABLE_FAILURE_PREDICTION:
case CMD_DISABLE_FAILURE_PREDICTION:
case CMD_ENABLE_PERFORMANCE_DATA: case CMD_ENABLE_PERFORMANCE_DATA:
case CMD_DISABLE_PERFORMANCE_DATA: case CMD_DISABLE_PERFORMANCE_DATA:
case CMD_START_EXECUTING_HOST_CHECKS: case CMD_START_EXECUTING_HOST_CHECKS:
@ -2013,6 +2046,7 @@ int commit_command(int cmd) {
case CMD_ENABLE_HOST_CHECK: case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK: case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT: case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_CLEAR_HOST_FLAPPING_STATE:
result = cmd_submitf(cmd, "%s", host_name); result = cmd_submitf(cmd, "%s", host_name);
break; break;
@ -2031,6 +2065,7 @@ int commit_command(int cmd) {
case CMD_ENABLE_SVC_CHECK: case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK: case CMD_DISABLE_SVC_CHECK:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT: case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_CLEAR_SVC_FLAPPING_STATE:
result = cmd_submitf(cmd, "%s;%s", host_name, service_desc); result = cmd_submitf(cmd, "%s;%s", host_name, service_desc);
break; break;
@ -2307,7 +2342,7 @@ void clean_comment_data(char *buffer) {
/* display information about a command */ /* display information about a command */
void show_command_help(cmd) { void show_command_help(int cmd) {
printf("<DIV ALIGN=CENTER CLASS='descriptionTitle'>Command Description</DIV>\n"); printf("<DIV ALIGN=CENTER CLASS='descriptionTitle'>Command Description</DIV>\n");
printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='commandDescription'>\n"); printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='commandDescription'>\n");
@ -2626,14 +2661,6 @@ void show_command_help(cmd) {
printf("This command is used to cancel active or pending scheduled downtime for the specified service.\n"); printf("This command is used to cancel active or pending scheduled downtime for the specified service.\n");
break; break;
case CMD_ENABLE_FAILURE_PREDICTION:
printf("This command is used to enable failure prediction for hosts and services on a program-wide basis. Individual hosts and services may have failure prediction disabled.\n");
break;
case CMD_DISABLE_FAILURE_PREDICTION:
printf("This command is used to disable failure prediction for hosts and services on a program-wide basis.\n");
break;
case CMD_ENABLE_PERFORMANCE_DATA: case CMD_ENABLE_PERFORMANCE_DATA:
printf("This command is used to enable the processing of performance data for hosts and services on a program-wide basis. Individual hosts and services may have performance data processing disabled.\n"); printf("This command is used to enable the processing of performance data for hosts and services on a program-wide basis. Individual hosts and services may have performance data processing disabled.\n");
break; break;
@ -2648,7 +2675,7 @@ void show_command_help(cmd) {
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n"); printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break; break;
case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME: case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
@ -2657,7 +2684,7 @@ void show_command_help(cmd) {
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n"); printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the hostgroup, check the 'Schedule downtime for hosts too' option.\n"); printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the hostgroup, check the 'Schedule downtime for hosts too' option.\n");
break; break;
@ -2748,7 +2775,7 @@ void show_command_help(cmd) {
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n"); printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
break; break;
case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME: case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
@ -2757,10 +2784,18 @@ void show_command_help(cmd) {
printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n"); printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the servicegroup, check the 'Schedule downtime for hosts too' option.\n"); printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the servicegroup, check the 'Schedule downtime for hosts too' option.\n");
break; break;
case CMD_CLEAR_HOST_FLAPPING_STATE:
case CMD_CLEAR_SVC_FLAPPING_STATE:
printf("This command is used to reset the flapping state for the specified %s.\n",
(cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
printf("All state history for the specified %s will be cleared.\n",
(cmd == CMD_CLEAR_HOST_FLAPPING_STATE) ? "host" : "service");
break;
case CMD_SEND_CUSTOM_HOST_NOTIFICATION: case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
case CMD_SEND_CUSTOM_SVC_NOTIFICATION: case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
printf("This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.\n", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service"); printf("This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.\n", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");

File diff suppressed because it is too large Load Diff

View File

@ -84,19 +84,8 @@ struct nagios_extcmd in_core_commands[] = {
CMD_DEF(DISABLE_HOSTGROUP_HOST_NOTIFICATIONS, 0, NULL), CMD_DEF(DISABLE_HOSTGROUP_HOST_NOTIFICATIONS, 0, NULL),
CMD_DEF(ENABLE_HOSTGROUP_SVC_CHECKS, 0, NULL), CMD_DEF(ENABLE_HOSTGROUP_SVC_CHECKS, 0, NULL),
CMD_DEF(DISABLE_HOSTGROUP_SVC_CHECKS, 0, NULL), CMD_DEF(DISABLE_HOSTGROUP_SVC_CHECKS, 0, NULL),
CMD_DEF(CANCEL_HOST_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_SVC_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_ACTIVE_HOST_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_PENDING_HOST_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_ACTIVE_SVC_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_PENDING_SVC_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_ACTIVE_HOST_SVC_DOWNTIME, 0, NULL),
CMD_DEF(CANCEL_PENDING_HOST_SVC_DOWNTIME, 0, NULL),
CMD_DEF(FLUSH_PENDING_COMMANDS, 0, NULL),
CMD_DEF(DEL_HOST_DOWNTIME, 0, NULL), CMD_DEF(DEL_HOST_DOWNTIME, 0, NULL),
CMD_DEF(DEL_SVC_DOWNTIME, 0, NULL), CMD_DEF(DEL_SVC_DOWNTIME, 0, NULL),
CMD_DEF(ENABLE_FAILURE_PREDICTION, 0, NULL),
CMD_DEF(DISABLE_FAILURE_PREDICTION, 0, NULL),
CMD_DEF(ENABLE_PERFORMANCE_DATA, 0, NULL), CMD_DEF(ENABLE_PERFORMANCE_DATA, 0, NULL),
CMD_DEF(DISABLE_PERFORMANCE_DATA, 0, NULL), CMD_DEF(DISABLE_PERFORMANCE_DATA, 0, NULL),
CMD_DEF(SCHEDULE_HOSTGROUP_HOST_DOWNTIME, 0, NULL), CMD_DEF(SCHEDULE_HOSTGROUP_HOST_DOWNTIME, 0, NULL),
@ -183,7 +172,8 @@ struct nagios_extcmd in_core_commands[] = {
CMD_DEF(CHANGE_SVC_MODATTR, 0, NULL), CMD_DEF(CHANGE_SVC_MODATTR, 0, NULL),
CMD_DEF(CHANGE_CONTACT_MODATTR, 0, NULL), CMD_DEF(CHANGE_CONTACT_MODATTR, 0, NULL),
CMD_DEF(CHANGE_CONTACT_MODHATTR, 0, NULL), CMD_DEF(CHANGE_CONTACT_MODHATTR, 0, NULL),
CMD_DEF(CHANGE_CONTACT_MODSATTR, 0, NULL), CMD_DEF(CLEAR_HOST_FLAPPING_STATE, 0, NULL),
CMD_DEF(CLEAR_SVC_FLAPPING_STATE, 0, NULL),
}; };
#undef CMD_DEF #undef CMD_DEF
@ -192,7 +182,7 @@ struct nagios_extcmd in_core_commands[] = {
#endif #endif
const char *extcmd_get_name(int id) { const char *extcmd_get_name(int id) {
int i; unsigned int i;
for(i = 0; i < ARRAY_SIZE(in_core_commands); i++) { for(i = 0; i < ARRAY_SIZE(in_core_commands); i++) {
struct nagios_extcmd *ecmd; struct nagios_extcmd *ecmd;

View File

@ -2,8 +2,6 @@
* *
* EXTINFO.C - Nagios Extended Information CGI * EXTINFO.C - Nagios Extended Information CGI
* *
* Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 06-17-2009
* *
* License: * License:
* *
@ -35,28 +33,10 @@
static nagios_macros *mac; static nagios_macros *mac;
extern char nagios_check_command[MAX_INPUT_BUFFER];
extern char nagios_process_info[MAX_INPUT_BUFFER]; extern char nagios_process_info[MAX_INPUT_BUFFER];
extern int nagios_process_state; extern int nagios_process_state;
extern int refresh_rate; extern int refresh_rate;
extern time_t program_start;
extern int nagios_pid;
extern int daemon_mode;
extern time_t last_command_check;
extern time_t last_log_rotation;
extern int enable_notifications;
extern int execute_service_checks;
extern int accept_passive_service_checks;
extern int execute_host_checks;
extern int accept_passive_host_checks;
extern int enable_event_handlers;
extern int obsess_over_services;
extern int obsess_over_hosts;
extern int enable_flap_detection;
extern int enable_failure_prediction;
extern int process_performance_data;
extern int buffer_stats[1][3]; extern int buffer_stats[1][3];
extern int program_stats[MAX_CHECK_STATS_TYPES][3]; extern int program_stats[MAX_CHECK_STATS_TYPES][3];
@ -66,19 +46,15 @@ extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char url_docs_path[MAX_FILENAME_LENGTH]; extern char url_docs_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char log_file[MAX_FILENAME_LENGTH]; extern char url_js_path[MAX_FILENAME_LENGTH];
extern int enable_splunk_integration; extern int enable_splunk_integration;
extern char *notes_url_target; extern char *notes_url_target;
extern char *action_url_target; extern char *action_url_target;
extern comment *comment_list;
extern scheduled_downtime *scheduled_downtime_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
extern hostgroup *hostgroup_list;
extern servicegroup *servicegroup_list;
#define MAX_MESSAGE_BUFFER 4096 #define MAX_MESSAGE_BUFFER 4096
@ -133,7 +109,6 @@ int display_header = TRUE;
int main(void) { int main(void) {
int result = OK;
int found = FALSE; int found = FALSE;
char temp_buffer[MAX_INPUT_BUFFER] = ""; char temp_buffer[MAX_INPUT_BUFFER] = "";
char *processed_string = NULL; char *processed_string = NULL;
@ -151,51 +126,16 @@ int main(void) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, READ_ALL_STATUS_DATA);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
/* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
if(result == ERROR) {
document_header(FALSE);
status_data_error();
document_footer();
free_memory();
return ERROR;
}
/* initialize macros */ /* initialize macros */
init_macros(); init_macros();
document_header(TRUE);
/* get authentication information */ /* get authentication information */
get_authentication_information(&current_authdata); get_authentication_information(&current_authdata);
document_header(TRUE);
if(display_header == TRUE) { if(display_header == TRUE) {
@ -582,6 +522,7 @@ int main(void) {
void document_header(int use_stylesheet) { void document_header(int use_stylesheet) {
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
char *vidurl = NULL;
time_t current_time; time_t current_time;
time_t expire_time; time_t expire_time;
@ -597,7 +538,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -612,7 +553,30 @@ void document_header(int use_stylesheet) {
if(use_stylesheet == TRUE) { if(use_stylesheet == TRUE) {
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, COMMON_CSS); printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, COMMON_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, EXTINFO_CSS); printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, EXTINFO_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, NAGFUNCS_CSS);
} }
if (display_type == DISPLAY_HOST_INFO)
vidurl = "https://www.youtube.com/embed/n3QEAf-MxY4";
else if(display_type == DISPLAY_SERVICE_INFO)
vidurl = "https://www.youtube.com/embed/f_knwQOS6FI";
if (vidurl) {
printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, JQUERY_JS);
printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, NAGFUNCS_JS);
printf("<script type='text/javascript'>\n");
printf("var vbox, vBoxId='extinfo%d', vboxText = "
"'<a href=https://www.nagios.com/tours target=_blank>"
"Click here to watch the entire Nagios Core 4 Tour!</a>';\n",
display_type);
printf("$(document).ready(function() {\n"
"var user = '%s';\nvBoxId += ';' + user;\n",
current_authdata.username);
printf("vbox = new vidbox({pos:'lr',vidurl:'%s',text:vboxText,"
"vidid:vBoxId});\n", vidurl);
printf("});\n</script>\n");
}
printf("</head>\n"); printf("</head>\n");
printf("<body CLASS='extinfo'>\n"); printf("<body CLASS='extinfo'>\n");
@ -651,7 +615,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -824,10 +787,6 @@ void show_process_info(void) {
sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds); sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds);
printf("<TR><TD CLASS='dataVar'>Total Running Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", run_time_string); printf("<TR><TD CLASS='dataVar'>Total Running Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", run_time_string);
/* last external check */
get_time_string(&last_command_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("<TR><TD CLASS='dataVar'>Last External Command Check:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_command_check == (time_t)0) ? "N/A" : date_time);
/* last log file rotation */ /* last log file rotation */
get_time_string(&last_log_rotation, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&last_log_rotation, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("<TR><TD CLASS='dataVar'>Last Log File Rotation:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_log_rotation == (time_t)0) ? "N/A" : date_time); printf("<TR><TD CLASS='dataVar'>Last Log File Rotation:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_log_rotation == (time_t)0) ? "N/A" : date_time);
@ -862,19 +821,9 @@ void show_process_info(void) {
/* flap detection enabled */ /* flap detection enabled */
printf("<TR><TD CLASS='dataVar'>Flap Detection Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_flap_detection == TRUE) ? "Yes" : "No"); printf("<TR><TD CLASS='dataVar'>Flap Detection Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_flap_detection == TRUE) ? "Yes" : "No");
#ifdef PREDICT_FAILURES
/* failure prediction enabled */
printf("<TR><TD CLASS='dataVar'>Failure Prediction Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_failure_prediction == TRUE) ? "Yes" : "No");
#endif
/* process performance data */ /* process performance data */
printf("<TR><TD CLASS='dataVar'>Performance Data Being Processed?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (process_performance_data == TRUE) ? "Yes" : "No"); printf("<TR><TD CLASS='dataVar'>Performance Data Being Processed?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (process_performance_data == TRUE) ? "Yes" : "No");
#ifdef USE_OLDCRUD
/* daemon mode */
printf("<TR><TD CLASS='dataVar'>Running As A Daemon?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (daemon_mode == TRUE) ? "Yes" : "No");
#endif
printf("</TABLE>\n"); printf("</TABLE>\n");
printf("</TD></TR>\n"); printf("</TD></TR>\n");
printf("</TABLE>\n"); printf("</TABLE>\n");
@ -940,12 +889,6 @@ void show_process_info(void) {
else else
printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Flap Detection' TITLE='Enable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable flap detection</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FLAP_DETECTION); printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Flap Detection' TITLE='Enable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable flap detection</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FLAP_DETECTION);
#ifdef PREDICT_FAILURES
if(enable_failure_prediction == TRUE)
printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Failure Prediction' TITLE='Disable Failure Prediction'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable failure prediction</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_FAILURE_PREDICTION);
else
printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Failure Prediction' TITLE='Enable Failure Prediction'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable failure prediction</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FAILURE_PREDICTION);
#endif
if(process_performance_data == TRUE) if(process_performance_data == TRUE)
printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Performance Data' TITLE='Disable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable performance data</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PERFORMANCE_DATA); printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Performance Data' TITLE='Disable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable performance data</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PERFORMANCE_DATA);
else else
@ -955,11 +898,6 @@ void show_process_info(void) {
} }
else { else {
printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...\n"); printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...\n");
if(!strcmp(nagios_check_command, "")) {
printf("<BR><BR>\n");
printf("Hint: It looks as though you have not defined a command for checking the process state by supplying a value for the <b>nagios_check_command</b> option in the CGI configuration file.<BR>\n");
printf("Read the documentation for more information on checking the status of the Nagios process in the CGIs.\n");
}
printf("</DIV>\n"); printf("</DIV>\n");
} }
@ -978,7 +916,7 @@ void show_host_info(void) {
char state_duration[48]; char state_duration[48];
char status_age[48]; char status_age[48];
char state_string[MAX_INPUT_BUFFER]; char state_string[MAX_INPUT_BUFFER];
char *bg_class = ""; const char *bg_class = "";
char *buf = NULL; char *buf = NULL;
int days; int days;
int hours; int hours;
@ -1058,15 +996,15 @@ void show_host_info(void) {
snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : "");
state_duration[sizeof(state_duration) - 1] = '\x0'; state_duration[sizeof(state_duration) - 1] = '\x0';
if(temp_hoststatus->status == HOST_UP) { if(temp_hoststatus->status == SD_HOST_UP) {
strcpy(state_string, "UP"); strcpy(state_string, "UP");
bg_class = "hostUP"; bg_class = "hostUP";
} }
else if(temp_hoststatus->status == HOST_DOWN) { else if(temp_hoststatus->status == SD_HOST_DOWN) {
strcpy(state_string, "DOWN"); strcpy(state_string, "DOWN");
bg_class = "hostDOWN"; bg_class = "hostDOWN";
} }
else if(temp_hoststatus->status == HOST_UNREACHABLE) { else if(temp_hoststatus->status == SD_HOST_UNREACHABLE) {
strcpy(state_string, "UNREACHABLE"); strcpy(state_string, "UNREACHABLE");
bg_class = "hostUNREACHABLE"; bg_class = "hostUNREACHABLE";
} }
@ -1092,10 +1030,10 @@ void show_host_info(void) {
get_time_string(&temp_hoststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_hoststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("<TR><TD CLASS='dataVar'>Last Check Time:</td><td CLASS='dataVal'>%s</td></tr>\n", date_time); printf("<TR><TD CLASS='dataVar'>Last Check Time:</td><td CLASS='dataVal'>%s</td></tr>\n", date_time);
printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->check_type == HOST_CHECK_ACTIVE) ? "ACTIVE" : "PASSIVE"); printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE");
printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>"); printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
if(temp_hoststatus->check_type == HOST_CHECK_ACTIVE) if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE)
printf("%.3f", temp_hoststatus->latency); printf("%.3f", temp_hoststatus->latency);
else else
printf("N/A"); printf("N/A");
@ -1152,9 +1090,9 @@ void show_host_info(void) {
printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->accept_passive_host_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->accept_passive_host_checks) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->accept_passive_checks) ? "ENABLED" : "DISABLED");
printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->obsess_over_host == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->obsess_over_host) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->obsess) ? "ENABLED" : "DISABLED");
printf("<TR><TD CLASS='dataVar'>Notifications:</td><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Notifications:</td><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED");
@ -1194,19 +1132,19 @@ void show_host_info(void) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable active checks of this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable active checks of this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(host_name));
printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Host Check' TITLE='Re-schedule Next Host Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s%s'>Re-schedule the next check of this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(host_name), (temp_hoststatus->checks_enabled == TRUE) ? "&force_check" : ""); printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Host Check' TITLE='Re-schedule Next Host Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s%s'>Re-schedule the next check of this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(host_name), (temp_hoststatus->checks_enabled == TRUE) ? "&force_check" : "");
if(temp_hoststatus->accept_passive_host_checks == TRUE) { if(temp_hoststatus->accept_passive_checks == TRUE) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Host' TITLE='Submit Passive Check Result For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Submit passive check result for this host</a></td></tr>\n", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_HOST_CHECK_RESULT, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Host' TITLE='Submit Passive Check Result For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Submit passive check result for this host</a></td></tr>\n", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_HOST_CHECK_RESULT, url_encode(host_name));
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Host' TITLE='Stop Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop accepting passive checks for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_HOST_CHECKS, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Host' TITLE='Stop Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop accepting passive checks for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
} }
else else
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Host' TITLE='Start Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start accepting passive checks for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_HOST_CHECKS, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Host' TITLE='Start Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start accepting passive checks for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
if(temp_hoststatus->obsess_over_host == TRUE) if(temp_hoststatus->obsess == TRUE)
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Host' TITLE='Stop Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop obsessing over this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Host' TITLE='Stop Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop obsessing over this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST, url_encode(host_name));
else else
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Host' TITLE='Start Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start obsessing over this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Host' TITLE='Start Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start obsessing over this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST, url_encode(host_name));
if(temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) { if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE) {
if(temp_hoststatus->problem_has_been_acknowledged == FALSE) if(temp_hoststatus->problem_has_been_acknowledged == FALSE)
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Host Problem' TITLE='Acknowledge This Host Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Acknowledge this host problem</a></td></tr>\n", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Host Problem' TITLE='Acknowledge This Host Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Acknowledge this host problem</a></td></tr>\n", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(host_name));
else else
@ -1220,7 +1158,7 @@ void show_host_info(void) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Send custom host notification</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_HOST_NOTIFICATION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Send custom host notification</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_HOST_NOTIFICATION, url_encode(host_name));
if(temp_hoststatus->status != HOST_UP) if(temp_hoststatus->status != SD_HOST_UP)
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Host Notification' TITLE='Delay Next Host Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Delay next host notification</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_HOST_NOTIFICATION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Host Notification' TITLE='Delay Next Host Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Delay next host notification</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_HOST_NOTIFICATION, url_encode(host_name));
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host' TITLE='Schedule Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host' TITLE='Schedule Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME, url_encode(host_name));
@ -1241,9 +1179,10 @@ void show_host_info(void) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Host' TITLE='Disable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable event handler for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_EVENT_HANDLER, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Host' TITLE='Disable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable event handler for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_EVENT_HANDLER, url_encode(host_name));
else else
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Host' TITLE='Enable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable event handler for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_EVENT_HANDLER, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Host' TITLE='Enable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable event handler for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_EVENT_HANDLER, url_encode(host_name));
if(temp_hoststatus->flap_detection_enabled == TRUE) if(temp_hoststatus->flap_detection_enabled == TRUE) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Host' TITLE='Disable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable flap detection for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_FLAP_DETECTION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Host' TITLE='Disable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable flap detection for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_FLAP_DETECTION, url_encode(host_name));
else printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Clear Flapping State For This Host' TITLE='Clear Flapping State For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Clear flapping state for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_CLEAR_HOST_FLAPPING_STATE, url_encode(host_name));
} else
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Host' TITLE='Enable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable flap detection for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_FLAP_DETECTION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Host' TITLE='Enable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable flap detection for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_FLAP_DETECTION, url_encode(host_name));
printf("</TABLE>\n"); printf("</TABLE>\n");
@ -1266,10 +1205,9 @@ void show_host_info(void) {
printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n"); printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
if(is_authorized_for_read_only(&current_authdata) == FALSE) { /* display comments */
/* display comments */ display_comments(HOST_COMMENT);
display_comments(HOST_COMMENT);
}
printf("</TD>\n"); printf("</TD>\n");
printf("</TR>\n"); printf("</TR>\n");
@ -1287,7 +1225,7 @@ void show_service_info(void) {
char state_duration[48]; char state_duration[48];
servicestatus *temp_svcstatus; servicestatus *temp_svcstatus;
char state_string[MAX_INPUT_BUFFER]; char state_string[MAX_INPUT_BUFFER];
char *bg_class = ""; const char *bg_class = "";
char *buf = NULL; char *buf = NULL;
int days; int days;
int hours; int hours;
@ -1405,10 +1343,10 @@ void show_service_info(void) {
get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("<TR><TD CLASS='dataVar'>Last Check Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time); printf("<TR><TD CLASS='dataVar'>Last Check Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time);
printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->check_type == SERVICE_CHECK_ACTIVE) ? "ACTIVE" : "PASSIVE"); printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->check_type == CHECK_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE");
printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>"); printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
if(temp_svcstatus->check_type == SERVICE_CHECK_ACTIVE) if(temp_svcstatus->check_type == CHECK_TYPE_ACTIVE)
printf("%.3f", temp_svcstatus->latency); printf("%.3f", temp_svcstatus->latency);
else else
printf("N/A"); printf("N/A");
@ -1467,9 +1405,9 @@ void show_service_info(void) {
printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED");
printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->accept_passive_service_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->accept_passive_service_checks) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->accept_passive_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->accept_passive_checks) ? "ENABLED" : "DISABLED");
printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->obsess_over_service == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->obsess_over_service) ? "ENABLED" : "DISABLED"); printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->obsess == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->obsess) ? "ENABLED" : "DISABLED");
printf("<TR><td CLASS='dataVar'>Notifications:</TD><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED"); printf("<TR><td CLASS='dataVar'>Notifications:</TD><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED");
@ -1515,7 +1453,7 @@ void show_service_info(void) {
printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Service Check' TITLE='Re-schedule Next Service Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(host_name)); printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Service Check' TITLE='Re-schedule Next Service Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(host_name));
printf("&service=%s%s'>Re-schedule the next check of this service</a></td></tr>\n", url_encode(service_desc), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : ""); printf("&service=%s%s'>Re-schedule the next check of this service</a></td></tr>\n", url_encode(service_desc), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "");
if(temp_svcstatus->accept_passive_service_checks == TRUE) { if(temp_svcstatus->accept_passive_checks == TRUE) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Service' TITLE='Submit Passive Check Result For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_SERVICE_CHECK_RESULT, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Service' TITLE='Submit Passive Check Result For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_SERVICE_CHECK_RESULT, url_encode(host_name));
printf("&service=%s'>Submit passive check result for this service</a></td></tr>\n", url_encode(service_desc)); printf("&service=%s'>Submit passive check result for this service</a></td></tr>\n", url_encode(service_desc));
@ -1527,7 +1465,7 @@ void show_service_info(void) {
printf("&service=%s'>Start accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc)); printf("&service=%s'>Start accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc));
} }
if(temp_svcstatus->obsess_over_service == TRUE) { if(temp_svcstatus->obsess == TRUE) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Service' TITLE='Stop Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Service' TITLE='Stop Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC, url_encode(host_name));
printf("&service=%s'>Stop obsessing over this service</a></td></tr>\n", url_encode(service_desc)); printf("&service=%s'>Stop obsessing over this service</a></td></tr>\n", url_encode(service_desc));
} }
@ -1582,6 +1520,8 @@ void show_service_info(void) {
if(temp_svcstatus->flap_detection_enabled == TRUE) { if(temp_svcstatus->flap_detection_enabled == TRUE) {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Service' TITLE='Disable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_FLAP_DETECTION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Service' TITLE='Disable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_FLAP_DETECTION, url_encode(host_name));
printf("&service=%s'>Disable flap detection for this service</a></td></tr>\n", url_encode(service_desc)); printf("&service=%s'>Disable flap detection for this service</a></td></tr>\n", url_encode(service_desc));
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Clear Flapping State For This Service' TITLE='Clear Flapping State For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_CLEAR_SVC_FLAPPING_STATE, url_encode(host_name));
printf("&service=%s'>Clear flapping state for this service</a></td></tr>\n", url_encode(service_desc));
} }
else { else {
printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Service' TITLE='Enable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_FLAP_DETECTION, url_encode(host_name)); printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Service' TITLE='Enable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_FLAP_DETECTION, url_encode(host_name));
@ -1611,10 +1551,9 @@ void show_service_info(void) {
printf("<TR>\n"); printf("<TR>\n");
printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n"); printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
if(is_authorized_for_read_only(&current_authdata) == FALSE) { /* display comments */
/* display comments */ display_comments(SERVICE_COMMENT);
display_comments(SERVICE_COMMENT);
}
printf("</TD>\n"); printf("</TD>\n");
printf("</TR>\n"); printf("</TR>\n");
@ -1817,22 +1756,15 @@ void show_servicegroup_info() {
/* shows all service and host comments */ /* shows all service and host comments */
void show_all_comments(void) { void show_all_comments(void) {
int total_comments = 0; int total_comments = 0;
char *bg_class = ""; const char *bg_class = "";
int odd = 0; int odd = 0;
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
comment *temp_comment; nagios_comment *temp_comment;
host *temp_host; host *temp_host;
service *temp_service; service *temp_service;
char *comment_type; char *comment_type;
char expire_time[MAX_DATETIME_LENGTH]; char expire_time[MAX_DATETIME_LENGTH];
if(is_authorized_for_read_only(&current_authdata) == TRUE) {
printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to view comments.<br>\n");
return;
}
printf("<BR />\n"); printf("<BR />\n");
printf("<DIV CLASS='commentNav'>[&nbsp;<A HREF='#HOSTCOMMENTS' CLASS='commentNav'>Host Comments</A>&nbsp;|&nbsp;<A HREF='#SERVICECOMMENTS' CLASS='commentNav'>Service Comments</A>&nbsp;]</DIV>\n"); printf("<DIV CLASS='commentNav'>[&nbsp;<A HREF='#HOSTCOMMENTS' CLASS='commentNav'>Host Comments</A>&nbsp;|&nbsp;<A HREF='#SERVICECOMMENTS' CLASS='commentNav'>Service Comments</A>&nbsp;]</DIV>\n");
printf("<BR />\n"); printf("<BR />\n");
@ -1840,14 +1772,19 @@ void show_all_comments(void) {
printf("<A NAME=HOSTCOMMENTS></A>\n"); printf("<A NAME=HOSTCOMMENTS></A>\n");
printf("<DIV CLASS='commentTitle'>Host Comments</DIV>\n"); printf("<DIV CLASS='commentTitle'>Host Comments</DIV>\n");
printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON); if(is_authorized_for_read_only(&current_authdata)==FALSE) {
printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT); printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON);
printf("Add a new host comment</a></div>\n"); printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT);
printf("Add a new host comment</a></div>\n");
}
printf("<BR />\n"); printf("<BR />\n");
printf("<DIV ALIGN=CENTER>\n"); printf("<DIV ALIGN=CENTER>\n");
printf("<TABLE BORDER=0 CLASS='comment'>\n"); printf("<TABLE BORDER=0 CLASS='comment'>\n");
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n"); if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
else
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
/* display all the host comments */ /* display all the host comments */
for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) { for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
@ -1894,7 +1831,8 @@ void show_all_comments(void) {
printf("<tr CLASS='%s'>", bg_class); printf("<tr CLASS='%s'>", bg_class);
printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name); printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name);
printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_HOST_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_HOST_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
printf("</tr>\n"); printf("</tr>\n");
} }
@ -1910,14 +1848,19 @@ void show_all_comments(void) {
printf("<A NAME=SERVICECOMMENTS></A>\n"); printf("<A NAME=SERVICECOMMENTS></A>\n");
printf("<DIV CLASS='commentTitle'>Service Comments</DIV>\n"); printf("<DIV CLASS='commentTitle'>Service Comments</DIV>\n");
printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON); if(is_authorized_for_read_only(&current_authdata)==FALSE){
printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_SVC_COMMENT); printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON);
printf("Add a new service comment</a></div>\n"); printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_SVC_COMMENT);
printf("Add a new service comment</a></div>\n");
}
printf("<BR />\n"); printf("<BR />\n");
printf("<DIV ALIGN=CENTER>\n"); printf("<DIV ALIGN=CENTER>\n");
printf("<TABLE BORDER=0 CLASS='comment'>\n"); printf("<TABLE BORDER=0 CLASS='comment'>\n");
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n"); if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
else
printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
/* display all the service comments */ /* display all the service comments */
for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) { for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
@ -1966,7 +1909,8 @@ void show_all_comments(void) {
printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_comment->host_name)); printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_comment->host_name));
printf("&service=%s'>%s</A></td>", url_encode(temp_comment->service_description), temp_comment->service_description); printf("&service=%s'>%s</A></td>", url_encode(temp_comment->service_description), temp_comment->service_description);
printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
printf("<td><a href='%s?cmd_typ=%d&com_id=%ld'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<td><a href='%s?cmd_typ=%d&com_id=%ld'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
printf("</tr>\n"); printf("</tr>\n");
} }
@ -2070,7 +2014,7 @@ void show_performance_data(void) {
continue; continue;
/* is this an active or passive check? */ /* is this an active or passive check? */
if(temp_servicestatus->check_type == SERVICE_CHECK_ACTIVE) { if(temp_servicestatus->check_type == CHECK_TYPE_ACTIVE) {
total_active_service_checks++; total_active_service_checks++;
@ -2157,7 +2101,7 @@ void show_performance_data(void) {
continue; continue;
/* is this an active or passive check? */ /* is this an active or passive check? */
if(temp_hoststatus->check_type == HOST_CHECK_ACTIVE) { if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) {
total_active_host_checks++; total_active_host_checks++;
@ -2498,10 +2442,11 @@ void display_comments(int type) {
service *temp_service = NULL; service *temp_service = NULL;
int total_comments = 0; int total_comments = 0;
int display_comment = FALSE; int display_comment = FALSE;
char *bg_class = ""; const char *bg_class = "";
int odd = 1; int odd = 1;
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
comment *temp_comment; nagios_comment *temp_comment;
scheduled_downtime *temp_downtime;
char *comment_type; char *comment_type;
char expire_time[MAX_DATETIME_LENGTH]; char expire_time[MAX_DATETIME_LENGTH];
@ -2521,35 +2466,40 @@ void display_comments(int type) {
printf("<A NAME=comments></A>\n"); printf("<A NAME=comments></A>\n");
printf("<DIV CLASS='commentTitle'>%s Comments</DIV>\n", (type == HOST_COMMENT) ? "Host" : "Service"); printf("<DIV CLASS='commentTitle'>%s Comments</DIV>\n", (type == HOST_COMMENT) ? "Host" : "Service");
printf("<TABLE BORDER=0>\n");
printf("<tr>\n"); if(is_authorized_for_read_only(&current_authdata)==FALSE){
printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, COMMENT_ICON); printf("<TABLE BORDER=0>\n");
if(type == HOST_COMMENT)
printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name)); printf("<tr>\n");
else { printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, COMMENT_ICON);
printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_ADD_SVC_COMMENT, url_encode(host_name)); if(type == HOST_COMMENT)
printf("service=%s' CLASS='comment'>", url_encode(service_desc)); printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name));
else {
printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_ADD_SVC_COMMENT, url_encode(host_name));
printf("service=%s' CLASS='comment'>", url_encode(service_desc));
}
printf("Add a new comment</a></td>\n");
printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, DELETE_ICON);
if(type == HOST_COMMENT)
printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name));
else {
printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_DEL_ALL_SVC_COMMENTS, url_encode(host_name));
printf("service=%s' CLASS='comment'>", url_encode(service_desc));
}
printf("Delete all comments</a></td>\n");
printf("</tr>\n");
printf("</TABLE>\n");
} }
printf("Add a new comment</a></td>\n");
printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, DELETE_ICON);
if(type == HOST_COMMENT)
printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name));
else {
printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_DEL_ALL_SVC_COMMENTS, url_encode(host_name));
printf("service=%s' CLASS='comment'>", url_encode(service_desc));
}
printf("Delete all comments</a></td>\n");
printf("</tr>\n");
printf("</TABLE>\n");
//printf("</DIV>\n");
printf("<DIV ALIGN=CENTER>\n"); printf("<DIV ALIGN=CENTER>\n");
printf("<TABLE BORDER=0 CLASS='comment'>\n"); printf("<TABLE BORDER=0 CLASS='comment'>\n");
printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n"); if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
else
printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH></TR>\n");
/* check all the comments to see if they apply to this host or service */ /* check all the comments to see if they apply to this host or service */
/* Comments are displayed in the order they are read from the status.dat file */ /* Comments are displayed in the order they are read from the status.dat file */
@ -2591,14 +2541,31 @@ void display_comments(int type) {
comment_type = "?"; comment_type = "?";
} }
if (temp_comment->entry_type == DOWNTIME_COMMENT) {
for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
if (temp_downtime->comment_id == temp_comment->comment_id)
break;
}
}
else
temp_downtime = NULL;
get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME); get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("<tr CLASS='%s'>", bg_class); printf("<tr CLASS='%s'>", bg_class);
printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%lu</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author);
printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, (type == HOST_COMMENT) ? CMD_DEL_HOST_COMMENT : CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON); printf("<td CLASS='%s'>%s", bg_class, temp_comment->comment_data);
if (temp_downtime)
printf("<hr>%s", temp_downtime->comment);
printf("</td><td CLASS='%s'>%lu</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>",
bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No",
bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
if(is_authorized_for_read_only(&current_authdata)==FALSE)
printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, (type == HOST_COMMENT) ? CMD_DEL_HOST_COMMENT : CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
printf("</tr>\n"); printf("</tr>\n");
total_comments++; total_comments++;
} }
} }
@ -2617,7 +2584,7 @@ void display_comments(int type) {
/* shows all service and host scheduled downtime */ /* shows all service and host scheduled downtime */
void show_all_downtime(void) { void show_all_downtime(void) {
int total_downtime = 0; int total_downtime = 0;
char *bg_class = ""; const char *bg_class = "";
int odd = 0; int odd = 0;
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
scheduled_downtime *temp_downtime; scheduled_downtime *temp_downtime;
@ -2781,7 +2748,7 @@ void show_scheduling_queue(void) {
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
char temp_url[MAX_INPUT_BUFFER]; char temp_url[MAX_INPUT_BUFFER];
int odd = 0; int odd = 0;
char *bgclass = ""; const char *bgclass = "";
/* make sure the user has rights to view system information */ /* make sure the user has rights to view system information */
@ -3061,7 +3028,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
time_t next_check[2]; time_t next_check[2];
int current_attempt[2]; int current_attempt[2];
int status[2]; int status[2];
char *host_name[2]; char *hname[2];
char *service_description[2]; char *service_description[2];
if(new_sortdata->is_service == TRUE) { if(new_sortdata->is_service == TRUE) {
@ -3069,7 +3036,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
last_check[0] = temp_svcstatus->last_check; last_check[0] = temp_svcstatus->last_check;
next_check[0] = temp_svcstatus->next_check; next_check[0] = temp_svcstatus->next_check;
status[0] = temp_svcstatus->status; status[0] = temp_svcstatus->status;
host_name[0] = temp_svcstatus->host_name; hname[0] = temp_svcstatus->host_name;
service_description[0] = temp_svcstatus->description; service_description[0] = temp_svcstatus->description;
current_attempt[0] = temp_svcstatus->current_attempt; current_attempt[0] = temp_svcstatus->current_attempt;
} }
@ -3078,7 +3045,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
last_check[0] = temp_hststatus->last_check; last_check[0] = temp_hststatus->last_check;
next_check[0] = temp_hststatus->next_check; next_check[0] = temp_hststatus->next_check;
status[0] = temp_hststatus->status; status[0] = temp_hststatus->status;
host_name[0] = temp_hststatus->host_name; hname[0] = temp_hststatus->host_name;
service_description[0] = ""; service_description[0] = "";
current_attempt[0] = temp_hststatus->current_attempt; current_attempt[0] = temp_hststatus->current_attempt;
} }
@ -3087,7 +3054,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
last_check[1] = temp_svcstatus->last_check; last_check[1] = temp_svcstatus->last_check;
next_check[1] = temp_svcstatus->next_check; next_check[1] = temp_svcstatus->next_check;
status[1] = temp_svcstatus->status; status[1] = temp_svcstatus->status;
host_name[1] = temp_svcstatus->host_name; hname[1] = temp_svcstatus->host_name;
service_description[1] = temp_svcstatus->description; service_description[1] = temp_svcstatus->description;
current_attempt[1] = temp_svcstatus->current_attempt; current_attempt[1] = temp_svcstatus->current_attempt;
} }
@ -3096,7 +3063,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
last_check[1] = temp_hststatus->last_check; last_check[1] = temp_hststatus->last_check;
next_check[1] = temp_hststatus->next_check; next_check[1] = temp_hststatus->next_check;
status[1] = temp_hststatus->status; status[1] = temp_hststatus->status;
host_name[1] = temp_hststatus->host_name; hname[1] = temp_hststatus->host_name;
service_description[1] = ""; service_description[1] = "";
current_attempt[1] = temp_hststatus->current_attempt; current_attempt[1] = temp_hststatus->current_attempt;
} }
@ -3128,7 +3095,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
return FALSE; return FALSE;
} }
else if(s_option == SORT_HOSTNAME) { else if(s_option == SORT_HOSTNAME) {
if(strcasecmp(host_name[0], host_name[1]) < 0) if(strcasecmp(hname[0], hname[1]) < 0)
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -3166,7 +3133,7 @@ int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, s
return FALSE; return FALSE;
} }
else if(s_option == SORT_HOSTNAME) { else if(s_option == SORT_HOSTNAME) {
if(strcasecmp(host_name[0], host_name[1]) > 0) if(strcasecmp(hname[0], hname[1]) > 0)
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -3197,4 +3164,3 @@ void free_sortdata_list(void) {
return; return;
} }

View File

@ -2,7 +2,6 @@
* *
* GETCGI.C - Nagios CGI Input Routines * GETCGI.C - Nagios CGI Input Routines
* *
* Last Modified: 05-15-2006
* *
*****************************************/ *****************************************/
@ -112,7 +111,7 @@ void unescape_cgi_input(char *input) {
/* this is a hacked version of a routine I found a long time ago somewhere - can't remember where anymore */ /* this is a hacked version of a routine I found a long time ago somewhere - can't remember where anymore */
char **getcgivars(void) { char **getcgivars(void) {
register int i; register int i;
char *accept_language; char *accept_lang;
char *request_method; char *request_method;
char *content_type; char *content_type;
char *content_length_string; char *content_length_string;
@ -123,13 +122,14 @@ char **getcgivars(void) {
int paircount; int paircount;
char *nvpair; char *nvpair;
char *eqpos; char *eqpos;
char *cookies, *formid;
/* initialize char variable(s) */ /* initialize char variable(s) */
cgiinput = ""; cgiinput = "";
/* Attempt to set the locale */ /* Attempt to set the locale */
accept_language = getenv("HTTP_ACCEPT_LANGUAGE"); accept_lang = getenv("HTTP_ACCEPT_LANGUAGE");
process_language(accept_language); process_language(accept_lang);
/* depending on the request method, read all CGI input into cgiinput */ /* depending on the request method, read all CGI input into cgiinput */
@ -218,7 +218,7 @@ char **getcgivars(void) {
/* first, split on ampersands (&) to extract the name-value pairs into pairlist */ /* first, split on ampersands (&) to extract the name-value pairs into pairlist */
/* allocate memory for 256 name-value pairs at a time, increasing by same /* allocate memory for 256 name-value pairs at a time, increasing by same
amount as necessary... */ amount as necessary... */
pairlist = (char **)malloc(256 * sizeof(char **)); pairlist = (char **)malloc(256 * sizeof(char *));
if(pairlist == NULL) { if(pairlist == NULL) {
printf("getcgivars(): Could not allocate memory for name-value pairlist.\n"); printf("getcgivars(): Could not allocate memory for name-value pairlist.\n");
exit(1); exit(1);
@ -227,13 +227,13 @@ char **getcgivars(void) {
nvpair = strtok(cgiinput, "&"); nvpair = strtok(cgiinput, "&");
while(nvpair) { while(nvpair) {
pairlist[paircount] = strdup(nvpair); pairlist[paircount] = strdup(nvpair);
if(NULL == pairlist[paircount]) { if( NULL == pairlist[paircount]) {
printf("getcgivars(): Could not allocate memory for name-value pair #%d.\n", paircount); printf("getcgivars(): Could not allocate memory for name-value pair #%d.\n", paircount);
exit(1); exit(1);
} }
paircount++; paircount++;
if(!(paircount % 256)) { if(!(paircount % 256)) {
pairlist = (char **)realloc(pairlist, (paircount + 256) * sizeof(char **)); pairlist = (char **)realloc(pairlist, (paircount + 256) * sizeof(char *));
if(pairlist == NULL) { if(pairlist == NULL) {
printf("getcgivars(): Could not re-allocate memory for name-value pairlist.\n"); printf("getcgivars(): Could not re-allocate memory for name-value pairlist.\n");
exit(1); exit(1);
@ -242,11 +242,43 @@ char **getcgivars(void) {
nvpair = strtok(NULL, "&"); nvpair = strtok(NULL, "&");
} }
/* See if there is a NagFormId cookie & get it if it's available */
cookies = getenv("HTTP_COOKIE");
if (cookies && *cookies) {
formid = strstr(cookies, "NagFormId=");
if (formid) {
if(!(paircount % 256)) {
pairlist = (char **)realloc(pairlist, (paircount + 1) * sizeof(char *));
if(pairlist == NULL) {
printf("getcgivars(): Could not re-allocate memory for name-value pairlist.\n");
exit(1);
}
}
formid = strtok(formid, ";");
if (strlen(formid) > 10 && strlen(formid) < 21) {
for (i = strlen(formid) - 1; i > 9; --i)
if (!isxdigit(formid[i]))
break;
if (i == 9) {
pairlist[paircount] = strdup(formid);
if (!pairlist[paircount]) {
printf("getcgivars(): Could not allocate memory for name-value pair #%d.\n", paircount);
exit(1);
}
paircount++;
}
}
}
}
/* terminate the list */ /* terminate the list */
pairlist[paircount] = '\x0'; pairlist[paircount] = '\x0';
/* extract the names and values from the pairlist */ /* extract the names and values from the pairlist */
cgivars = (char **)malloc((paircount * 2 + 1) * sizeof(char **)); cgivars = (char **)malloc((paircount * 2 + 1) * sizeof(char *));
if(cgivars == NULL) { if(cgivars == NULL) {
printf("getcgivars(): Could not allocate memory for name-value list.\n"); printf("getcgivars(): Could not allocate memory for name-value list.\n");
exit(1); exit(1);
@ -257,7 +289,7 @@ char **getcgivars(void) {
if((eqpos = strchr(pairlist[i], '=')) != NULL) { if((eqpos = strchr(pairlist[i], '=')) != NULL) {
*eqpos = '\0'; *eqpos = '\0';
cgivars[i * 2 + 1] = strdup(eqpos + 1); cgivars[i * 2 + 1] = strdup(eqpos + 1);
if(NULL == cgivars[ i * 2 + 1]) { if( NULL == cgivars[ i * 2 + 1]) {
printf("getcgivars(): Could not allocate memory for cgi value #%d.\n", i); printf("getcgivars(): Could not allocate memory for cgi value #%d.\n", i);
exit(1); exit(1);
} }
@ -265,7 +297,7 @@ char **getcgivars(void) {
} }
else { else {
cgivars[i * 2 + 1] = strdup(""); cgivars[i * 2 + 1] = strdup("");
if(NULL == cgivars[ i * 2 + 1]) { if( NULL == cgivars[ i * 2 + 1]) {
printf("getcgivars(): Could not allocate memory for empty stringfor variable value #%d.\n", i); printf("getcgivars(): Could not allocate memory for empty stringfor variable value #%d.\n", i);
exit(1); exit(1);
} }
@ -274,7 +306,7 @@ char **getcgivars(void) {
/* get the variable value (or name/value of there was no real "pair" in the first place) */ /* get the variable value (or name/value of there was no real "pair" in the first place) */
cgivars[i * 2] = strdup(pairlist[i]); cgivars[i * 2] = strdup(pairlist[i]);
if(NULL == cgivars[ i * 2]) { if( NULL == cgivars[ i * 2]) {
printf("getcgivars(): Could not allocate memory for cgi name #%d.\n", i); printf("getcgivars(): Could not allocate memory for cgi name #%d.\n", i);
exit(1); exit(1);
} }
@ -299,43 +331,45 @@ char **getcgivars(void) {
/* Set the locale based on the HTTP_ACCEPT_LANGUAGE variable value sent by /* Set the locale based on the HTTP_ACCEPT_LANGUAGE variable value sent by
the browser */ the browser */
void process_language(char * accept_language) { void process_language( char * accept_lang) {
accept_languages *accept_langs = NULL; accept_languages *accept_langs = NULL;
int x; int x;
char locale_string[ 64]; char locale_string[ 64];
char * locale = NULL; char * locale = NULL;
char * locale_failsafe[] = { "en_US.utf8", "POSIX", "C" }; char * locale_failsafe[] = { "en_US.utf8", "POSIX", "C" };
if(accept_language != NULL) { if( accept_lang != NULL) {
accept_langs = parse_accept_languages(accept_language); accept_langs = parse_accept_languages( accept_lang);
}
if(NULL != accept_langs) {
/* Sort the results */
qsort(accept_langs->languages, accept_langs->count,
sizeof(accept_langs->languages[ 0]), compare_accept_languages);
/* Try each language in order of priority */
for(x = 0; ((x < accept_langs->count) && (NULL == locale)); x++) {
snprintf(locale_string, sizeof(locale_string), "%s_%s.%s",
accept_langs->languages[ x]->language,
accept_langs->languages[ x]->locality, "utf8");
locale = setlocale(LC_CTYPE, locale_string);
if(NULL != locale) break;
}
free_accept_languages(accept_langs);
}
if(NULL == locale) { /* Still isn't set */
/* Try the fail safe locales */
for(x = 0; ((x < (sizeof(locale_failsafe) / sizeof(char *))) &&
(NULL == locale)); x++) {
locale = setlocale(LC_CTYPE, locale_failsafe[ x]);
}
}
} }
accept_languages * parse_accept_languages(char * acceptlang) { if( NULL != accept_langs) {
/* Sort the results */
qsort( accept_langs->languages, accept_langs->count,
sizeof( accept_langs->languages[ 0]), compare_accept_languages);
/* Try each language in order of priority */
for( x = 0; (( x < accept_langs->count) && ( NULL == locale)); x++) {
accept_language *l;
l = accept_langs->languages[x];
if (!l || !l->locality || !l->language)
continue;
snprintf( locale_string, sizeof( locale_string), "%s_%s.%s",
l->language, l->locality, "utf8");
locale = setlocale( LC_ALL, locale_string);
}
free_accept_languages( accept_langs);
}
if( NULL == locale) { /* Still isn't set */
/* Try the fail safe locales */
for( x = 0; (( x < (int)( sizeof( locale_failsafe) / sizeof( char *))) &&
( NULL == locale)); x++) {
locale = setlocale( LC_ALL, locale_failsafe[ x]);
}
}
}
accept_languages * parse_accept_languages( char * acceptlang) {
char * langdup; /* Duplicate of accept language for parsing */ char * langdup; /* Duplicate of accept language for parsing */
accept_languages *langs = NULL; accept_languages *langs = NULL;
char * langtok; /* Language token (language + locality + q value) */ char * langtok; /* Language token (language + locality + q value) */
@ -347,164 +381,164 @@ accept_languages * parse_accept_languages(char * acceptlang) {
/* If the browser did not pass an HTTP_ACCEPT_LANGUAGE variable, there /* If the browser did not pass an HTTP_ACCEPT_LANGUAGE variable, there
is not much we can do */ is not much we can do */
if(NULL == acceptlang) { if( NULL == acceptlang) {
return NULL; return NULL;
} }
/* Duplicate the browser supplied HTTP_ACCEPT_LANGUAGE variable */ /* Duplicate the browser supplied HTTP_ACCEPT_LANGUAGE variable */
if(NULL == (langdup = strdup(acceptlang))) { if( NULL == ( langdup = strdup( acceptlang))) {
printf("Unable to allocate memory for langdup\n"); printf( "Unable to allocate memory for langdup\n");
return NULL; return NULL;
} }
/* Initialize the structure to contain the parsed HTTP_ACCEPT_LANGUAGE /* Initialize the structure to contain the parsed HTTP_ACCEPT_LANGUAGE
information */ information */
if(NULL == (langs = malloc(sizeof(accept_languages)))) { if( NULL == ( langs = malloc( sizeof( accept_languages)))) {
printf("Unable to allocate memory for langs\n"); printf( "Unable to allocate memory for langs\n");
free(langdup); free( langdup);
return NULL; return NULL;
} }
langs->count = 0; langs->count = 0;
langs->languages = (accept_language **)NULL; langs->languages = ( accept_language **)NULL;
/* Tokenize the HTTP_ACCEPT_LANGUAGE string */ /* Tokenize the HTTP_ACCEPT_LANGUAGE string */
langtok = strtok_r(langdup, ",", &saveptr); langtok = strtok_r( langdup, ",", &saveptr);
while(langtok != NULL) { while( langtok != NULL) {
/* Bump the count and allocate memory for structures */ /* Bump the count and allocate memory for structures */
langs->count++; langs->count++;
if(NULL == langs->languages) { if( NULL == langs->languages) {
/* Adding first language */ /* Adding first language */
if(NULL == (langs->languages = if( NULL == ( langs->languages =
malloc(langs->count * sizeof(accept_language *)))) { malloc( langs->count * sizeof( accept_language *)))) {
printf("Unable to allocate memory for first language\n"); printf( "Unable to allocate memory for first language\n");
langs->count--; langs->count--;
free_accept_languages(langs); free_accept_languages( langs);
free(langdup); free( langdup);
return NULL; return NULL;
}
} }
}
else { else {
/* Adding additional language */ /* Adding additional language */
if(NULL == (langs->languages = realloc(langs->languages, if( NULL == ( langs->languages = realloc( langs->languages,
langs->count * sizeof(accept_language *)))) { langs->count * sizeof( accept_language *)))) {
printf("Unable to allocate memory for additional language\n"); printf( "Unable to allocate memory for additional language\n");
langs->count--; langs->count--;
free_accept_languages(langs); free_accept_languages( langs);
free(langdup); free( langdup);
return NULL; return NULL;
}
} }
if(NULL == (langs->languages[ langs->count - 1] = }
malloc(sizeof(accept_language)))) { if( NULL == ( langs->languages[ langs->count - 1] =
printf("Unable to allocate memory for language\n"); malloc( sizeof( accept_language)))) {
printf( "Unable to allocate memory for language\n");
langs->count--; langs->count--;
free_accept_languages(langs); free_accept_languages( langs);
free(langdup); free( langdup);
return NULL; return NULL;
} }
langs->languages[ langs->count - 1]->language = (char *)NULL; langs->languages[ langs->count - 1]->language = ( char *)NULL;
langs->languages[ langs->count - 1]->locality = (char *)NULL; langs->languages[ langs->count - 1]->locality = ( char *)NULL;
langs->languages[ langs->count - 1]->q = 1.0; langs->languages[ langs->count - 1]->q = 1.0;
/* Check to see if there is a q value */ /* Check to see if there is a q value */
qdelim = strstr(langtok, ACCEPT_LANGUAGE_Q_DELIMITER); qdelim = strstr( langtok, ACCEPT_LANGUAGE_Q_DELIMITER);
if(NULL != qdelim) { /* found a q value */ if( NULL != qdelim) { /* found a q value */
langs->languages[ langs->count - 1]->q = langs->languages[ langs->count - 1]->q =
strtod(qdelim + strlen(ACCEPT_LANGUAGE_Q_DELIMITER), NULL); strtod( qdelim + strlen( ACCEPT_LANGUAGE_Q_DELIMITER), NULL);
langtok[ qdelim - langtok] = '\0'; langtok[ qdelim - langtok] = '\0';
} }
/* Check to see if there is a locality specifier */ /* Check to see if there is a locality specifier */
if(NULL == (localitydelim = strchr(langtok, '-'))) { if( NULL == ( localitydelim = strchr( langtok, '-'))) {
localitydelim = strchr(langtok, '_'); localitydelim = strchr( langtok, '_');
}
if( NULL != localitydelim) {
/* We have a locality delimiter, so copy it */
if( NULL == ( langs->languages[ langs->count - 1]->locality =
strdup( localitydelim + 1))) {
printf( "Unable to allocate memory for locality '%s'\n",
langtok);
free_accept_languages( langs);
free( langdup);
return NULL;
} }
if(NULL != localitydelim) {
/* We have a locality delimiter, so copy it */
if(NULL == (langs->languages[ langs->count - 1]->locality =
strdup(localitydelim + 1))) {
printf("Unable to allocate memory for locality '%s'\n",
langtok);
free_accept_languages(langs);
free(langdup);
return NULL;
}
/* Ensure it is upper case */ /* Ensure it is upper case */
for(x = 0, stp = langs->languages[ langs->count - 1]->locality; for( x = 0, stp = langs->languages[ langs->count - 1]->locality;
x < strlen(langs->languages[ langs->count - 1]->locality); x < (int)strlen( langs->languages[ langs->count - 1]->locality);
x++, stp++) { x++, stp++) {
*stp = toupper(*stp); *stp = toupper( *stp);
} }
/* Then null out the delimiter so the language copy works */ /* Then null out the delimiter so the language copy works */
*localitydelim = '\0'; *localitydelim = '\0';
} }
if(NULL == (langs->languages[ langs->count - 1]->language = if( NULL == ( langs->languages[ langs->count - 1]->language =
strdup(langtok))) { strdup( langtok))) {
printf("Unable to allocate memory for language '%s'\n", printf( "Unable to allocate memory for language '%s'\n",
langtok); langtok);
free_accept_languages(langs); free_accept_languages( langs);
free(langdup); free( langdup);
return NULL; return NULL;
} }
/* Get the next language token */ /* Get the next language token */
langtok = strtok_r(NULL, ",", &saveptr); langtok = strtok_r( NULL, ",", &saveptr);
}
free(langdup);
return langs;
} }
int compare_accept_languages(const void *p1, const void *p2) { free( langdup);
accept_language * lang1 = *(accept_language **)p1; return langs;
accept_language * lang2 = *(accept_language **)p2; }
if(lang1->q == lang2->q) { int compare_accept_languages( const void *p1, const void *p2) {
if(((NULL == lang1->locality) && (NULL == lang2->locality)) || accept_language * lang1 = *( accept_language **)p1;
((NULL != lang1->locality) && (NULL != lang2->locality))) { accept_language * lang2 = *( accept_language **)p2;
if( lang1->q == lang2->q) {
if((( NULL == lang1->locality) && ( NULL == lang2->locality)) ||
(( NULL != lang1->locality) && ( NULL != lang2->locality))) {
return 0; return 0;
} }
else if(NULL != lang1->locality) { else if( NULL != lang1->locality) {
return -1; return -1;
} }
else { /* NULL != lang2->locality */ else { /* NULL != lang2->locality */
return 1; return 1;
}
}
else {
return(lang2->q > lang1->q);
} }
} }
else {
return( lang2->q > lang1->q);
}
}
void free_accept_languages(accept_languages * langs) { void free_accept_languages( accept_languages * langs) {
int x; int x;
if(NULL == langs) { if( NULL == langs) {
return; return;
} }
for(x = 0; x < langs->count; x++) { for( x = 0; x < langs->count; x++) {
if(NULL != langs->languages[ x]) { if( NULL != langs->languages[ x]) {
if(langs->languages[ x]->language != NULL) { if( langs->languages[ x]->language != NULL) {
free(langs->languages[ x]->language); free( langs->languages[ x]->language);
}
if(langs->languages[ x]->locality != NULL) {
free(langs->languages[ x]->locality);
}
free(langs->languages[ x]);
} }
if( langs->languages[ x]->locality != NULL) {
free( langs->languages[ x]->locality);
}
free( langs->languages[ x]);
} }
if(langs->languages != NULL) { }
free(langs->languages); if( langs->languages != NULL) {
} free( langs->languages);
free(langs); }
free( langs);
return; return;
} }
/* free() memory allocated to storing the CGI variables */ /* free() memory allocated to storing the CGI variables */
void free_cgivars(char **cgivars) { void free_cgivars(char **cgivars) {

View File

@ -2,8 +2,6 @@
* *
* HISTOGRAM.C - Nagios Alert Histogram CGI * HISTOGRAM.C - Nagios Alert Histogram CGI
* *
* Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-15-2008
* *
* License: * License:
* *
@ -129,13 +127,7 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char physical_images_path[MAX_FILENAME_LENGTH]; extern char physical_images_path[MAX_FILENAME_LENGTH];
extern char *status_file;
extern int log_rotation_method;
extern host *host_list;
extern service *service_list;
authdata current_authdata; authdata current_authdata;
@ -257,6 +249,9 @@ int main(int argc, char **argv) {
/* reset internal CGI variables */ /* reset internal CGI variables */
reset_cgi_vars(); reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* read the CGI configuration file */ /* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location()); result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) { if(result == ERROR) {
@ -291,7 +286,7 @@ int main(int argc, char **argv) {
} }
/* read all status data */ /* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) { if(result == ERROR) {
if(mode == CREATE_HTML) { if(mode == CREATE_HTML) {
document_header(FALSE); document_header(FALSE);
@ -400,7 +395,11 @@ int main(int argc, char **argv) {
/* right hand column of top row */ /* right hand column of top row */
printf("<td align=right valign=bottom width=33%%>\n"); printf("<td align=right valign=bottom width=33%%>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI); printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_HISTOGRAM_CGI);
#endif
printf("<table border=0 CLASS='optBox'>\n"); printf("<table border=0 CLASS='optBox'>\n");
if(display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) { if(display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) {
@ -548,7 +547,11 @@ int main(int argc, char **argv) {
printf("<BR><BR>\n"); printf("<BR><BR>\n");
printf("<DIV ALIGN=CENTER>\n"); printf("<DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", HISTOGRAM_CGI, (unsigned long)t1, (unsigned long)t2); printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", HISTOGRAM_CGI, (unsigned long)t1, (unsigned long)t2);
#else
printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", LEGACY_HISTOGRAM_CGI, (unsigned long)t1, (unsigned long)t2);
#endif
printf("&host=%s", url_encode(host_name)); printf("&host=%s", url_encode(host_name));
if(display_type == DISPLAY_SERVICE_HISTOGRAM) if(display_type == DISPLAY_SERVICE_HISTOGRAM)
printf("&service=%s", url_encode(svc_description)); printf("&service=%s", url_encode(svc_description));
@ -686,7 +689,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI); printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_HISTOGRAM_CGI);
#endif
printf("<input type='hidden' name='input' value='getoptions'>\n"); printf("<input type='hidden' name='input' value='getoptions'>\n");
printf("<TABLE BORDER=0 cellspacing=0 cellpadding=10>\n"); printf("<TABLE BORDER=0 cellspacing=0 cellpadding=10>\n");
@ -742,7 +749,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", HISTOGRAM_CGI); printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", HISTOGRAM_CGI);
#else
printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", LEGACY_HISTOGRAM_CGI);
#endif
printf("<input type='hidden' name='input' value='getoptions'>\n"); printf("<input type='hidden' name='input' value='getoptions'>\n");
printf("<input type='hidden' name='host' value='%s'>\n", (first_service == NULL) ? "unknown" : (char *)escape_string(first_service)); printf("<input type='hidden' name='host' value='%s'>\n", (first_service == NULL) ? "unknown" : (char *)escape_string(first_service));
@ -786,7 +797,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI); printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_HISTOGRAM_CGI);
#endif
printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name)); printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name));
if(display_type == DISPLAY_SERVICE_HISTOGRAM) if(display_type == DISPLAY_SERVICE_HISTOGRAM)
printf("<input type='hidden' name='service' value='%s'>\n", escape_string(svc_description)); printf("<input type='hidden' name='service' value='%s'>\n", escape_string(svc_description));
@ -944,7 +959,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI); printf("<form method=\"GET\" action=\"%s\">\n", HISTOGRAM_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_HISTOGRAM_CGI);
#endif
printf("<TABLE BORDER=0 cellpadding=5>\n"); printf("<TABLE BORDER=0 cellpadding=5>\n");
printf("<tr><td class='reportSelectSubTitle' align=right>Type:</td>\n"); printf("<tr><td class='reportSelectSubTitle' align=right>Type:</td>\n");
printf("<td class='reportSelectItem'>\n"); printf("<td class='reportSelectItem'>\n");
@ -992,7 +1011,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -1014,7 +1033,11 @@ void document_header(int use_stylesheet) {
printf("<BODY CLASS='histogram'>\n"); printf("<BODY CLASS='histogram'>\n");
/* include user SSI header */ /* include user SSI header */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(HISTOGRAM_CGI, SSI_HEADER); include_ssi_files(HISTOGRAM_CGI, SSI_HEADER);
#else
include_ssi_files(LEGACY_HISTOGRAM_CGI, SSI_HEADER);
#endif
printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n"); printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n");
} }
@ -1047,7 +1070,11 @@ void document_footer(void) {
if(mode == CREATE_HTML) { if(mode == CREATE_HTML) {
/* include user SSI footer */ /* include user SSI footer */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(HISTOGRAM_CGI, SSI_FOOTER); include_ssi_files(HISTOGRAM_CGI, SSI_FOOTER);
#else
include_ssi_files(LEGACY_HISTOGRAM_CGI, SSI_FOOTER);
#endif
printf("</body>\n"); printf("</body>\n");
printf("</html>\n"); printf("</html>\n");
@ -1069,7 +1096,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }

View File

@ -2,8 +2,6 @@
* *
* HISTORY.C - Nagios History CGI * HISTORY.C - Nagios History CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 06-23-2008
* *
* This CGI program will display the history for the specified host. * This CGI program will display the history for the specified host.
* If no host is specified, the history for all hosts will be displayed. * If no host is specified, the history for all hosts will be displayed.
@ -57,8 +55,6 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int log_rotation_method;
extern int enable_splunk_integration; extern int enable_splunk_integration;
authdata current_authdata; authdata current_authdata;
@ -85,7 +81,6 @@ int display_downtime_alerts = TRUE;
int main(void) { int main(void) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
char temp_buffer2[MAX_INPUT_BUFFER]; char temp_buffer2[MAX_INPUT_BUFFER];
@ -95,32 +90,7 @@ int main(void) {
/* reset internal CGI variables */ /* reset internal CGI variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, 0);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
document_header(TRUE); document_header(TRUE);
@ -315,7 +285,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -805,22 +775,22 @@ void get_history(void) {
else if(display_type == DISPLAY_HOSTS) { else if(display_type == DISPLAY_HOSTS) {
if(history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) { if(history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) {
snprintf(match1, sizeof(match1), snprintf(match1, sizeof( match1),
" HOST ALERT: %s;", host_name); " HOST ALERT: %s;", host_name);
snprintf(match2, sizeof(match2), snprintf(match2, sizeof( match2),
" SERVICE ALERT: %s;", host_name); " SERVICE ALERT: %s;", host_name);
} }
else if(history_type == HOST_FLAPPING_HISTORY || history_type == SERVICE_FLAPPING_HISTORY) { else if(history_type == HOST_FLAPPING_HISTORY || history_type == SERVICE_FLAPPING_HISTORY) {
snprintf(match1, sizeof(match1), snprintf(match1, sizeof( match1),
" HOST FLAPPING ALERT: %s;", host_name); " HOST FLAPPING ALERT: %s;", host_name);
snprintf(match2, sizeof(match2), snprintf(match2, sizeof( match2),
" SERVICE FLAPPING ALERT: %s;", host_name); " SERVICE FLAPPING ALERT: %s;", host_name);
} }
else if(history_type == HOST_DOWNTIME_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY) { else if(history_type == HOST_DOWNTIME_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY) {
snprintf(match1, sizeof(match1), snprintf(match1, sizeof( match1),
" HOST DOWNTIME ALERT: %s;", host_name); " HOST DOWNTIME ALERT: %s;", host_name);
snprintf(match2, sizeof(match2), snprintf(match2, sizeof( match2),
" SERVICE DOWNTIME ALERT: %s;", host_name); " SERVICE DOWNTIME ALERT: %s;", host_name);
} }
if(show_all_hosts == TRUE) if(show_all_hosts == TRUE)
@ -859,11 +829,11 @@ void get_history(void) {
else if(display_type == DISPLAY_SERVICES) { else if(display_type == DISPLAY_SERVICES) {
if(history_type == SERVICE_HISTORY) if(history_type == SERVICE_HISTORY)
snprintf(match1, sizeof(match1), " SERVICE ALERT: %s;%s;", host_name, svc_description); snprintf(match1, sizeof( match1), " SERVICE ALERT: %s;%s;", host_name, svc_description);
else if(history_type == SERVICE_FLAPPING_HISTORY) else if(history_type == SERVICE_FLAPPING_HISTORY)
snprintf(match1, sizeof(match1), " SERVICE FLAPPING ALERT: %s;%s;", host_name, svc_description); snprintf(match1, sizeof( match1), " SERVICE FLAPPING ALERT: %s;%s;", host_name, svc_description);
else if(history_type == SERVICE_DOWNTIME_HISTORY) else if(history_type == SERVICE_DOWNTIME_HISTORY)
snprintf(match1, sizeof(match1), " SERVICE DOWNTIME ALERT: %s;%s;", host_name, svc_description); snprintf(match1, sizeof( match1), " SERVICE DOWNTIME ALERT: %s;%s;", host_name, svc_description);
if(strstr(temp_buffer, match1) && (history_type == SERVICE_HISTORY || history_type == SERVICE_FLAPPING_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY)) if(strstr(temp_buffer, match1) && (history_type == SERVICE_HISTORY || history_type == SERVICE_FLAPPING_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY))
display_line = TRUE; display_line = TRUE;

1483
cgi/jsonutils.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@
* *
* NOTIFICATIONS.C - Nagios Notifications CGI * NOTIFICATIONS.C - Nagios Notifications CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 01-08-2008
* *
* This CGI program will display the notification events for * This CGI program will display the notification events for
* a given host or contact or for all contacts/hosts. * a given host or contact or for all contacts/hosts.
@ -37,8 +35,6 @@ extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_docs_path[MAX_FILENAME_LENGTH]; extern char url_docs_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int log_rotation_method;
#define FIND_HOST 1 #define FIND_HOST 1
#define FIND_CONTACT 2 #define FIND_CONTACT 2
@ -77,7 +73,6 @@ int display_header = TRUE;
int main(void) { int main(void) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
char temp_buffer2[MAX_INPUT_BUFFER]; char temp_buffer2[MAX_INPUT_BUFFER];
@ -88,33 +83,7 @@ int main(void) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, 0);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
document_header(TRUE); document_header(TRUE);
@ -238,6 +207,7 @@ int main(void) {
printf("<option value=%d %s>Service critical\n", NOTIFICATION_SERVICE_CRITICAL, (notification_options == NOTIFICATION_SERVICE_CRITICAL) ? "selected" : ""); printf("<option value=%d %s>Service critical\n", NOTIFICATION_SERVICE_CRITICAL, (notification_options == NOTIFICATION_SERVICE_CRITICAL) ? "selected" : "");
printf("<option value=%d %s>Service recovery\n", NOTIFICATION_SERVICE_RECOVERY, (notification_options == NOTIFICATION_SERVICE_RECOVERY) ? "selected" : ""); printf("<option value=%d %s>Service recovery\n", NOTIFICATION_SERVICE_RECOVERY, (notification_options == NOTIFICATION_SERVICE_RECOVERY) ? "selected" : "");
printf("<option value=%d %s>Service flapping\n", NOTIFICATION_SERVICE_FLAP, (notification_options == NOTIFICATION_SERVICE_FLAP) ? "selected" : ""); printf("<option value=%d %s>Service flapping\n", NOTIFICATION_SERVICE_FLAP, (notification_options == NOTIFICATION_SERVICE_FLAP) ? "selected" : "");
printf("<option value=%d %s>Service downtime\n", NOTIFICATION_SERVICE_DOWNTIME, (notification_options == NOTIFICATION_SERVICE_DOWNTIME) ? "selected" : "");
if(query_type != FIND_SERVICE) { if(query_type != FIND_SERVICE) {
printf("<option value=%d %s>Host custom\n", NOTIFICATION_HOST_CUSTOM, (notification_options == NOTIFICATION_HOST_CUSTOM) ? "selected" : ""); printf("<option value=%d %s>Host custom\n", NOTIFICATION_HOST_CUSTOM, (notification_options == NOTIFICATION_HOST_CUSTOM) ? "selected" : "");
printf("<option value=%d %s>Host acknowledgements\n", NOTIFICATION_HOST_ACK, (notification_options == NOTIFICATION_HOST_ACK) ? "selected" : ""); printf("<option value=%d %s>Host acknowledgements\n", NOTIFICATION_HOST_ACK, (notification_options == NOTIFICATION_HOST_ACK) ? "selected" : "");
@ -245,6 +215,7 @@ int main(void) {
printf("<option value=%d %s>Host unreachable\n", NOTIFICATION_HOST_UNREACHABLE, (notification_options == NOTIFICATION_HOST_UNREACHABLE) ? "selected" : ""); printf("<option value=%d %s>Host unreachable\n", NOTIFICATION_HOST_UNREACHABLE, (notification_options == NOTIFICATION_HOST_UNREACHABLE) ? "selected" : "");
printf("<option value=%d %s>Host recovery\n", NOTIFICATION_HOST_RECOVERY, (notification_options == NOTIFICATION_HOST_RECOVERY) ? "selected" : ""); printf("<option value=%d %s>Host recovery\n", NOTIFICATION_HOST_RECOVERY, (notification_options == NOTIFICATION_HOST_RECOVERY) ? "selected" : "");
printf("<option value=%d %s>Host flapping\n", NOTIFICATION_HOST_FLAP, (notification_options == NOTIFICATION_HOST_FLAP) ? "selected" : ""); printf("<option value=%d %s>Host flapping\n", NOTIFICATION_HOST_FLAP, (notification_options == NOTIFICATION_HOST_FLAP) ? "selected" : "");
printf("<option value=%d %s>Host downtime\n", NOTIFICATION_HOST_DOWNTIME, (notification_options == NOTIFICATION_HOST_DOWNTIME) ? "selected" : "");
} }
printf("</select></td>\n"); printf("</select></td>\n");
printf("</tr>\n"); printf("</tr>\n");
@ -303,7 +274,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -358,7 +329,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -619,6 +589,10 @@ void display_notifications(void) {
notification_detail_type = NOTIFICATION_SERVICE_FLAP; notification_detail_type = NOTIFICATION_SERVICE_FLAP;
strcpy(alert_level_class, "UNKNOWN"); strcpy(alert_level_class, "UNKNOWN");
} }
else if(strstr(alert_level, "DOWNTIME")) {
notification_detail_type = NOTIFICATION_SERVICE_DOWNTIME;
strcpy(alert_level_class, "DOWNTIME");
}
else { else {
strcpy(alert_level, "UNKNOWN"); strcpy(alert_level, "UNKNOWN");
notification_detail_type = NOTIFICATION_SERVICE_UNKNOWN; notification_detail_type = NOTIFICATION_SERVICE_UNKNOWN;
@ -661,6 +635,10 @@ void display_notifications(void) {
strcpy(alert_level_class, "UNKNOWN"); strcpy(alert_level_class, "UNKNOWN");
notification_detail_type = NOTIFICATION_HOST_FLAP; notification_detail_type = NOTIFICATION_HOST_FLAP;
} }
else if(strstr(alert_level, "DOWNTIME")) {
strcpy(alert_level_class, "DOWNTIME");
notification_detail_type = NOTIFICATION_HOST_DOWNTIME;
}
} }
/* get the method name */ /* get the method name */

6027
cgi/objectjson.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@
* *
* OUTAGES.C - Nagios Network Outages CGI * OUTAGES.C - Nagios Network Outages CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 01-08-2008
* *
* License: * License:
* *
@ -32,10 +30,7 @@
#include "../include/cgiauth.h" #include "../include/cgiauth.h"
extern int refresh_rate; extern int refresh_rate;
extern time_t program_start;
extern host *host_list;
extern service *service_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
@ -44,7 +39,6 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char log_file[MAX_FILENAME_LENGTH];
/* HOSTOUTAGE structure */ /* HOSTOUTAGE structure */
@ -101,51 +95,13 @@ int display_header = TRUE;
int main(void) { int main(void) {
int result = OK;
/* get the arguments passed in the URL */ /* get the arguments passed in the URL */
process_cgivars(); process_cgivars();
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, READ_ALL_STATUS_DATA);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
/* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
if(result == ERROR) {
document_header(FALSE);
status_data_error();
document_footer();
free_memory();
return ERROR;
}
document_header(TRUE); document_header(TRUE);
@ -215,7 +171,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -269,7 +225,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -313,8 +268,8 @@ void display_network_outages(void) {
hostoutage *temp_hostoutage; hostoutage *temp_hostoutage;
hoststatus *temp_hoststatus; hoststatus *temp_hoststatus;
int odd = 0; int odd = 0;
char *bg_class = ""; const char *bg_class = "";
char *status = ""; const char *status = "";
int days; int days;
int hours; int hours;
int minutes; int minutes;
@ -326,6 +281,7 @@ void display_network_outages(void) {
int total_entries = 0; int total_entries = 0;
/* user must be authorized for all hosts.. */ /* user must be authorized for all hosts.. */
/*
if(is_authorized_for_all_hosts(&current_authdata) == FALSE) { if(is_authorized_for_all_hosts(&current_authdata) == FALSE) {
printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information you requested...</DIV></P>\n"); printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information you requested...</DIV></P>\n");
@ -334,6 +290,7 @@ void display_network_outages(void) {
return; return;
} }
*/
/* find all hosts that are causing network outages */ /* find all hosts that are causing network outages */
find_hosts_causing_outages(); find_hosts_causing_outages();
@ -375,7 +332,7 @@ void display_network_outages(void) {
continue; continue;
/* make sure we only caught valid state types */ /* make sure we only caught valid state types */
if(temp_hoststatus->status != HOST_DOWN && temp_hoststatus->status != HOST_UNREACHABLE) if(temp_hoststatus->status != SD_HOST_DOWN && temp_hoststatus->status != SD_HOST_UNREACHABLE)
continue; continue;
total_entries++; total_entries++;
@ -389,9 +346,9 @@ void display_network_outages(void) {
bg_class = "dataEven"; bg_class = "dataEven";
} }
if(temp_hoststatus->status == HOST_UNREACHABLE) if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
status = "UNREACHABLE"; status = "UNREACHABLE";
else if(temp_hoststatus->status == HOST_DOWN) else if(temp_hoststatus->status == SD_HOST_DOWN)
status = "DOWN"; status = "DOWN";
printf("<TR CLASS='%s'>\n", bg_class); printf("<TR CLASS='%s'>\n", bg_class);
@ -469,7 +426,7 @@ void find_hosts_causing_outages(void) {
for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) { for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* check only hosts that are not up and not pending */ /* check only hosts that are not up and not pending */
if(temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) { if(temp_hoststatus->status != SD_HOST_UP && temp_hoststatus->status != HOST_PENDING) {
/* find the host entry */ /* find the host entry */
temp_host = find_host(temp_hoststatus->host_name); temp_host = find_host(temp_hoststatus->host_name);
@ -477,6 +434,9 @@ void find_hosts_causing_outages(void) {
if(temp_host == NULL) if(temp_host == NULL)
continue; continue;
if (!is_authorized_for_host(temp_host, &current_authdata))
continue;
/* if the route to this host is not blocked, it is a causing an outage */ /* if the route to this host is not blocked, it is a causing an outage */
if(is_route_to_host_blocked(temp_host) == FALSE) if(is_route_to_host_blocked(temp_host) == FALSE)
add_hostoutage(temp_host); add_hostoutage(temp_host);
@ -622,7 +582,7 @@ int is_route_to_host_blocked(host *hst) {
continue; continue;
/* at least one parent it up (or pending), so this host is not blocked */ /* at least one parent it up (or pending), so this host is not blocked */
if(temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING) if(temp_hoststatus->status == SD_HOST_UP || temp_hoststatus->status == HOST_PENDING)
return FALSE; return FALSE;
} }

View File

@ -2,8 +2,6 @@
* *
* SHOWLOG.C - Nagios Log File CGI * SHOWLOG.C - Nagios Log File CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 01-08-2008
* *
* This CGI program will display the contents of the Nagios * This CGI program will display the contents of the Nagios
* log file. * log file.
@ -37,8 +35,6 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int log_rotation_method;
extern int enable_splunk_integration; extern int enable_splunk_integration;
void document_header(int); void document_header(int);
@ -61,7 +57,6 @@ int display_timebreaks = TRUE;
int main(void) { int main(void) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
@ -71,33 +66,7 @@ int main(void) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, 0);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
document_header(TRUE); document_header(TRUE);
@ -188,7 +157,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -547,4 +516,3 @@ int display_log(void) {
return OK; return OK;
} }

File diff suppressed because it is too large Load Diff

4962
cgi/statusjson.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,6 @@
* *
* STATUSMAP.C - Nagios Network Status Map CGI * STATUSMAP.C - Nagios Network Status Map CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 05-19-2008
* *
* Description: * Description:
* *
@ -55,10 +53,8 @@ extern char physical_images_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char *status_file;
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
@ -95,10 +91,10 @@ extern int default_statusmap_layout_method;
#define LAYOUT_CIRCULAR_BALLOON 6 #define LAYOUT_CIRCULAR_BALLOON 6
typedef struct layer_struct { struct layer {
char *layer_name; char *layer_name;
struct layer_struct *next; struct layer *next;
} layer; };
void document_header(int); void document_header(int);
@ -222,9 +218,7 @@ int nagios_icon_y = 0;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern time_t program_start; struct layer *layer_list = NULL;
layer *layer_list = NULL;
int exclude_layers = TRUE; int exclude_layers = TRUE;
int all_layers = FALSE; int all_layers = FALSE;
@ -240,6 +234,9 @@ int main(int argc, char **argv) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* read the CGI configuration file */ /* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location()); result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) { if(result == ERROR) {
@ -277,7 +274,7 @@ int main(int argc, char **argv) {
} }
/* read all status data */ /* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) { if(result == ERROR) {
document_header(FALSE); document_header(FALSE);
if(create_type == CREATE_HTML) if(create_type == CREATE_HTML)
@ -328,7 +325,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-Type: text/html\r\n\r\n"); printf("Content-Type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -353,7 +350,11 @@ void document_header(int use_stylesheet) {
printf("<body CLASS='statusmap' name='mappage' id='mappage'>\n"); printf("<body CLASS='statusmap' name='mappage' id='mappage'>\n");
/* include user SSI header */ /* include user SSI header */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(STATUSMAP_CGI, SSI_HEADER); include_ssi_files(STATUSMAP_CGI, SSI_HEADER);
#else
include_ssi_files(LEGACY_STATUSMAP_CGI, SSI_HEADER);
#endif
printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n"); printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n");
} }
@ -385,7 +386,11 @@ void document_footer(void) {
if(create_type == CREATE_HTML) { if(create_type == CREATE_HTML) {
/* include user SSI footer */ /* include user SSI footer */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(STATUSMAP_CGI, SSI_FOOTER); include_ssi_files(STATUSMAP_CGI, SSI_FOOTER);
#else
include_ssi_files(LEGACY_STATUSMAP_CGI, SSI_FOOTER);
#endif
printf("</body>\n"); printf("</body>\n");
printf("</html>\n"); printf("</html>\n");
@ -407,7 +412,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -603,7 +607,7 @@ void display_page_header(void) {
int zoom_height_granularity = 0; int zoom_height_granularity = 0;
int current_zoom_granularity = 0; int current_zoom_granularity = 0;
hostgroup *temp_hostgroup; hostgroup *temp_hostgroup;
layer *temp_layer; struct layer *temp_layer;
int found = 0; int found = 0;
@ -630,7 +634,11 @@ void display_page_header(void) {
printf("<TR><TD CLASS='linkBox'>\n"); printf("<TR><TD CLASS='linkBox'>\n");
if(show_all_hosts == FALSE) { if(show_all_hosts == FALSE) {
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<a href='%s?host=all&max_width=%d&max_height=%d'>View Status Map For All Hosts</a><BR>", STATUSMAP_CGI, max_image_width, max_image_height); printf("<a href='%s?host=all&max_width=%d&max_height=%d'>View Status Map For All Hosts</a><BR>", STATUSMAP_CGI, max_image_width, max_image_height);
#else
printf("<a href='%s?host=all&max_width=%d&max_height=%d'>View Status Map For All Hosts</a><BR>", LEGACY_STATUSMAP_CGI, max_image_width, max_image_height);
#endif
printf("<a href='%s?host=%s'>View Status Detail For This Host</a><BR>\n", STATUS_CGI, url_encode(host_name)); printf("<a href='%s?host=%s'>View Status Detail For This Host</a><BR>\n", STATUS_CGI, url_encode(host_name));
} }
printf("<a href='%s?host=all'>View Status Detail For All Hosts</a><BR>\n", STATUS_CGI); printf("<a href='%s?host=all'>View Status Detail For All Hosts</a><BR>\n", STATUS_CGI);
@ -683,7 +691,11 @@ void display_page_header(void) {
zoom_width = total_image_width - (zoom * zoom_width_granularity); zoom_width = total_image_width - (zoom * zoom_width_granularity);
zoom_height = total_image_height - (zoom * zoom_height_granularity); zoom_height = total_image_height - (zoom * zoom_height_granularity);
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<td valign=center><a href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s", STATUSMAP_CGI, url_encode(host_name), layout_method, max_image_width, max_image_height, zoom_width, zoom_height, (display_header == TRUE) ? "" : "&noheader", (display_popups == FALSE) ? "&nopopups" : ""); printf("<td valign=center><a href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s", STATUSMAP_CGI, url_encode(host_name), layout_method, max_image_width, max_image_height, zoom_width, zoom_height, (display_header == TRUE) ? "" : "&noheader", (display_popups == FALSE) ? "&nopopups" : "");
#else
printf("<td valign=center><a href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s", LEGACY_STATUSMAP_CGI, url_encode(host_name), layout_method, max_image_width, max_image_height, zoom_width, zoom_height, (display_header == TRUE) ? "" : "&noheader", (display_popups == FALSE) ? "&nopopups" : "");
#endif
if(user_supplied_scaling == TRUE) if(user_supplied_scaling == TRUE)
printf("&scaling_factor=%2.1f", user_scaling_factor); printf("&scaling_factor=%2.1f", user_scaling_factor);
print_layer_url(TRUE); print_layer_url(TRUE);
@ -705,7 +717,11 @@ void display_page_header(void) {
/* right hand column of top row */ /* right hand column of top row */
printf("<td align=right valign=top>\n"); printf("<td align=right valign=top>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"POST\" action=\"%s\">\n", STATUSMAP_CGI); printf("<form method=\"POST\" action=\"%s\">\n", STATUSMAP_CGI);
#else
printf("<form method=\"POST\" action=\"%s\">\n", LEGACY_STATUSMAP_CGI);
#endif
printf("<table border=0 CLASS='optBox'>\n"); printf("<table border=0 CLASS='optBox'>\n");
printf("<tr><td valign=top>\n"); printf("<tr><td valign=top>\n");
printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name)); printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name));
@ -843,7 +859,11 @@ void display_map(void) {
/* write the URL location for the image we just generated - the web browser will come and get it... */ /* write the URL location for the image we just generated - the web browser will come and get it... */
if(create_type == CREATE_HTML) { if(create_type == CREATE_HTML) {
printf("<P><DIV ALIGN=center>\n"); printf("<P><DIV ALIGN=center>\n");
printf("<img src='%s?host=%s&createimage&time=%lu", STATUSMAP_CGI, url_encode(host_name), (unsigned long)time(NULL)); #ifdef LEGACY_GRAPHICAL_CGIS
printf("<img src='%s?host=%s&createimage&time=%llu", STATUSMAP_CGI, url_encode(host_name), (unsigned long long)time(NULL));
#else
printf("<img src='%s?host=%s&createimage&time=%llu", LEGACY_STATUSMAP_CGI, url_encode(host_name), (unsigned long long)time(NULL));
#endif
printf("&canvas_x=%d&canvas_y=%d&canvas_width=%d&canvas_height=%d&max_width=%d&max_height=%d&layout=%d%s%s%s", canvas_x, canvas_y, canvas_width, canvas_height, max_image_width, max_image_height, layout_method, (use_links == FALSE) ? "&nolinks" : "", (use_text == FALSE) ? "&notext" : "", (use_highlights == FALSE) ? "&nohighlights" : ""); printf("&canvas_x=%d&canvas_y=%d&canvas_width=%d&canvas_height=%d&max_width=%d&max_height=%d&layout=%d%s%s%s", canvas_x, canvas_y, canvas_width, canvas_height, max_image_width, max_image_height, layout_method, (use_links == FALSE) ? "&nolinks" : "", (use_text == FALSE) ? "&notext" : "", (use_highlights == FALSE) ? "&nohighlights" : "");
print_layer_url(TRUE); print_layer_url(TRUE);
printf("' width=%d height=%d border=0 name='statusimage' useMap='#statusmap'>\n", (int)(canvas_width * scaling_factor), (int)(canvas_height * scaling_factor)); printf("' width=%d height=%d border=0 name='statusimage' useMap='#statusmap'>\n", (int)(canvas_width * scaling_factor), (int)(canvas_height * scaling_factor));
@ -1249,13 +1269,13 @@ void calculate_canvas_bounds(void) {
/* calculates canvas coordinates/dimensions around a particular host */ /* calculates canvas coordinates/dimensions around a particular host */
void calculate_canvas_bounds_from_host(char *host_name) { void calculate_canvas_bounds_from_host(char *hname) {
host *temp_host; host *temp_host;
int zoom_width; int zoom_width;
int zoom_height; int zoom_height;
/* find the extended host info */ /* find the extended host info */
temp_host = find_host(host_name); temp_host = find_host(hname);
if(temp_host == NULL) if(temp_host == NULL)
return; return;
@ -1480,7 +1500,7 @@ void draw_host_links(void) {
/* determine color to use when drawing links to children */ /* determine color to use when drawing links to children */
this_hoststatus = find_hoststatus(this_host->name); this_hoststatus = find_hoststatus(this_host->name);
if(this_hoststatus != NULL) { if(this_hoststatus != NULL) {
if(this_hoststatus->status == HOST_DOWN || this_hoststatus->status == HOST_UNREACHABLE) if(this_hoststatus->status == SD_HOST_DOWN || this_hoststatus->status == SD_HOST_UNREACHABLE)
status_color = color_red; status_color = color_red;
else else
status_color = color_black; status_color = color_black;
@ -1545,7 +1565,7 @@ void draw_host_links(void) {
/* determine color to use when drawing links to parent host */ /* determine color to use when drawing links to parent host */
parent_hoststatus = find_hoststatus(parent_host->name); parent_hoststatus = find_hoststatus(parent_host->name);
if(parent_hoststatus != NULL) { if(parent_hoststatus != NULL) {
if(parent_hoststatus->status == HOST_DOWN || parent_hoststatus->status == HOST_UNREACHABLE) if(parent_hoststatus->status == SD_HOST_DOWN || parent_hoststatus->status == SD_HOST_UNREACHABLE)
status_color = color_red; status_color = color_red;
else else
status_color = color_black; status_color = color_black;
@ -1571,7 +1591,7 @@ void draw_host_links(void) {
void draw_hosts(void) { void draw_hosts(void) {
host *temp_host; host *temp_host;
int x1, x2; int x1, x2;
int y1, y2; int y1;
int has_image = FALSE; int has_image = FALSE;
char image_input_file[MAX_INPUT_BUFFER]; char image_input_file[MAX_INPUT_BUFFER];
int current_radius = 0; int current_radius = 0;
@ -1607,7 +1627,6 @@ void draw_hosts(void) {
x1 = nagios_icon_x - canvas_x; x1 = nagios_icon_x - canvas_x;
x2 = x1 + DEFAULT_NODE_WIDTH; x2 = x1 + DEFAULT_NODE_WIDTH;
y1 = nagios_icon_y - canvas_y; y1 = nagios_icon_y - canvas_y;
y2 = y1 + DEFAULT_NODE_HEIGHT;
/* get the name of the image file to open for the logo */ /* get the name of the image file to open for the logo */
snprintf(image_input_file, sizeof(image_input_file) - 1, "%s%s", physical_logo_images_path, NAGIOS_GD2_ICON); snprintf(image_input_file, sizeof(image_input_file) - 1, "%s%s", physical_logo_images_path, NAGIOS_GD2_ICON);
@ -1653,18 +1672,17 @@ void draw_hosts(void) {
x1 = temp_host->x_2d - canvas_x; x1 = temp_host->x_2d - canvas_x;
x2 = x1 + DEFAULT_NODE_WIDTH; x2 = x1 + DEFAULT_NODE_WIDTH;
y1 = temp_host->y_2d - canvas_y; y1 = temp_host->y_2d - canvas_y;
y2 = y1 + DEFAULT_NODE_HEIGHT;
if(create_type == CREATE_IMAGE) { if(create_type == CREATE_IMAGE) {
temp_hoststatus = find_hoststatus(temp_host->name); temp_hoststatus = find_hoststatus(temp_host->name);
if(temp_hoststatus != NULL) { if(temp_hoststatus != NULL) {
if(temp_hoststatus->status == HOST_DOWN) if(temp_hoststatus->status == SD_HOST_DOWN)
status_color = color_red; status_color = color_red;
else if(temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
status_color = color_red; status_color = color_red;
else if(temp_hoststatus->status == HOST_UP) else if(temp_hoststatus->status == SD_HOST_UP)
status_color = color_green; status_color = color_green;
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
status_color = color_grey; status_color = color_grey;
@ -1699,7 +1717,7 @@ void draw_hosts(void) {
/* calculate width of border */ /* calculate width of border */
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
inner_radius = outer_radius; inner_radius = outer_radius;
else if((temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) && temp_hoststatus->problem_has_been_acknowledged == FALSE) else if((temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE) && temp_hoststatus->problem_has_been_acknowledged == FALSE)
inner_radius = outer_radius - 3; inner_radius = outer_radius - 3;
else else
inner_radius = outer_radius; inner_radius = outer_radius;
@ -1813,7 +1831,11 @@ void draw_hosts(void) {
if(!strcmp(host_name, temp_host->name)) if(!strcmp(host_name, temp_host->name))
printf("href='%s?host=%s' ", STATUS_CGI, url_encode(temp_host->name)); printf("href='%s?host=%s' ", STATUS_CGI, url_encode(temp_host->name));
else { else {
#ifdef LEGACY_GRAPHICAL_CGIS
printf("href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s%s%s%s", STATUSMAP_CGI, url_encode(temp_host->name), layout_method, max_image_width, max_image_height, proximity_width, proximity_height, (display_header == TRUE) ? "" : "&noheader", (use_links == FALSE) ? "&nolinks" : "", (use_text == FALSE) ? "&notext" : "", (use_highlights == FALSE) ? "&nohighlights" : "", (display_popups == FALSE) ? "&nopopups" : ""); printf("href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s%s%s%s", STATUSMAP_CGI, url_encode(temp_host->name), layout_method, max_image_width, max_image_height, proximity_width, proximity_height, (display_header == TRUE) ? "" : "&noheader", (use_links == FALSE) ? "&nolinks" : "", (use_text == FALSE) ? "&notext" : "", (use_highlights == FALSE) ? "&nohighlights" : "", (display_popups == FALSE) ? "&nopopups" : "");
#else
printf("href='%s?host=%s&layout=%d&max_width=%d&max_height=%d&proximity_width=%d&proximity_height=%d%s%s%s%s%s", LEGACY_STATUSMAP_CGI, url_encode(temp_host->name), layout_method, max_image_width, max_image_height, proximity_width, proximity_height, (display_header == TRUE) ? "" : "&noheader", (use_links == FALSE) ? "&nolinks" : "", (use_text == FALSE) ? "&notext" : "", (use_highlights == FALSE) ? "&nohighlights" : "", (display_popups == FALSE) ? "&nopopups" : "");
#endif
if(user_supplied_scaling == TRUE) if(user_supplied_scaling == TRUE)
printf("&scaling_factor=%2.1f", user_scaling_factor); printf("&scaling_factor=%2.1f", user_scaling_factor);
print_layer_url(TRUE); print_layer_url(TRUE);
@ -1875,15 +1897,15 @@ void draw_host_text(char *name, int x, int y) {
if(temp_hoststatus != NULL) { if(temp_hoststatus != NULL) {
/* draw the status string */ /* draw the status string */
if(temp_hoststatus->status == HOST_DOWN) { if(temp_hoststatus->status == SD_HOST_DOWN) {
strncpy(temp_buffer, "Down", sizeof(temp_buffer)); strncpy(temp_buffer, "Down", sizeof(temp_buffer));
status_color = color_red; status_color = color_red;
} }
else if(temp_hoststatus->status == HOST_UNREACHABLE) { else if(temp_hoststatus->status == SD_HOST_UNREACHABLE) {
strncpy(temp_buffer, "Unreachable", sizeof(temp_buffer)); strncpy(temp_buffer, "Unreachable", sizeof(temp_buffer));
status_color = color_red; status_color = color_red;
} }
else if(temp_hoststatus->status == HOST_UP) { else if(temp_hoststatus->status == SD_HOST_UP) {
strncpy(temp_buffer, "Up", sizeof(temp_buffer)); strncpy(temp_buffer, "Up", sizeof(temp_buffer));
status_color = color_green; status_color = color_green;
} }
@ -1958,21 +1980,21 @@ void write_host_popup_text(host *hst) {
printf("<tr><td class=\\\"popupText\\\">State:</td><td class=\\\"popupText\\\"><b>"); printf("<tr><td class=\\\"popupText\\\">State:</td><td class=\\\"popupText\\\"><b>");
/* get the status of the host (pending, up, down, or unreachable) */ /* get the status of the host (pending, up, down, or unreachable) */
if(temp_status->status == HOST_DOWN) { if(temp_status->status == SD_HOST_DOWN) {
printf("<font color=red>Down"); printf("<font color=red>Down");
if(temp_status->problem_has_been_acknowledged == TRUE) if(temp_status->problem_has_been_acknowledged == TRUE)
printf(" (Acknowledged)"); printf(" (Acknowledged)");
printf("</font>"); printf("</font>");
} }
else if(temp_status->status == HOST_UNREACHABLE) { else if(temp_status->status == SD_HOST_UNREACHABLE) {
printf("<font color=red>Unreachable"); printf("<font color=red>Unreachable");
if(temp_status->problem_has_been_acknowledged == TRUE) if(temp_status->problem_has_been_acknowledged == TRUE)
printf(" (Acknowledged)"); printf(" (Acknowledged)");
printf("</font>"); printf("</font>");
} }
else if(temp_status->status == HOST_UP) else if(temp_status->status == SD_HOST_UP)
printf("<font color=green>Up</font>"); printf("<font color=green>Up</font>");
else if(temp_status->status == HOST_PENDING) else if(temp_status->status == HOST_PENDING)
@ -2333,13 +2355,13 @@ void write_popup_code(void) {
/* adds a layer to the list in memory */ /* adds a layer to the list in memory */
int add_layer(char *group_name) { int add_layer(char *group_name) {
layer *new_layer; struct layer *new_layer;
if(group_name == NULL) if(group_name == NULL)
return ERROR; return ERROR;
/* allocate memory for a new layer */ /* allocate memory for a new layer */
new_layer = (layer *)malloc(sizeof(layer)); new_layer = (struct layer *)malloc(sizeof(struct layer));
if(new_layer == NULL) if(new_layer == NULL)
return ERROR; return ERROR;
@ -2362,8 +2384,7 @@ int add_layer(char *group_name) {
/* frees memory allocated to the layer list */ /* frees memory allocated to the layer list */
void free_layer_list(void) { void free_layer_list(void) {
layer *this_layer; struct layer *this_layer, *next_layer;
layer *next_layer;
return; return;
@ -2380,7 +2401,7 @@ void free_layer_list(void) {
/* checks to see if a host is in the layer list */ /* checks to see if a host is in the layer list */
int is_host_in_layer_list(host *hst) { int is_host_in_layer_list(host *hst) {
hostgroup *temp_hostgroup; hostgroup *temp_hostgroup;
layer *temp_layer; struct layer *temp_layer;
if(hst == NULL) if(hst == NULL)
return FALSE; return FALSE;
@ -2404,7 +2425,7 @@ int is_host_in_layer_list(host *hst) {
/* print layer url info */ /* print layer url info */
void print_layer_url(int get_method) { void print_layer_url(int get_method) {
layer *temp_layer; struct layer *temp_layer;
for(temp_layer = layer_list; temp_layer != NULL; temp_layer = temp_layer->next) { for(temp_layer = layer_list; temp_layer != NULL; temp_layer = temp_layer->next) {
if(get_method == TRUE) if(get_method == TRUE)
@ -2650,7 +2671,6 @@ void calculate_circular_layer_coords(host *parent, double start_angle, double us
double this_drawing_angle = 0.0; double this_drawing_angle = 0.0;
double available_angle = 0.0; double available_angle = 0.0;
double clipped_available_angle = 0.0; double clipped_available_angle = 0.0;
double average_child_angle = 0.0;
double x_coord = 0.0; double x_coord = 0.0;
double y_coord = 0.0; double y_coord = 0.0;
host *temp_host; host *temp_host;
@ -2666,9 +2686,6 @@ void calculate_circular_layer_coords(host *parent, double start_angle, double us
/* calculate total drawing "width" of parent host */ /* calculate total drawing "width" of parent host */
parent_drawing_width = max_child_host_drawing_width(parent); parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate average angle given to each child host */
average_child_angle = (double)(useable_angle / (double)immediate_children);
/* calculate initial drawing angle */ /* calculate initial drawing angle */
current_drawing_angle = start_angle; current_drawing_angle = start_angle;
@ -2739,7 +2756,6 @@ void draw_circular_layer_markup(host *parent, double start_angle, double useable
double current_drawing_angle = 0.0; double current_drawing_angle = 0.0;
double available_angle = 0.0; double available_angle = 0.0;
double clipped_available_angle = 0.0; double clipped_available_angle = 0.0;
double average_child_angle = 0.0;
double x_coord[4] = {0.0, 0.0, 0.0, 0.0}; double x_coord[4] = {0.0, 0.0, 0.0, 0.0};
double y_coord[4] = {0.0, 0.0, 0.0, 0.0}; double y_coord[4] = {0.0, 0.0, 0.0, 0.0};
hoststatus *temp_hoststatus; hoststatus *temp_hoststatus;
@ -2764,9 +2780,6 @@ void draw_circular_layer_markup(host *parent, double start_angle, double useable
/* calculate total drawing "width" of parent host */ /* calculate total drawing "width" of parent host */
parent_drawing_width = max_child_host_drawing_width(parent); parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate average angle given to each child host */
average_child_angle = (double)(useable_angle / (double)immediate_children);
/* calculate initial drawing angle */ /* calculate initial drawing angle */
current_drawing_angle = start_angle; current_drawing_angle = start_angle;
@ -2836,7 +2849,7 @@ void draw_circular_layer_markup(host *parent, double start_angle, double useable
temp_hoststatus = find_hoststatus(temp_host->name); temp_hoststatus = find_hoststatus(temp_host->name);
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
bgcolor = color_lightgrey; bgcolor = color_lightgrey;
else if(temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)
bgcolor = color_lightred; bgcolor = color_lightred;
else else
bgcolor = color_lightgreen; bgcolor = color_lightgreen;
@ -2856,4 +2869,3 @@ void draw_circular_layer_markup(host *parent, double start_angle, double useable
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* STATUSWML.C - Nagios Status CGI for WAP-enabled devices * STATUSWML.C - Nagios Status CGI for WAP-enabled devices
* *
* Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-15-2008
* *
* License: * License:
* *
@ -30,19 +28,13 @@
#include "../include/getcgi.h" #include "../include/getcgi.h"
#include "../include/cgiauth.h" #include "../include/cgiauth.h"
extern time_t program_start;
extern char main_config_file[MAX_FILENAME_LENGTH]; extern char main_config_file[MAX_FILENAME_LENGTH];
extern char *status_file;
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
extern int use_ssl_authentication; extern int use_ssl_authentication;
extern int enable_notifications;
extern int execute_service_checks;
extern int nagios_process_state; extern int nagios_process_state;
extern char *ping_syntax; extern char *ping_syntax;
@ -108,6 +100,9 @@ int main(void) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
document_header(); document_header();
/* validate arguments in URL */ /* validate arguments in URL */
@ -142,7 +137,7 @@ int main(void) {
} }
/* read all status data */ /* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) { if(result == ERROR) {
printf("<P>Error: Could not read host and service status information!</P>\n"); printf("<P>Error: Could not read host and service status information!</P>\n");
document_footer(); document_footer();
@ -235,8 +230,13 @@ int process_cgivars(void) {
for(x = 0; variables[x] != NULL; x++) { for(x = 0; variables[x] != NULL; x++) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
continue;
}
/* we found the hostgroup argument */ /* we found the hostgroup argument */
if(!strcmp(variables[x], "hostgroup")) { else if(!strcmp(variables[x], "hostgroup")) {
display_type = DISPLAY_HOSTGROUP; display_type = DISPLAY_HOSTGROUP;
x++; x++;
if(variables[x] == NULL) { if(variables[x] == NULL) {
@ -564,9 +564,9 @@ void display_quick_stats(void) {
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
continue; continue;
if(temp_hoststatus->status == HOST_UNREACHABLE) if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
hosts_unreachable++; hosts_unreachable++;
else if(temp_hoststatus->status == HOST_DOWN) else if(temp_hoststatus->status == SD_HOST_DOWN)
hosts_down++; hosts_down++;
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
hosts_pending++; hosts_pending++;
@ -664,13 +664,13 @@ void display_hostgroup_overview(void) {
continue; continue;
printf("<tr><td><anchor title='%s'>", temp_host->name); printf("<tr><td><anchor title='%s'>", temp_host->name);
if(temp_hoststatus->status == HOST_UP) if(temp_hoststatus->status == SD_HOST_UP)
printf("UP"); printf("UP");
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
printf("PND"); printf("PND");
else if(temp_hoststatus->status == HOST_DOWN) else if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DWN"); printf("DWN");
else if(temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNR"); printf("UNR");
else else
printf("???"); printf("???");
@ -757,9 +757,9 @@ void display_hostgroup_summary(void) {
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
continue; continue;
if(temp_hoststatus->status == HOST_UNREACHABLE) if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
hosts_unreachable++; hosts_unreachable++;
else if(temp_hoststatus->status == HOST_DOWN) else if(temp_hoststatus->status == SD_HOST_DOWN)
hosts_down++; hosts_down++;
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
hosts_pending++; hosts_pending++;
@ -889,13 +889,13 @@ void display_host(void) {
printf("<table columns='2' align='LL'>\n"); printf("<table columns='2' align='LL'>\n");
printf("<tr><td>Status:</td><td>"); printf("<tr><td>Status:</td><td>");
if(temp_hoststatus->status == HOST_UP) if(temp_hoststatus->status == SD_HOST_UP)
printf("UP"); printf("UP");
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
printf("PENDING"); printf("PENDING");
else if(temp_hoststatus->status == HOST_DOWN) else if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DOWN"); printf("DOWN");
else if(temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNREACHABLE"); printf("UNREACHABLE");
else else
printf("?"); printf("?");
@ -954,7 +954,7 @@ void display_host(void) {
printf("<b><anchor title='Ping Host'>Ping Host<go href='%s' method='post'><postfield name='ping' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address); printf("<b><anchor title='Ping Host'>Ping Host<go href='%s' method='post'><postfield name='ping' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);
printf("<b><anchor title='Traceroute'>Traceroute<go href='%s' method='post'><postfield name='traceroute' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address); printf("<b><anchor title='Traceroute'>Traceroute<go href='%s' method='post'><postfield name='traceroute' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);
if(temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) if(temp_hoststatus->status != SD_HOST_UP && temp_hoststatus->status != HOST_PENDING)
printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n"); printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");
if(temp_hoststatus->checks_enabled == FALSE) if(temp_hoststatus->checks_enabled == FALSE)
@ -1180,7 +1180,7 @@ void display_service(void) {
printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_DISABLE_SVC_CHECK, CMDMODE_COMMIT); printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), CMD_DISABLE_SVC_CHECK, CMDMODE_COMMIT);
printf("<b><anchor title='Schedule Immediate Check'>Schedule Immediate Check<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name)); printf("<b><anchor title='Schedule Immediate Check'>Schedule Immediate Check<go href='%s' method='post'><postfield name='host' value='%s'/>", COMMAND_CGI, escape_string(host_name));
printf("<postfield name='service' value='%s'/><postfield name='start_time' value='%lu'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), (unsigned long)current_time, CMD_SCHEDULE_SVC_CHECK, CMDMODE_COMMIT); printf("<postfield name='service' value='%s'/><postfield name='start_time' value='%llu'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", escape_string(service_desc), (unsigned long long)current_time, CMD_SCHEDULE_SVC_CHECK, CMDMODE_COMMIT);
} }
if(temp_servicestatus->notifications_enabled == FALSE) { if(temp_servicestatus->notifications_enabled == FALSE) {
@ -1419,7 +1419,7 @@ void display_problems(void) {
if(is_authorized_for_host(temp_host, &current_authdata) == FALSE) if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
continue; continue;
if(temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING) if(temp_hoststatus->status == SD_HOST_UP || temp_hoststatus->status == HOST_PENDING)
continue; continue;
if(display_type == DISPLAY_UNHANDLED_PROBLEMS) { if(display_type == DISPLAY_UNHANDLED_PROBLEMS) {
@ -1434,9 +1434,9 @@ void display_problems(void) {
total_host_problems++; total_host_problems++;
printf("<tr><td><anchor title='%s'>", temp_host->name); printf("<tr><td><anchor title='%s'>", temp_host->name);
if(temp_hoststatus->status == HOST_DOWN) if(temp_hoststatus->status == SD_HOST_DOWN)
printf("DWN"); printf("DWN");
else if(temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("UNR"); printf("UNR");
else else
printf("???"); printf("???");
@ -1510,6 +1510,3 @@ void display_problems(void) {
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* STATUSWRL.C - Nagios 3-D (VRML) Network Status View * STATUSWRL.C - Nagios 3-D (VRML) Network Status View
* *
* Copyright (c) 1999-2007 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 07-16-2007
* *
* Description: * Description:
* *
@ -40,12 +38,10 @@ extern char main_config_file[MAX_FILENAME_LENGTH];
extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH];
extern char *status_file;
extern char *statuswrl_include; extern char *statuswrl_include;
extern host *host_list;
extern service *service_list;
extern int default_statuswrl_layout_method; extern int default_statuswrl_layout_method;
@ -139,6 +135,9 @@ int main(int argc, char **argv) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* read the CGI configuration file */ /* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location()); result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) { if(result == ERROR) {
@ -165,7 +164,7 @@ int main(int argc, char **argv) {
return ERROR; return ERROR;
/* read all status data */ /* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) { if(result == ERROR) {
free_memory(); free_memory();
return ERROR; return ERROR;
@ -950,7 +949,7 @@ void draw_host(host *temp_host) {
printf("material DEF HostMat%s Material{\n", vrml_safe_hostname); printf("material DEF HostMat%s Material{\n", vrml_safe_hostname);
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
printf("emissiveColor 0.2 0.2 0.2\ndiffuseColor 0.2 0.2 0.2\n"); printf("emissiveColor 0.2 0.2 0.2\ndiffuseColor 0.2 0.2 0.2\n");
else if(temp_hoststatus->status == HOST_UP) else if(temp_hoststatus->status == SD_HOST_UP)
printf("emissiveColor 0.2 1.0 0.2\ndiffuseColor 0.2 1.0 0.2\n"); printf("emissiveColor 0.2 1.0 0.2\ndiffuseColor 0.2 1.0 0.2\n");
else else
printf("emissiveColor 1.0 0.2 0.2\ndiffuseColor 1.0 0.2 0.2\n"); printf("emissiveColor 1.0 0.2 0.2\ndiffuseColor 1.0 0.2 0.2\n");
@ -986,18 +985,18 @@ void draw_host(host *temp_host) {
printf("HostText{\n"); printf("HostText{\n");
if(temp_hoststatus != NULL) { if(temp_hoststatus != NULL) {
if(temp_hoststatus->status == HOST_UP) if(temp_hoststatus->status == SD_HOST_UP)
printf("font_color 0 1 0\n"); printf("font_color 0 1 0\n");
else if(temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)
printf("font_color 1 0 0\n"); printf("font_color 1 0 0\n");
} }
printf("the_text [\"%s\", \"%s\", ", temp_host->name, temp_host->alias); printf("the_text [\"%s\", \"%s\", ", temp_host->name, temp_host->alias);
if(temp_hoststatus == NULL) if(temp_hoststatus == NULL)
strcpy(state_string, "UNKNOWN"); strcpy(state_string, "UNKNOWN");
else { else {
if(temp_hoststatus->status == HOST_DOWN) if(temp_hoststatus->status == SD_HOST_DOWN)
strcpy(state_string, "DOWN"); strcpy(state_string, "DOWN");
else if(temp_hoststatus->status == HOST_UNREACHABLE) else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
strcpy(state_string, "UNREACHABLE"); strcpy(state_string, "UNREACHABLE");
else if(temp_hoststatus->status == HOST_PENDING) else if(temp_hoststatus->status == HOST_PENDING)
strcpy(state_string, "PENDING"); strcpy(state_string, "PENDING");
@ -1012,7 +1011,7 @@ void draw_host(host *temp_host) {
} }
/* host is down or unreachable, so make it fade in and out */ /* host is down or unreachable, so make it fade in and out */
if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) if(temp_hoststatus != NULL && (temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE))
printf("ROUTE ProblemTimer.fraction_changed TO HostMat%s.set_transparency\n", vrml_safe_hostname); printf("ROUTE ProblemTimer.fraction_changed TO HostMat%s.set_transparency\n", vrml_safe_hostname);
free(vrml_safe_hostname); free(vrml_safe_hostname);
@ -1229,7 +1228,6 @@ void calculate_circular_layer_coords(host *parent, double start_angle, double us
double this_drawing_angle = 0.0; double this_drawing_angle = 0.0;
double available_angle = 0.0; double available_angle = 0.0;
double clipped_available_angle = 0.0; double clipped_available_angle = 0.0;
double average_child_angle = 0.0;
double x_coord = 0.0; double x_coord = 0.0;
double y_coord = 0.0; double y_coord = 0.0;
host *temp_host; host *temp_host;
@ -1245,9 +1243,6 @@ void calculate_circular_layer_coords(host *parent, double start_angle, double us
/* calculate total drawing "width" of parent host */ /* calculate total drawing "width" of parent host */
parent_drawing_width = max_child_host_drawing_width(parent); parent_drawing_width = max_child_host_drawing_width(parent);
/* calculate average angle given to each child host */
average_child_angle = (double)(useable_angle / (double)immediate_children);
/* calculate initial drawing angle */ /* calculate initial drawing angle */
current_drawing_angle = start_angle; current_drawing_angle = start_angle;
@ -1297,5 +1292,3 @@ void calculate_circular_layer_coords(host *parent, double start_angle, double us
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* SUMMARY.C - Nagios Alert Summary CGI * SUMMARY.C - Nagios Alert Summary CGI
* *
* Copyright (c) 2002-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 01-23-2008
* *
* License: * License:
* *
@ -37,14 +35,6 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern host *host_list;
extern hostgroup *hostgroup_list;
extern service *service_list;
extern servicegroup *servicegroup_list;
extern int log_rotation_method;
/* output types */ /* output types */
#define HTML_OUTPUT 0 #define HTML_OUTPUT 0
#define CSV_OUTPUT 1 #define CSV_OUTPUT 1
@ -205,7 +195,6 @@ int generate_report = FALSE;
int main(int argc, char **argv) { int main(int argc, char **argv) {
int result = OK;
char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer[MAX_INPUT_BUFFER];
char start_timestring[MAX_DATETIME_LENGTH]; char start_timestring[MAX_DATETIME_LENGTH];
char end_timestring[MAX_DATETIME_LENGTH]; char end_timestring[MAX_DATETIME_LENGTH];
@ -221,32 +210,7 @@ int main(int argc, char **argv) {
/* reset internal CGI variables */ /* reset internal CGI variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, 0);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
/* initialize report time period to last 24 hours */ /* initialize report time period to last 24 hours */
time(&t2); time(&t2);
@ -698,7 +662,7 @@ void document_header(int use_stylesheet) {
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
if(output_format == HTML_OUTPUT) if(output_format == HTML_OUTPUT)
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
else { else {
printf("Content-type: text/plain\r\n\r\n"); printf("Content-type: text/plain\r\n\r\n");
return; return;
@ -761,7 +725,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -1564,9 +1527,9 @@ void add_archived_event(int event_type, time_t time_stamp, int entry_type, int s
#ifdef DEBUG #ifdef DEBUG
if(event_type == AE_HOST_ALERT) if(event_type == AE_HOST_ALERT)
printf("Adding host alert (%s) @ %lu<BR>\n", host_name, (unsigned long)time_stamp); printf("Adding host alert (%s) @ %llu<BR>\n", host_name, (unsigned long long)time_stamp);
else else
printf("Adding service alert (%s/%s) @ %lu<BR>\n", host_name, svc_description, (unsigned long)time_stamp); printf("Adding service alert (%s/%s) @ %llu<BR>\n", host_name, svc_description, (unsigned long long)time_stamp);
#endif #endif
/* allocate memory for the new entry */ /* allocate memory for the new entry */
@ -1734,9 +1697,9 @@ void display_recent_alerts(void) {
archived_event *temp_event; archived_event *temp_event;
int current_item = 0; int current_item = 0;
int odd = 0; int odd = 0;
char *bgclass = ""; const char *bgclass = "";
char *status_bgclass = ""; const char *status_bgclass = "";
char *status = ""; const char *status = "";
char date_time[MAX_DATETIME_LENGTH]; char date_time[MAX_DATETIME_LENGTH];
@ -2694,7 +2657,7 @@ void display_top_alerts(void) {
int producer_type = AE_HOST_PRODUCER; int producer_type = AE_HOST_PRODUCER;
int current_item = 0; int current_item = 0;
int odd = 0; int odd = 0;
char *bgclass = ""; const char *bgclass = "";
/* process all events */ /* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) { for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {

247
cgi/tac.c
View File

@ -2,8 +2,6 @@
* *
* TAC.C - Nagios Tactical Monitoring Overview CGI * TAC.C - Nagios Tactical Monitoring Overview CGI
* *
* Copyright (c) 2001-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-05-2010
* *
* This CGI program will display the contents of the Nagios * This CGI program will display the contents of the Nagios
* log file. * log file.
@ -51,8 +49,10 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char url_media_path[MAX_FILENAME_LENGTH]; extern char url_media_path[MAX_FILENAME_LENGTH];
extern char url_js_path[MAX_FILENAME_LENGTH];
extern int refresh_rate; extern int refresh_rate;
extern int tac_cgi_hard_only;
extern char *service_critical_sound; extern char *service_critical_sound;
extern char *service_warning_sound; extern char *service_warning_sound;
@ -61,17 +61,9 @@ extern char *host_down_sound;
extern char *host_unreachable_sound; extern char *host_unreachable_sound;
extern char *normal_sound; extern char *normal_sound;
extern host *host_list;
extern hostgroup *hostgroup_list;
extern hoststatus *hoststatus_list; extern hoststatus *hoststatus_list;
extern servicestatus *servicestatus_list; extern servicestatus *servicestatus_list;
extern int enable_notifications;
extern int execute_service_checks;
extern int accept_passive_service_checks;
extern int enable_event_handlers;
extern int enable_flap_detection;
extern int nagios_process_state; extern int nagios_process_state;
@ -190,16 +182,7 @@ int services_critical = 0;
/*efine DEBUG 1*/ /*efine DEBUG 1*/
int main(void) { int main(void) {
int result = OK;
char *sound = NULL; char *sound = NULL;
#ifdef DEBUG
time_t t1, t2, t3, t4, t5, t6, t7, t8, t9;
#endif
#ifdef DEBUG
time(&t1);
#endif
/* get the CGI variables passed in the URL */ /* get the CGI variables passed in the URL */
process_cgivars(); process_cgivars();
@ -207,64 +190,13 @@ int main(void) {
/* reset internal variables */ /* reset internal variables */
reset_cgi_vars(); reset_cgi_vars();
/* read the CGI configuration file */ cgi_init(document_header, document_footer, READ_ALL_OBJECT_DATA, READ_ALL_STATUS_DATA);
result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) {
document_header(FALSE);
cgi_config_file_error(get_cgi_config_location());
document_footer();
return ERROR;
}
#ifdef DEBUG
time(&t2);
#endif
/* read the main configuration file */
result = read_main_config_file(main_config_file);
if(result == ERROR) {
document_header(FALSE);
main_config_file_error(main_config_file);
document_footer();
return ERROR;
}
#ifdef DEBUG
time(&t3);
#endif
/* read all object configuration data */
result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
if(result == ERROR) {
document_header(FALSE);
object_data_error();
document_footer();
return ERROR;
}
#ifdef DEBUG
time(&t4);
#endif
/* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
if(result == ERROR) {
document_header(FALSE);
status_data_error();
document_footer();
free_memory();
return ERROR;
}
#ifdef DEBUG
time(&t5);
#endif
document_header(TRUE);
/* get authentication information */ /* get authentication information */
get_authentication_information(&current_authdata); get_authentication_information(&current_authdata);
document_header(TRUE);
if(display_header == TRUE) { if(display_header == TRUE) {
/* begin top table */ /* begin top table */
@ -291,26 +223,12 @@ int main(void) {
} }
#ifdef DEBUG
time(&t6);
#endif
/* analyze current host and service status data for tac overview */ /* analyze current host and service status data for tac overview */
analyze_status_data(); analyze_status_data();
#ifdef DEBUG
time(&t7);
#endif
/* find all hosts that are causing network outages */ /* find all hosts that are causing network outages */
find_hosts_causing_outages(); find_hosts_causing_outages();
#ifdef DEBUG
time(&t8);
#endif
/* embed sound tag if necessary... */ /* embed sound tag if necessary... */
if(hosts_unreachable_unacknowledged > 0 && host_unreachable_sound != NULL) if(hosts_unreachable_unacknowledged > 0 && host_unreachable_sound != NULL)
sound = host_unreachable_sound; sound = host_unreachable_sound;
@ -323,7 +241,7 @@ int main(void) {
else if(services_unknown_unacknowledged == 0 && services_warning_unacknowledged == 0 && services_critical_unacknowledged == 0 && hosts_down_unacknowledged == 0 && hosts_unreachable_unacknowledged == 0 && normal_sound != NULL) else if(services_unknown_unacknowledged == 0 && services_warning_unacknowledged == 0 && services_critical_unacknowledged == 0 && hosts_down_unacknowledged == 0 && hosts_unreachable_unacknowledged == 0 && normal_sound != NULL)
sound = normal_sound; sound = normal_sound;
if(sound != NULL) { if(sound != NULL) {
printf("<object type=\"audio/x-wav\" data=\"%s%s\" height=\"-\" width=\"0\">", url_media_path, sound); printf("<object type=\"audio/x-wav\" data=\"%s%s\" height=\"1\" width=\"1\">", url_media_path, sound);
printf("<param name=\"filename\" value=\"%s%s\">", url_media_path, sound); printf("<param name=\"filename\" value=\"%s%s\">", url_media_path, sound);
printf("<param name=\"autostart\" value=\"true\">"); printf("<param name=\"autostart\" value=\"true\">");
printf("<param name=\"playcount\" value=\"1\">"); printf("<param name=\"playcount\" value=\"1\">");
@ -334,10 +252,6 @@ int main(void) {
/**** display main tac screen ****/ /**** display main tac screen ****/
display_tac_overview(); display_tac_overview();
#ifdef DEBUG
time(&t9);
#endif
document_footer(); document_footer();
/* free memory allocated to the host outage list */ /* free memory allocated to the host outage list */
@ -346,18 +260,6 @@ int main(void) {
/* free allocated memory */ /* free allocated memory */
free_memory(); free_memory();
#ifdef DEBUG
printf("T1: %lu\n", (unsigned long)t1);
printf("T2: %lu\n", (unsigned long)t2);
printf("T3: %lu\n", (unsigned long)t3);
printf("T4: %lu\n", (unsigned long)t4);
printf("T5: %lu\n", (unsigned long)t5);
printf("T6: %lu\n", (unsigned long)t6);
printf("T7: %lu\n", (unsigned long)t7);
printf("T8: %lu\n", (unsigned long)t8);
printf("T9: %lu\n", (unsigned long)t9);
#endif
return OK; return OK;
} }
@ -381,7 +283,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -396,8 +298,22 @@ void document_header(int use_stylesheet) {
if(use_stylesheet == TRUE) { if(use_stylesheet == TRUE) {
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMON_CSS); printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMON_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, TAC_CSS); printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, TAC_CSS);
printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, NAGFUNCS_CSS);
} }
printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, JQUERY_JS);
printf("<script type='text/javascript' src='%s%s'></script>\n", url_js_path, NAGFUNCS_JS);
printf("<script type='text/javascript'>\nvar vbox, vBoxId='tac', "
"vboxText = '<a href=https://www.nagios.com/tours target=_blank>"
"Click here to watch the entire Nagios Core 4 Tour!</a>';\n");
printf("$(document).ready(function() {\n"
"var user = '%s';\nvBoxId += ';' + user;", current_authdata.username);
printf("vbox = new vidbox({pos:'lr',"
"vidurl:'https://www.youtube.com/embed/l20YRDhbOfA',text:vboxText,"
"vidid:vBoxId});");
printf("\n});\n</script>\n");
printf("</HEAD>\n"); printf("</HEAD>\n");
printf("<BODY CLASS='tac' marginwidth=2 marginheight=2 topmargin=0 leftmargin=0 rightmargin=0>\n"); printf("<BODY CLASS='tac' marginwidth=2 marginheight=2 topmargin=0 leftmargin=0 rightmargin=0>\n");
@ -496,7 +412,7 @@ void analyze_status_data(void) {
active_checks_disabled_services++; active_checks_disabled_services++;
/* passive check acceptance */ /* passive check acceptance */
if(temp_servicestatus->accept_passive_service_checks == FALSE) if(temp_servicestatus->accept_passive_checks == FALSE)
passive_checks_disabled_services++; passive_checks_disabled_services++;
@ -514,7 +430,7 @@ void analyze_status_data(void) {
else if(temp_servicestatus->status == SERVICE_WARNING) { else if(temp_servicestatus->status == SERVICE_WARNING) {
temp_hoststatus = find_hoststatus(temp_servicestatus->host_name); temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) { if(temp_hoststatus != NULL && (temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)) {
services_warning_host_problem++; services_warning_host_problem++;
problem = FALSE; problem = FALSE;
} }
@ -530,14 +446,16 @@ void analyze_status_data(void) {
services_warning_disabled++; services_warning_disabled++;
problem = FALSE; problem = FALSE;
} }
if(problem == TRUE) if(problem == TRUE) {
services_warning_unacknowledged++; if (temp_servicestatus->state_type == HARD_STATE || tac_cgi_hard_only == FALSE)
services_warning_unacknowledged++;
}
services_warning++; services_warning++;
} }
else if(temp_servicestatus->status == SERVICE_UNKNOWN) { else if(temp_servicestatus->status == SERVICE_UNKNOWN) {
temp_hoststatus = find_hoststatus(temp_servicestatus->host_name); temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) { if(temp_hoststatus != NULL && (temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)) {
services_unknown_host_problem++; services_unknown_host_problem++;
problem = FALSE; problem = FALSE;
} }
@ -553,14 +471,16 @@ void analyze_status_data(void) {
services_unknown_disabled++; services_unknown_disabled++;
problem = FALSE; problem = FALSE;
} }
if(problem == TRUE) if(problem == TRUE) {
services_unknown_unacknowledged++; if (temp_servicestatus->state_type == HARD_STATE || tac_cgi_hard_only == FALSE)
services_unknown_unacknowledged++;
}
services_unknown++; services_unknown++;
} }
else if(temp_servicestatus->status == SERVICE_CRITICAL) { else if(temp_servicestatus->status == SERVICE_CRITICAL) {
temp_hoststatus = find_hoststatus(temp_servicestatus->host_name); temp_hoststatus = find_hoststatus(temp_servicestatus->host_name);
if(temp_hoststatus != NULL && (temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE)) { if(temp_hoststatus != NULL && (temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)) {
services_critical_host_problem++; services_critical_host_problem++;
problem = FALSE; problem = FALSE;
} }
@ -576,8 +496,10 @@ void analyze_status_data(void) {
services_critical_disabled++; services_critical_disabled++;
problem = FALSE; problem = FALSE;
} }
if(problem == TRUE) if(problem == TRUE) {
services_critical_unacknowledged++; if (temp_servicestatus->state_type == HARD_STATE || tac_cgi_hard_only == FALSE)
services_critical_unacknowledged++;
}
services_critical++; services_critical++;
} }
@ -600,7 +522,7 @@ void analyze_status_data(void) {
/* calculate execution time and latency stats */ /* calculate execution time and latency stats */
if(temp_servicestatus->check_type == SERVICE_CHECK_ACTIVE) { if(temp_servicestatus->check_type == CHECK_TYPE_ACTIVE) {
total_active_service_checks++; total_active_service_checks++;
@ -655,7 +577,7 @@ void analyze_status_data(void) {
active_checks_disabled_hosts++; active_checks_disabled_hosts++;
/* passive check acceptance */ /* passive check acceptance */
if(temp_hoststatus->accept_passive_host_checks == FALSE) if(temp_hoststatus->accept_passive_checks == FALSE)
passive_checks_disabled_hosts++; passive_checks_disabled_hosts++;
@ -663,7 +585,7 @@ void analyze_status_data(void) {
problem = TRUE; problem = TRUE;
if(temp_hoststatus->status == HOST_UP) { if(temp_hoststatus->status == SD_HOST_UP) {
if(temp_hoststatus->checks_enabled == FALSE) if(temp_hoststatus->checks_enabled == FALSE)
hosts_up_disabled++; hosts_up_disabled++;
else else
@ -671,7 +593,7 @@ void analyze_status_data(void) {
hosts_up++; hosts_up++;
} }
else if(temp_hoststatus->status == HOST_DOWN) { else if(temp_hoststatus->status == SD_HOST_DOWN) {
if(temp_hoststatus->scheduled_downtime_depth > 0) { if(temp_hoststatus->scheduled_downtime_depth > 0) {
hosts_down_scheduled++; hosts_down_scheduled++;
problem = FALSE; problem = FALSE;
@ -684,12 +606,14 @@ void analyze_status_data(void) {
hosts_down_disabled++; hosts_down_disabled++;
problem = FALSE; problem = FALSE;
} }
if(problem == TRUE) if(problem == TRUE) {
hosts_down_unacknowledged++; if (temp_hoststatus->state_type == HARD_STATE || tac_cgi_hard_only == FALSE)
hosts_down_unacknowledged++;
}
hosts_down++; hosts_down++;
} }
else if(temp_hoststatus->status == HOST_UNREACHABLE) { else if(temp_hoststatus->status == SD_HOST_UNREACHABLE) {
if(temp_hoststatus->scheduled_downtime_depth > 0) { if(temp_hoststatus->scheduled_downtime_depth > 0) {
hosts_unreachable_scheduled++; hosts_unreachable_scheduled++;
problem = FALSE; problem = FALSE;
@ -702,8 +626,10 @@ void analyze_status_data(void) {
hosts_unreachable_disabled++; hosts_unreachable_disabled++;
problem = FALSE; problem = FALSE;
} }
if(problem == TRUE) if(problem == TRUE) {
hosts_unreachable_unacknowledged++; if (temp_hoststatus->state_type == HARD_STATE || tac_cgi_hard_only == FALSE)
hosts_unreachable_unacknowledged++;
}
hosts_unreachable++; hosts_unreachable++;
} }
@ -714,14 +640,14 @@ void analyze_status_data(void) {
} }
/* get health stats */ /* get health stats */
if(temp_hoststatus->status == HOST_UP) if(temp_hoststatus->status == SD_HOST_UP)
total_host_health++; total_host_health++;
if(temp_hoststatus->status != HOST_PENDING) if(temp_hoststatus->status != HOST_PENDING)
potential_host_health++; potential_host_health++;
/* check type stats */ /* check type stats */
if(temp_hoststatus->check_type == HOST_CHECK_ACTIVE) { if(temp_hoststatus->check_type == CHECK_TYPE_ACTIVE) {
total_active_host_checks++; total_active_host_checks++;
@ -801,7 +727,7 @@ void find_hosts_causing_outages(void) {
for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) { for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
/* check only hosts that are not up and not pending */ /* check only hosts that are not up and not pending */
if(temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) { if(temp_hoststatus->status != SD_HOST_UP && temp_hoststatus->status != HOST_PENDING) {
/* find the host entry */ /* find the host entry */
temp_host = find_host(temp_hoststatus->host_name); temp_host = find_host(temp_hoststatus->host_name);
@ -920,7 +846,7 @@ int is_route_to_host_blocked(host *hst) {
continue; continue;
/* at least one parent it up (or pending), so this host is not blocked */ /* at least one parent it up (or pending), so this host is not blocked */
if(temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING) if(temp_hoststatus->status == SD_HOST_UP || temp_hoststatus->status == HOST_PENDING)
return FALSE; return FALSE;
} }
@ -953,7 +879,7 @@ void display_tac_overview(void) {
/* right column */ /* right column */
printf("<td align=right valign=bottom width=50%%>\n"); printf("<td align=right valign=bottom width=50%%>\n");
printf("<table border=0 cellspacing=0 cellspadding=0>\n"); printf("<table border=0 cellspacing=0 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
@ -966,7 +892,7 @@ void display_tac_overview(void) {
printf("<td>\n"); printf("<td>\n");
printf("<table border=0 cellspacing=4 cellspadding=0>\n"); printf("<table border=0 cellspacing=4 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td class='perfTitle'>&nbsp;<a href='%s?type=%d' class='perfTitle'>Monitoring Performance</a></td>\n", EXTINFO_CGI, DISPLAY_PERFORMANCE); printf("<td class='perfTitle'>&nbsp;<a href='%s?type=%d' class='perfTitle'>Monitoring Performance</a></td>\n", EXTINFO_CGI, DISPLAY_PERFORMANCE);
printf("</tr>\n"); printf("</tr>\n");
@ -974,10 +900,10 @@ void display_tac_overview(void) {
printf("<tr>\n"); printf("<tr>\n");
printf("<td>\n"); printf("<td>\n");
printf("<table border=0 cellspacing=0 cellspadding=0>\n"); printf("<table border=0 cellspacing=0 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td class='perfBox'>\n"); printf("<td class='perfBox'>\n");
printf("<table border=0 cellspacing=4 cellspadding=0>\n"); printf("<table border=0 cellspacing=4 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td align=left valign=center class='perfItem'><a href='%s?type=%d' class='perfItem'>Service Check Execution Time:</a></td>", EXTINFO_CGI, DISPLAY_PERFORMANCE); printf("<td align=left valign=center class='perfItem'><a href='%s?type=%d' class='perfItem'>Service Check Execution Time:</a></td>", EXTINFO_CGI, DISPLAY_PERFORMANCE);
printf("<td valign=top class='perfValue' nowrap><a href='%s?type=%d' class='perfValue'>%.2f / %.2f / %.3f sec</a></td>\n", EXTINFO_CGI, DISPLAY_PERFORMANCE, min_service_execution_time, max_service_execution_time, average_service_execution_time); printf("<td valign=top class='perfValue' nowrap><a href='%s?type=%d' class='perfValue'>%.2f / %.2f / %.3f sec</a></td>\n", EXTINFO_CGI, DISPLAY_PERFORMANCE, min_service_execution_time, max_service_execution_time, average_service_execution_time);
@ -1103,11 +1029,11 @@ void display_tac_overview(void) {
strncpy(service_health_image, THERM_OK_IMAGE, sizeof(service_health_image)); strncpy(service_health_image, THERM_OK_IMAGE, sizeof(service_health_image));
service_health_image[sizeof(service_health_image) - 1] = '\x0'; service_health_image[sizeof(service_health_image) - 1] = '\x0';
printf("<table border=0 cellspacing=0 cellspadding=0>\n"); printf("<table border=0 cellspacing=0 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td>\n"); printf("<td>\n");
printf("<table border=0 cellspacing=4 cellspadding=0>\n"); printf("<table border=0 cellspacing=4 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td class='healthTitle'>&nbsp;Network Health</td>\n"); printf("<td class='healthTitle'>&nbsp;Network Health</td>\n");
printf("</tr>\n"); printf("</tr>\n");
@ -1115,10 +1041,10 @@ void display_tac_overview(void) {
printf("<tr>\n"); printf("<tr>\n");
printf("<td>\n"); printf("<td>\n");
printf("<table border=0 cellspacing=0 cellspadding=0>\n"); printf("<table border=0 cellspacing=0 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td class='healthBox'>\n"); printf("<td class='healthBox'>\n");
printf("<table border=0 cellspacing=4 cellspadding=0>\n"); printf("<table border=0 cellspacing=4 cellpadding=0>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td align=left valign=center class='healthItem'>Host Health:</td>"); printf("<td align=left valign=center class='healthItem'>Host Health:</td>");
printf("<td valign=top width=100 class='healthBar'><img src='%s%s' border=0 width=%d height=20 alt='%2.1f%% Health' title='%2.1f%% Health'></td>\n", url_images_path, host_health_image, (percent_host_health < 5.0) ? 5 : (int)percent_host_health, percent_host_health, percent_host_health); printf("<td valign=top width=100 class='healthBar'><img src='%s%s' border=0 width=%d height=20 alt='%2.1f%% Health' title='%2.1f%% Health'></td>\n", url_images_path, host_health_image, (percent_host_health < 5.0) ? 5 : (int)percent_host_health, percent_host_health, percent_host_health);
@ -1158,9 +1084,9 @@ void display_tac_overview(void) {
printf("<tr><td colspan=4 height=20 class='hostTitle'>&nbsp;Hosts</td></tr>\n"); printf("<tr><td colspan=4 height=20 class='hostTitle'>&nbsp;Hosts</td></tr>\n");
printf("<tr>\n"); printf("<tr>\n");
printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Down</a></td>\n", STATUS_CGI, HOST_DOWN, hosts_down); printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Down</a></td>\n", STATUS_CGI, SD_HOST_DOWN, hosts_down);
printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Unreachable</a></td>\n", STATUS_CGI, HOST_UNREACHABLE, hosts_unreachable); printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Unreachable</a></td>\n", STATUS_CGI, SD_HOST_UNREACHABLE, hosts_unreachable);
printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Up</a></td>\n", STATUS_CGI, HOST_UP, hosts_up); printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Up</a></td>\n", STATUS_CGI, SD_HOST_UP, hosts_up);
printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Pending</a></td>\n", STATUS_CGI, HOST_PENDING, hosts_pending); printf("<td class='hostHeader' width=125><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d' class='hostHeader'>%d Pending</a></td>\n", STATUS_CGI, HOST_PENDING, hosts_pending);
printf("</tr>\n"); printf("</tr>\n");
@ -1177,16 +1103,16 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(hosts_down_unacknowledged > 0) if(hosts_down_unacknowledged > 0)
printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, HOST_DOWN, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_down_unacknowledged); printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SD_HOST_DOWN, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_down_unacknowledged);
if(hosts_down_scheduled > 0) if(hosts_down_scheduled > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, HOST_DOWN, HOST_SCHEDULED_DOWNTIME, hosts_down_scheduled); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SD_HOST_DOWN, HOST_SCHEDULED_DOWNTIME, hosts_down_scheduled);
if(hosts_down_acknowledged > 0) if(hosts_down_acknowledged > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, HOST_DOWN, HOST_STATE_ACKNOWLEDGED, hosts_down_acknowledged); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, SD_HOST_DOWN, HOST_STATE_ACKNOWLEDGED, hosts_down_acknowledged);
if(hosts_down_disabled > 0) if(hosts_down_disabled > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, HOST_DOWN, HOST_CHECKS_DISABLED, hosts_down_disabled); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, SD_HOST_DOWN, HOST_CHECKS_DISABLED, hosts_down_disabled);
printf("</table>\n"); printf("</table>\n");
printf("</td>\n"); printf("</td>\n");
@ -1208,16 +1134,16 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(hosts_unreachable_unacknowledged > 0) if(hosts_unreachable_unacknowledged > 0)
printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, HOST_UNREACHABLE, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_unreachable_unacknowledged); printf("<tr><td width=100%% class='hostImportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SD_HOST_UNREACHABLE, HOST_NO_SCHEDULED_DOWNTIME | HOST_STATE_UNACKNOWLEDGED | HOST_CHECKS_ENABLED, hosts_unreachable_unacknowledged);
if(hosts_unreachable_scheduled > 0) if(hosts_unreachable_scheduled > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, HOST_UNREACHABLE, HOST_SCHEDULED_DOWNTIME, hosts_unreachable_scheduled); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SD_HOST_UNREACHABLE, HOST_SCHEDULED_DOWNTIME, hosts_unreachable_scheduled);
if(hosts_unreachable_acknowledged > 0) if(hosts_unreachable_acknowledged > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, HOST_UNREACHABLE, HOST_STATE_ACKNOWLEDGED, hosts_unreachable_acknowledged); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Acknowledged</a></td></tr>\n", STATUS_CGI, SD_HOST_UNREACHABLE, HOST_STATE_ACKNOWLEDGED, hosts_unreachable_acknowledged);
if(hosts_unreachable_disabled > 0) if(hosts_unreachable_disabled > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, HOST_UNREACHABLE, HOST_CHECKS_DISABLED, hosts_unreachable_disabled); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, SD_HOST_UNREACHABLE, HOST_CHECKS_DISABLED, hosts_unreachable_disabled);
printf("</table>\n"); printf("</table>\n");
printf("</td>\n"); printf("</td>\n");
@ -1239,7 +1165,7 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(hosts_up_disabled > 0) if(hosts_up_disabled > 0)
printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, HOST_UP, HOST_CHECKS_DISABLED, hosts_up_disabled); printf("<tr><td width=100%% class='hostUnimportantProblem'><a href='%s?hostgroup=all&style=hostdetail&hoststatustypes=%d&hostprops=%d'>%d Disabled</a></td></tr>\n", STATUS_CGI, SD_HOST_UP, HOST_CHECKS_DISABLED, hosts_up_disabled);
printf("</table>\n"); printf("</table>\n");
printf("</td>\n"); printf("</td>\n");
@ -1320,10 +1246,10 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(services_critical_unacknowledged > 0) if(services_critical_unacknowledged > 0)
printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_critical_unacknowledged); printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, SD_HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_critical_unacknowledged);
if(services_critical_host_problem > 0) if(services_critical_host_problem > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, HOST_DOWN | HOST_UNREACHABLE, services_critical_host_problem); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, SD_HOST_DOWN | SD_HOST_UNREACHABLE, services_critical_host_problem);
if(services_critical_scheduled > 0) if(services_critical_scheduled > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, SERVICE_SCHEDULED_DOWNTIME, services_critical_scheduled); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_CRITICAL, SERVICE_SCHEDULED_DOWNTIME, services_critical_scheduled);
@ -1355,10 +1281,10 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(services_warning_unacknowledged > 0) if(services_warning_unacknowledged > 0)
printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_warning_unacknowledged); printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, SD_HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_warning_unacknowledged);
if(services_warning_host_problem > 0) if(services_warning_host_problem > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, HOST_DOWN | HOST_UNREACHABLE, services_warning_host_problem); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, SD_HOST_DOWN | SD_HOST_UNREACHABLE, services_warning_host_problem);
if(services_warning_scheduled > 0) if(services_warning_scheduled > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, SERVICE_SCHEDULED_DOWNTIME, services_warning_scheduled); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_WARNING, SERVICE_SCHEDULED_DOWNTIME, services_warning_scheduled);
@ -1390,10 +1316,10 @@ void display_tac_overview(void) {
printf("<table border=0 width=100%%>\n"); printf("<table border=0 width=100%%>\n");
if(services_unknown_unacknowledged > 0) if(services_unknown_unacknowledged > 0)
printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_unknown_unacknowledged); printf("<tr><td width=100%% class='serviceImportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d&serviceprops=%d'>%d Unhandled Problems</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, SD_HOST_UP | HOST_PENDING, SERVICE_NO_SCHEDULED_DOWNTIME | SERVICE_STATE_UNACKNOWLEDGED | SERVICE_CHECKS_ENABLED, services_unknown_unacknowledged);
if(services_unknown_host_problem > 0) if(services_unknown_host_problem > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, HOST_DOWN | HOST_UNREACHABLE, services_unknown_host_problem); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&hoststatustypes=%d'>%d on Problem Hosts</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, SD_HOST_DOWN | SD_HOST_UNREACHABLE, services_unknown_host_problem);
if(services_unknown_scheduled > 0) if(services_unknown_scheduled > 0)
printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, SERVICE_SCHEDULED_DOWNTIME, services_unknown_scheduled); printf("<tr><td width=100%% class='serviceUnimportantProblem'><a href='%s?host=all&type=detail&servicestatustypes=%d&serviceprops=%d'>%d Scheduled</a></td></tr>\n", STATUS_CGI, SERVICE_UNKNOWN, SERVICE_SCHEDULED_DOWNTIME, services_unknown_scheduled);
@ -1508,12 +1434,12 @@ void display_tac_overview(void) {
printf("<tr><td width=100%% class='featureItemServicesNotFlapping'>No Services Flapping</td></tr>\n"); printf("<tr><td width=100%% class='featureItemServicesNotFlapping'>No Services Flapping</td></tr>\n");
if(flap_disabled_hosts > 0) if(flap_disabled_hosts > 0)
printf("<tr><td width=100%% class='featureItemDisabledHostFlapDetection'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_FLAP_DETECTION_DISABLED, flap_disabled_hosts, (flap_disabled_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemDisabledHostFlapDetection'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_FLAP_DETECTION_DISABLED, flap_disabled_hosts, (flap_disabled_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemEnabledHostFlapDetection'>All Hosts Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledHostFlapDetection'>All Hosts Enabled</td></tr>\n");
if(flapping_hosts > 0) if(flapping_hosts > 0)
printf("<tr><td width=100%% class='featureItemHostsFlapping'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Flapping</a></td></tr>\n", STATUS_CGI, HOST_IS_FLAPPING, flapping_hosts, (flapping_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemHostsFlapping'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Flapping</a></td></tr>\n", STATUS_CGI, HOST_IS_FLAPPING, flapping_hosts, (flapping_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemHostsNotFlapping'>No Hosts Flapping</td></tr>\n"); printf("<tr><td width=100%% class='featureItemHostsNotFlapping'>No Hosts Flapping</td></tr>\n");
@ -1544,7 +1470,7 @@ void display_tac_overview(void) {
printf("<tr><td width=100%% class='featureItemEnabledServiceNotifications'>All Services Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledServiceNotifications'>All Services Enabled</td></tr>\n");
if(notification_disabled_hosts > 0) if(notification_disabled_hosts > 0)
printf("<tr><td width=100%% class='featureItemDisabledHostNotifications'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_NOTIFICATIONS_DISABLED, notification_disabled_hosts, (notification_disabled_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemDisabledHostNotifications'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_NOTIFICATIONS_DISABLED, notification_disabled_hosts, (notification_disabled_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemEnabledHostNotifications'>All Hosts Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledHostNotifications'>All Hosts Enabled</td></tr>\n");
@ -1576,7 +1502,7 @@ void display_tac_overview(void) {
printf("<tr><td width=100%% class='featureItemEnabledServiceHandlers'>All Services Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledServiceHandlers'>All Services Enabled</td></tr>\n");
if(event_handler_disabled_hosts > 0) if(event_handler_disabled_hosts > 0)
printf("<tr><td width=100%% class='featureItemDisabledHostHandlers'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_EVENT_HANDLER_DISABLED, event_handler_disabled_hosts, (event_handler_disabled_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemDisabledHostHandlers'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_EVENT_HANDLER_DISABLED, event_handler_disabled_hosts, (event_handler_disabled_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemEnabledHostHandlers'>All Hosts Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledHostHandlers'>All Hosts Enabled</td></tr>\n");
@ -1608,7 +1534,7 @@ void display_tac_overview(void) {
printf("<tr><td width=100%% class='featureItemEnabledActiveServiceChecks'>All Services Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledActiveServiceChecks'>All Services Enabled</td></tr>\n");
if(active_checks_disabled_hosts > 0) if(active_checks_disabled_hosts > 0)
printf("<tr><td width=100%% class='featureItemDisabledActiveHostChecks'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_CHECKS_DISABLED, active_checks_disabled_hosts, (active_checks_disabled_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemDisabledActiveHostChecks'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_CHECKS_DISABLED, active_checks_disabled_hosts, (active_checks_disabled_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemEnabledActiveHostChecks'>All Hosts Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledActiveHostChecks'>All Hosts Enabled</td></tr>\n");
@ -1641,7 +1567,7 @@ void display_tac_overview(void) {
printf("<tr><td width=100%% class='featureItemEnabledPassiveServiceChecks'>All Services Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledPassiveServiceChecks'>All Services Enabled</td></tr>\n");
if(passive_checks_disabled_hosts > 0) if(passive_checks_disabled_hosts > 0)
printf("<tr><td width=100%% class='featureItemDisabledPassiveHostChecks'><a href='%s?host=all&type=detail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_PASSIVE_CHECKS_DISABLED, passive_checks_disabled_hosts, (passive_checks_disabled_hosts == 1) ? "" : "s"); printf("<tr><td width=100%% class='featureItemDisabledPassiveHostChecks'><a href='%s?hostgroup=all&style=hostdetail&hostprops=%d'>%d Host%s Disabled</a></td></tr>\n", STATUS_CGI, HOST_PASSIVE_CHECKS_DISABLED, passive_checks_disabled_hosts, (passive_checks_disabled_hosts == 1) ? "" : "s");
else else
printf("<tr><td width=100%% class='featureItemEnabledPassiveHostChecks'>All Hosts Enabled</td></tr>\n"); printf("<tr><td width=100%% class='featureItemEnabledPassiveHostChecks'>All Hosts Enabled</td></tr>\n");
@ -1663,4 +1589,3 @@ void display_tac_overview(void) {
return; return;
} }

View File

@ -2,8 +2,6 @@
* *
* TRENDS.C - Nagios State Trends CGI * TRENDS.C - Nagios State Trends CGI
* *
* Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-15-2008
* *
* License: * License:
* *
@ -43,15 +41,10 @@ extern char url_html_path[MAX_FILENAME_LENGTH];
extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern char physical_images_path[MAX_FILENAME_LENGTH]; extern char physical_images_path[MAX_FILENAME_LENGTH];
extern char *status_file;
extern int log_rotation_method; extern int log_rotation_method;
extern host *host_list;
extern service *service_list;
#include "../include/skiplist.h"
extern skiplist *object_skiplists[NUM_OBJECT_SKIPLISTS];
/* archived state types */ /* archived state types */
#define AS_CURRENT_STATE -1 /* special case for initial assumed state */ #define AS_CURRENT_STATE -1 /* special case for initial assumed state */
#define AS_NO_DATA 0 #define AS_NO_DATA 0
@ -271,6 +264,9 @@ int main(int argc, char **argv) {
/* reset internal CGI variables */ /* reset internal CGI variables */
reset_cgi_vars(); reset_cgi_vars();
/* Initialize shared configuration variables */
init_shared_cfg_vars(1);
/* read the CGI configuration file */ /* read the CGI configuration file */
result = read_cgi_config_file(get_cgi_config_location()); result = read_cgi_config_file(get_cgi_config_location());
if(result == ERROR) { if(result == ERROR) {
@ -335,7 +331,7 @@ int main(int argc, char **argv) {
} }
/* read all status data */ /* read all status data */
result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); result = read_all_status_data(status_file, READ_ALL_STATUS_DATA);
if(result == ERROR) { if(result == ERROR) {
if(mode == CREATE_HTML) { if(mode == CREATE_HTML) {
document_header(FALSE); document_header(FALSE);
@ -394,7 +390,7 @@ int main(int argc, char **argv) {
problem_found = FALSE; problem_found = FALSE;
if(display_type == DISPLAY_HOST_TRENDS) { if(display_type == DISPLAY_HOST_TRENDS) {
for(temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) { for(temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if((temp_as->entry_type == HOST_DOWN || temp_as->entry_type == HOST_UNREACHABLE) && temp_as->time_stamp > t1) { if((temp_as->entry_type == SD_HOST_DOWN || temp_as->entry_type == SD_HOST_UNREACHABLE) && temp_as->time_stamp > t1) {
problem_t1 = temp_as->time_stamp; problem_t1 = temp_as->time_stamp;
problem_found = TRUE; problem_found = TRUE;
break; break;
@ -453,7 +449,7 @@ int main(int argc, char **argv) {
if(display_type == DISPLAY_HOST_TRENDS) { if(display_type == DISPLAY_HOST_TRENDS) {
printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Host</a><BR>\n", AVAIL_CGI, url_encode(host_name), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives); printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedhoststate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Host</a><BR>\n", AVAIL_CGI, url_encode(host_name), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_host_state, backtrack_archives);
#ifdef USE_HISTROGRAM #ifdef USE_HISTOGRAM
printf("<a href='%s?host=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Host</a><BR>\n", HISTOGRAM_CGI, url_encode(host_name), t1, t2, (assume_state_retention == TRUE) ? "yes" : "no"); printf("<a href='%s?host=%s&t1=%lu&t2=%lu&assumestateretention=%s'>View Alert Histogram For This Host</a><BR>\n", HISTOGRAM_CGI, url_encode(host_name), t1, t2, (assume_state_retention == TRUE) ? "yes" : "no");
#endif #endif
printf("<a href='%s?host=%s'>View Status Detail For This Host</a><BR>\n", STATUS_CGI, url_encode(host_name)); printf("<a href='%s?host=%s'>View Status Detail For This Host</a><BR>\n", STATUS_CGI, url_encode(host_name));
@ -461,7 +457,11 @@ int main(int argc, char **argv) {
printf("<a href='%s?host=%s'>View Notifications For This Host</a><BR>\n", NOTIFICATIONS_CGI, url_encode(host_name)); printf("<a href='%s?host=%s'>View Notifications For This Host</a><BR>\n", NOTIFICATIONS_CGI, url_encode(host_name));
} }
else { else {
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>View Trends For This Host</a><BR>\n", TRENDS_CGI, url_encode(host_name), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives); printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>View Trends For This Host</a><BR>\n", TRENDS_CGI, url_encode(host_name), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives);
#else
printf("<a href='%s?host=%s&t1=%lu&t2=%lu&includesoftstates=%s&assumestateretention=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d'>View Trends For This Host</a><BR>\n", LEGACY_TRENDS_CGI, url_encode(host_name), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives);
#endif
printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(host_name)); printf("<a href='%s?host=%s", AVAIL_CGI, url_encode(host_name));
printf("&service=%s&t1=%lu&t2=%lu&assumestateretention=%s&includesoftstates=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Service</a><BR>\n", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives); printf("&service=%s&t1=%lu&t2=%lu&assumestateretention=%s&includesoftstates=%s&assumeinitialstates=%s&assumestatesduringnotrunning=%s&initialassumedservicestate=%d&backtrack=%d&show_log_entries'>View Availability Report For This Service</a><BR>\n", url_encode(svc_description), t1, t2, (include_soft_states == TRUE) ? "yes" : "no", (assume_state_retention == TRUE) ? "yes" : "no", (assume_initial_states == TRUE) ? "yes" : "no", (assume_states_during_notrunning == TRUE) ? "yes" : "no", initial_assumed_service_state, backtrack_archives);
printf("<a href='%s?host=%s", HISTOGRAM_CGI, url_encode(host_name)); printf("<a href='%s?host=%s", HISTOGRAM_CGI, url_encode(host_name));
@ -509,7 +509,11 @@ int main(int argc, char **argv) {
/* right hand column of top row */ /* right hand column of top row */
printf("<td align=right valign=bottom width=33%%>\n"); printf("<td align=right valign=bottom width=33%%>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI); printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_TRENDS_CGI);
#endif
printf("<table border=0 CLASS='optBox'>\n"); printf("<table border=0 CLASS='optBox'>\n");
if(display_type != DISPLAY_NO_TRENDS && input_type == GET_INPUT_NONE) { if(display_type != DISPLAY_NO_TRENDS && input_type == GET_INPUT_NONE) {
@ -809,7 +813,11 @@ int main(int argc, char **argv) {
printf("<BR><BR>\n"); printf("<BR><BR>\n");
printf("<DIV ALIGN=CENTER>\n"); printf("<DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", TRENDS_CGI, (unsigned long)t1, (unsigned long)t2); printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", TRENDS_CGI, (unsigned long)t1, (unsigned long)t2);
#else
printf("<IMG SRC='%s?createimage&t1=%lu&t2=%lu", LEGACY_TRENDS_CGI, (unsigned long)t1, (unsigned long)t2);
#endif
printf("&assumeinitialstates=%s", (assume_initial_states == TRUE) ? "yes" : "no"); printf("&assumeinitialstates=%s", (assume_initial_states == TRUE) ? "yes" : "no");
printf("&assumestatesduringnotrunning=%s", (assume_states_during_notrunning == TRUE) ? "yes" : "no"); printf("&assumestatesduringnotrunning=%s", (assume_states_during_notrunning == TRUE) ? "yes" : "no");
printf("&initialassumedhoststate=%d", initial_assumed_host_state); printf("&initialassumedhoststate=%d", initial_assumed_host_state);
@ -875,7 +883,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI); printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_TRENDS_CGI);
#endif
printf("<input type='hidden' name='input' value='getoptions'>\n"); printf("<input type='hidden' name='input' value='getoptions'>\n");
printf("<TABLE BORDER=0 cellspacing=0 cellpadding=10>\n"); printf("<TABLE BORDER=0 cellspacing=0 cellpadding=10>\n");
@ -931,7 +943,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", TRENDS_CGI); printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", TRENDS_CGI);
#else
printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", LEGACY_TRENDS_CGI);
#endif
printf("<input type='hidden' name='input' value='getoptions'>\n"); printf("<input type='hidden' name='input' value='getoptions'>\n");
printf("<input type='hidden' name='host' value='%s'>\n", (first_service == NULL) ? "unknown" : (char *)escape_string(first_service)); printf("<input type='hidden' name='host' value='%s'>\n", (first_service == NULL) ? "unknown" : (char *)escape_string(first_service));
printf("<TABLE BORDER=0 cellpadding=5>\n"); printf("<TABLE BORDER=0 cellpadding=5>\n");
@ -975,7 +991,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI); printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_TRENDS_CGI);
#endif
printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name)); printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name));
if(display_type == DISPLAY_SERVICE_TRENDS) if(display_type == DISPLAY_SERVICE_TRENDS)
printf("<input type='hidden' name='service' value='%s'>\n", escape_string(svc_description)); printf("<input type='hidden' name='service' value='%s'>\n", escape_string(svc_description));
@ -1137,7 +1157,11 @@ int main(int argc, char **argv) {
printf("<P><DIV ALIGN=CENTER>\n"); printf("<P><DIV ALIGN=CENTER>\n");
#ifdef LEGACY_GRAPHICAL_CGIS
printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI); printf("<form method=\"GET\" action=\"%s\">\n", TRENDS_CGI);
#else
printf("<form method=\"GET\" action=\"%s\">\n", LEGACY_TRENDS_CGI);
#endif
printf("<TABLE BORDER=0 cellpadding=5>\n"); printf("<TABLE BORDER=0 cellpadding=5>\n");
printf("<tr><td class='reportSelectSubTitle' align=right>Type:</td>\n"); printf("<tr><td class='reportSelectSubTitle' align=right>Type:</td>\n");
@ -1190,7 +1214,7 @@ void document_header(int use_stylesheet) {
get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME); get_time_string(&expire_time, date_time, sizeof(date_time), HTTP_DATE_TIME);
printf("Expires: %s\r\n", date_time); printf("Expires: %s\r\n", date_time);
printf("Content-type: text/html\r\n\r\n"); printf("Content-type: text/html; charset=utf-8\r\n\r\n");
if(embedded == TRUE) if(embedded == TRUE)
return; return;
@ -1216,7 +1240,11 @@ void document_header(int use_stylesheet) {
printf("<BODY CLASS='trends'>\n"); printf("<BODY CLASS='trends'>\n");
/* include user SSI header */ /* include user SSI header */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(TRENDS_CGI, SSI_HEADER); include_ssi_files(TRENDS_CGI, SSI_HEADER);
#else
include_ssi_files(LEGACY_TRENDS_CGI, SSI_HEADER);
#endif
printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n"); printf("<div id=\"popup\" style=\"position:absolute; z-index:1; visibility: hidden\"></div>\n");
} }
@ -1249,7 +1277,11 @@ void document_footer(void) {
if(mode == CREATE_HTML) { if(mode == CREATE_HTML) {
/* include user SSI footer */ /* include user SSI footer */
#ifdef LEGACY_GRAPHICAL_CGIS
include_ssi_files(TRENDS_CGI, SSI_FOOTER); include_ssi_files(TRENDS_CGI, SSI_FOOTER);
#else
include_ssi_files(LEGACY_TRENDS_CGI, SSI_FOOTER);
#endif
printf("</body>\n"); printf("</body>\n");
printf("</html>\n"); printf("</html>\n");
@ -1271,7 +1303,6 @@ int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
@ -1739,7 +1770,6 @@ void graph_all_trend_data(void) {
hoststatus *hststatus = NULL; hoststatus *hststatus = NULL;
servicestatus *svcstatus = NULL; servicestatus *svcstatus = NULL;
unsigned long wobble = 300; unsigned long wobble = 300;
int first_real_state = AS_NO_DATA;
time_t initial_assumed_time; time_t initial_assumed_time;
int initial_assumed_state = AS_SVC_OK; int initial_assumed_state = AS_SVC_OK;
int error = FALSE; int error = FALSE;
@ -1766,25 +1796,22 @@ void graph_all_trend_data(void) {
/* the "wobble" value is necessary because when the CGI is called to do the PNG generation, t2 will actually be less that current_time by a bit */ /* the "wobble" value is necessary because when the CGI is called to do the PNG generation, t2 will actually be less that current_time by a bit */
/* if we don't have any data, assume current state (if possible) */ /* if we don't have any data, assume current state (if possible) */
if(as_list == NULL && current_time > t1 && current_time < (t2 + wobble)) { if(as_list == NULL && current_time > t1 && current_time < (time_t)(t2 + wobble)) {
/* we don't have any historical information, but the current time falls within the reporting period, so use */ /* we don't have any historical information, but the current time falls within the reporting period, so use */
/* the current status of the host/service as the starting data */ /* the current status of the host/service as the starting data */
if(display_type == DISPLAY_HOST_TRENDS) { if(display_type == DISPLAY_HOST_TRENDS) {
if(hststatus != NULL) { if(hststatus != NULL) {
if(hststatus->status == HOST_DOWN) if(hststatus->status == SD_HOST_DOWN)
last_known_state = AS_HOST_DOWN; last_known_state = AS_HOST_DOWN;
else if(hststatus->status == HOST_UNREACHABLE) else if(hststatus->status == SD_HOST_UNREACHABLE)
last_known_state = AS_HOST_UNREACHABLE; last_known_state = AS_HOST_UNREACHABLE;
else else
last_known_state = AS_HOST_UP; last_known_state = AS_HOST_UP;
/* add a dummy archived state item, so something can get graphed */ /* add a dummy archived state item, so something can get graphed */
add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Host State Assumed (Faked Log Entry)"); add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Host State Assumed (Faked Log Entry)");
/* use the current state as the last known real state */
first_real_state = last_known_state;
} }
} }
else { else {
@ -1801,9 +1828,6 @@ void graph_all_trend_data(void) {
/* add a dummy archived state item, so something can get graphed */ /* add a dummy archived state item, so something can get graphed */
add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Service State Assumed (Faked Log Entry)"); add_archived_state(last_known_state, AS_HARD_STATE, t1, "Current Service State Assumed (Faked Log Entry)");
/* use the current state as the last known real state */
first_real_state = last_known_state;
} }
} }
} }
@ -1838,13 +1862,13 @@ void graph_all_trend_data(void) {
if(((display_type == DISPLAY_HOST_TRENDS && initial_assumed_host_state == AS_CURRENT_STATE) || (display_type == DISPLAY_SERVICE_TRENDS && initial_assumed_service_state == AS_CURRENT_STATE)) && error == FALSE) { if(((display_type == DISPLAY_HOST_TRENDS && initial_assumed_host_state == AS_CURRENT_STATE) || (display_type == DISPLAY_SERVICE_TRENDS && initial_assumed_service_state == AS_CURRENT_STATE)) && error == FALSE) {
if(display_type == DISPLAY_HOST_TRENDS) { if(display_type == DISPLAY_HOST_TRENDS) {
switch(hststatus->status) { switch(hststatus->status) {
case HOST_DOWN: case SD_HOST_DOWN:
initial_assumed_state = AS_HOST_DOWN; initial_assumed_state = AS_HOST_DOWN;
break; break;
case HOST_UNREACHABLE: case SD_HOST_UNREACHABLE:
initial_assumed_state = AS_HOST_UNREACHABLE; initial_assumed_state = AS_HOST_UNREACHABLE;
break; break;
case HOST_UP: case SD_HOST_UP:
initial_assumed_state = AS_HOST_UP; initial_assumed_state = AS_HOST_UP;
break; break;
default: default:
@ -2044,7 +2068,6 @@ void graph_all_trend_data(void) {
/* graphs trend data */ /* graphs trend data */
void graph_trend_data(int first_state, int last_state, time_t real_start_time, time_t start_time, time_t end_time, char *state_info) { void graph_trend_data(int first_state, int last_state, time_t real_start_time, time_t start_time, time_t end_time, char *state_info) {
int start_state; int start_state;
int end_state;
int start_pixel = 0; int start_pixel = 0;
int end_pixel = 0; int end_pixel = 0;
int color_to_use = 0; int color_to_use = 0;
@ -2114,12 +2137,6 @@ void graph_trend_data(int first_state, int last_state, time_t real_start_time, t
last_known_state = first_state; last_known_state = first_state;
} }
/* special case if last entry was program stop */
if(last_state == AS_PROGRAM_END)
end_state = first_state;
else
end_state = last_state;
#ifdef DEBUG #ifdef DEBUG
printf("Graphing state %d\n", start_state); printf("Graphing state %d\n", start_state);
printf("\tfrom %s", ctime(&start_time)); printf("\tfrom %s", ctime(&start_time));
@ -2253,7 +2270,11 @@ void graph_trend_data(int first_state, int last_state, time_t real_start_time, t
printf("coords='%d,%d,%d,%d' ", drawing_x_offset + start_pixel, drawing_y_offset + (drawing_height - height), drawing_x_offset + end_pixel, drawing_y_offset + drawing_height); printf("coords='%d,%d,%d,%d' ", drawing_x_offset + start_pixel, drawing_y_offset + (drawing_height - height), drawing_x_offset + end_pixel, drawing_y_offset + drawing_height);
printf("href='%s?t1=%lu&t2=%lu&host=%s", TRENDS_CGI, (unsigned long)next_start_time, (unsigned long)next_end_time, url_encode(host_name)); #ifdef LEGACY_GRAPHICAL_CGIS
printf("href='%s?t1=%llu&t2=%llu&host=%s", TRENDS_CGI, (unsigned long long)next_start_time, (unsigned long long)next_end_time, url_encode(host_name));
#else
printf("href='%s?t1=%llu&t2=%llu&host=%s", LEGACY_TRENDS_CGI, (unsigned long long)next_start_time, (unsigned long long)next_end_time, url_encode(host_name));
#endif
if(display_type == DISPLAY_SERVICE_TRENDS) if(display_type == DISPLAY_SERVICE_TRENDS)
printf("&service=%s", url_encode(svc_description)); printf("&service=%s", url_encode(svc_description));
printf("&assumeinitialstates=%s", (assume_initial_states == TRUE) ? "yes" : "no"); printf("&assumeinitialstates=%s", (assume_initial_states == TRUE) ? "yes" : "no");
@ -2332,11 +2353,11 @@ void graph_trend_data(int first_state, int last_state, time_t real_start_time, t
/* convert current host state to archived state value */ /* convert current host state to archived state value */
int convert_host_state_to_archived_state(int current_status) { int convert_host_state_to_archived_state(int current_status) {
if(current_status == HOST_UP) if(current_status == SD_HOST_UP)
return AS_HOST_UP; return AS_HOST_UP;
if(current_status == HOST_DOWN) if(current_status == SD_HOST_DOWN)
return AS_HOST_DOWN; return AS_HOST_DOWN;
if(current_status == HOST_UNREACHABLE) if(current_status == SD_HOST_UNREACHABLE)
return AS_HOST_UNREACHABLE; return AS_HOST_UNREACHABLE;
return AS_NO_DATA; return AS_NO_DATA;
@ -2799,7 +2820,6 @@ void draw_time_breakdowns(void) {
unsigned long total_time = 0L; unsigned long total_time = 0L;
unsigned long total_state_time; unsigned long total_state_time;
unsigned long time_indeterminate = 0L; unsigned long time_indeterminate = 0L;
int string_height;
if(mode == CREATE_HTML) if(mode == CREATE_HTML)
return; return;
@ -2819,7 +2839,6 @@ void draw_time_breakdowns(void) {
else else
time_indeterminate = total_time - total_state_time; time_indeterminate = total_time - total_state_time;
string_height = gdFontSmall->h;
if(display_type == DISPLAY_HOST_TRENDS) { if(display_type == DISPLAY_HOST_TRENDS) {

View File

@ -1,7 +1,6 @@
############################ ############################
# Makefile for Nagios # Makefile for Nagios
# #
# Last Modified: 04-08-2003
############################ ############################
# Source code directories # Source code directories

View File

@ -2,8 +2,6 @@
* *
* COMMENTS.C - Comment functions for Nagios * COMMENTS.C - Comment functions for Nagios
* *
* Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 08-28-2010
* *
* License: * License:
* *
@ -26,12 +24,7 @@
#include "../include/common.h" #include "../include/common.h"
#include "../include/comments.h" #include "../include/comments.h"
#include "../include/objects.h" #include "../include/objects.h"
/***** IMPLEMENTATION-SPECIFIC INCLUDES *****/
#ifdef USE_XCDDEFAULT
#include "../xdata/xcddefault.h" #include "../xdata/xcddefault.h"
#endif
#ifdef NSCORE #ifdef NSCORE
#include "../include/nagios.h" #include "../include/nagios.h"
@ -43,15 +36,14 @@
#endif #endif
comment *comment_list = NULL; nagios_comment *comment_list = NULL;
int defer_comment_sorting = 0; int defer_comment_sorting = 0;
comment **comment_hashlist = NULL; nagios_comment **comment_hashlist = NULL;
#ifdef NSCORE #ifdef NSCORE
pthread_mutex_t nagios_comment_lock = PTHREAD_MUTEX_INITIALIZER;
/******************************************************************/ /******************************************************************/
/**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/ /**************** INITIALIZATION/CLEANUP FUNCTIONS ****************/
@ -59,32 +51,11 @@ pthread_mutex_t nagios_comment_lock = PTHREAD_MUTEX_INITIALIZER;
/* initializes comment data */ /* initializes comment data */
int initialize_comment_data(char *config_file) { int initialize_comment_data(void) {
int result = OK; return xcddefault_initialize_comment_data();
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_initialize_comment_data(config_file);
#endif
return result;
} }
/* removes old/invalid comments */
int cleanup_comment_data(char *config_file) {
int result = OK;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_cleanup_comment_data(config_file);
#endif
return result;
}
/******************************************************************/ /******************************************************************/
/****************** COMMENT OUTPUT FUNCTIONS **********************/ /****************** COMMENT OUTPUT FUNCTIONS **********************/
/******************************************************************/ /******************************************************************/
@ -92,7 +63,7 @@ int cleanup_comment_data(char *config_file) {
/* adds a new host or service comment */ /* adds a new host or service comment */
int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) { int add_new_comment(int type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK; int result;
unsigned long new_comment_id = 0L; unsigned long new_comment_id = 0L;
if(type == HOST_COMMENT) if(type == HOST_COMMENT)
@ -114,13 +85,10 @@ int add_new_comment(int type, int entry_type, char *host_name, char *svc_descrip
/* adds a new host comment */ /* adds a new host comment */
int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) { int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK; int result;
unsigned long new_comment_id = 0L; unsigned long new_comment_id = 0L;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id); result = xcddefault_add_new_host_comment(entry_type, host_name, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
#endif
/* save comment id */ /* save comment id */
if(comment_id != NULL) if(comment_id != NULL)
@ -137,13 +105,10 @@ int add_new_host_comment(int entry_type, char *host_name, time_t entry_time, cha
/* adds a new service comment */ /* adds a new service comment */
int add_new_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) { int add_new_service_comment(int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long *comment_id) {
int result = OK; int result;
unsigned long new_comment_id = 0L; unsigned long new_comment_id = 0L;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XCDDEFAULT
result = xcddefault_add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id); result = xcddefault_add_new_service_comment(entry_type, host_name, svc_description, entry_time, author_name, comment_data, persistent, source, expires, expire_time, &new_comment_id);
#endif
/* save comment id */ /* save comment id */
if(comment_id != NULL) if(comment_id != NULL)
@ -166,18 +131,12 @@ int add_new_service_comment(int entry_type, char *host_name, char *svc_descripti
/* deletes a host or service comment */ /* deletes a host or service comment */
int delete_comment(int type, unsigned long comment_id) { int delete_comment(int type, unsigned long comment_id) {
int result = OK; nagios_comment *this_comment = NULL;
comment *this_comment = NULL; nagios_comment *last_comment = NULL;
comment *last_comment = NULL; nagios_comment *next_comment = NULL;
comment *next_comment = NULL;
int hashslot = 0; int hashslot = 0;
comment *this_hash = NULL; nagios_comment *this_hash = NULL;
comment *last_hash = NULL; nagios_comment *last_hash = NULL;
/* lock the comments so we can modify them safely */
#ifdef NSCORE
pthread_mutex_lock(&nagios_comment_lock);
#endif
/* find the comment we should remove */ /* find the comment we should remove */
for(this_comment = comment_list, last_comment = comment_list; this_comment != NULL; this_comment = next_comment) { for(this_comment = comment_list, last_comment = comment_list; this_comment != NULL; this_comment = next_comment) {
@ -190,63 +149,47 @@ int delete_comment(int type, unsigned long comment_id) {
last_comment = this_comment; last_comment = this_comment;
} }
if(this_comment == NULL)
return ERROR;
/* remove the comment from the list in memory */ /* remove the comment from the list in memory */
if(this_comment != NULL) {
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
/* send data to event broker */ /* send data to event broker */
broker_comment_data(NEBTYPE_COMMENT_DELETE, NEBFLAG_NONE, NEBATTR_NONE, type, this_comment->entry_type, this_comment->host_name, this_comment->service_description, this_comment->entry_time, this_comment->author, this_comment->comment_data, this_comment->persistent, this_comment->source, this_comment->expires, this_comment->expire_time, comment_id, NULL); broker_comment_data(NEBTYPE_COMMENT_DELETE, NEBFLAG_NONE, NEBATTR_NONE, type, this_comment->entry_type, this_comment->host_name, this_comment->service_description, this_comment->entry_time, this_comment->author, this_comment->comment_data, this_comment->persistent, this_comment->source, this_comment->expires, this_comment->expire_time, comment_id, NULL);
#endif #endif
/* first remove from chained hash list */ /* first remove from chained hash list */
hashslot = hashfunc(this_comment->host_name, NULL, COMMENT_HASHSLOTS); hashslot = hashfunc(this_comment->host_name, NULL, COMMENT_HASHSLOTS);
last_hash = NULL; last_hash = NULL;
for(this_hash = comment_hashlist[hashslot]; this_hash; this_hash = this_hash->nexthash) { for(this_hash = comment_hashlist[hashslot]; this_hash; this_hash = this_hash->nexthash) {
if(this_hash == this_comment) { if(this_hash == this_comment) {
if(last_hash) if(last_hash)
last_hash->nexthash = this_hash->nexthash; last_hash->nexthash = this_hash->nexthash;
else { else {
if(this_hash->nexthash) if(this_hash->nexthash)
comment_hashlist[hashslot] = this_hash->nexthash; comment_hashlist[hashslot] = this_hash->nexthash;
else else
comment_hashlist[hashslot] = NULL; comment_hashlist[hashslot] = NULL;
}
break;
} }
last_hash = this_hash; break;
} }
last_hash = this_hash;
/* then removed from linked list */
if(comment_list == this_comment)
comment_list = this_comment->next;
else
last_comment->next = next_comment;
/* free memory */
my_free(this_comment->host_name);
my_free(this_comment->service_description);
my_free(this_comment->author);
my_free(this_comment->comment_data);
my_free(this_comment);
result = OK;
} }
/* then removed from linked list */
if(comment_list == this_comment)
comment_list = this_comment->next;
else else
result = ERROR; last_comment->next = next_comment;
/**** IMPLEMENTATION-SPECIFIC CALLS ****/ /* free memory */
#ifdef USE_XCDDEFAULT my_free(this_comment->host_name);
if(type == HOST_COMMENT) my_free(this_comment->service_description);
result = xcddefault_delete_host_comment(comment_id); my_free(this_comment->author);
else my_free(this_comment->comment_data);
result = xcddefault_delete_service_comment(comment_id); my_free(this_comment);
#endif
#ifdef NSCORE return OK;
pthread_mutex_unlock(&nagios_comment_lock);
#endif
return result;
} }
@ -289,8 +232,8 @@ int delete_all_comments(int type, char *host_name, char *svc_description) {
/* deletes all comments for a particular host */ /* deletes all comments for a particular host */
int delete_all_host_comments(char *host_name) { int delete_all_host_comments(char *host_name) {
int result = OK; int result = OK;
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
comment *next_comment = NULL; nagios_comment *next_comment = NULL;
if(host_name == NULL) if(host_name == NULL)
return ERROR; return ERROR;
@ -309,15 +252,15 @@ int delete_all_host_comments(char *host_name) {
/* deletes all non-persistent acknowledgement comments for a particular host */ /* deletes all non-persistent acknowledgement comments for a particular host */
int delete_host_acknowledgement_comments(host *hst) { int delete_host_acknowledgement_comments(host *hst) {
int result = OK; int result = OK;
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
comment *next_comment = NULL; nagios_comment *next_comment = NULL;
if(hst == NULL) if(hst == NULL)
return ERROR; return ERROR;
/* delete comments from memory */ /* delete comments from memory */
temp_comment = get_first_comment_by_host(hst->name); temp_comment = get_first_comment_by_host(hst->name);
while(temp_comment) { while (temp_comment) {
next_comment = get_next_comment_by_host(hst->name, temp_comment); next_comment = get_next_comment_by_host(hst->name, temp_comment);
if(temp_comment->comment_type == HOST_COMMENT && temp_comment->entry_type == ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent == FALSE) { if(temp_comment->comment_type == HOST_COMMENT && temp_comment->entry_type == ACKNOWLEDGEMENT_COMMENT && temp_comment->persistent == FALSE) {
delete_comment(HOST_COMMENT, temp_comment->comment_id); delete_comment(HOST_COMMENT, temp_comment->comment_id);
@ -332,8 +275,8 @@ int delete_host_acknowledgement_comments(host *hst) {
/* deletes all comments for a particular service */ /* deletes all comments for a particular service */
int delete_all_service_comments(char *host_name, char *svc_description) { int delete_all_service_comments(char *host_name, char *svc_description) {
int result = OK; int result = OK;
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
comment *next_comment = NULL; nagios_comment *next_comment = NULL;
if(host_name == NULL || svc_description == NULL) if(host_name == NULL || svc_description == NULL)
return ERROR; return ERROR;
@ -352,8 +295,8 @@ int delete_all_service_comments(char *host_name, char *svc_description) {
/* deletes all non-persistent acknowledgement comments for a particular service */ /* deletes all non-persistent acknowledgement comments for a particular service */
int delete_service_acknowledgement_comments(service *svc) { int delete_service_acknowledgement_comments(service *svc) {
int result = OK; int result = OK;
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
comment *next_comment = NULL; nagios_comment *next_comment = NULL;
if(svc == NULL) if(svc == NULL)
return ERROR; return ERROR;
@ -371,7 +314,7 @@ int delete_service_acknowledgement_comments(service *svc) {
/* checks for an expired comment (and removes it) */ /* checks for an expired comment (and removes it) */
int check_for_expired_comment(unsigned long comment_id) { int check_for_expired_comment(unsigned long comment_id) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
/* check all comments */ /* check all comments */
for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) { for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
@ -398,16 +341,16 @@ int check_for_expired_comment(unsigned long comment_id) {
/******************************************************************/ /******************************************************************/
/* adds comment to hash list in memory */ /* adds comment to hash list in memory */
int add_comment_to_hashlist(comment *new_comment) { int add_comment_to_hashlist(nagios_comment *new_comment) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
comment *lastpointer = NULL; nagios_comment *lastpointer = NULL;
int hashslot = 0; int hashslot = 0;
/* initialize hash list */ /* initialize hash list */
if(comment_hashlist == NULL) { if(comment_hashlist == NULL) {
int i; int i;
comment_hashlist = (comment **)malloc(sizeof(comment *) * COMMENT_HASHSLOTS); comment_hashlist = (nagios_comment **)malloc(sizeof(nagios_comment *) * COMMENT_HASHSLOTS);
if(comment_hashlist == NULL) if(comment_hashlist == NULL)
return 0; return 0;
@ -467,9 +410,9 @@ int add_service_comment(int entry_type, char *host_name, char *svc_description,
/* adds a comment to the list in memory */ /* adds a comment to the list in memory */
int add_comment(int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) { int add_comment(int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author, char *comment_data, unsigned long comment_id, int persistent, int expires, time_t expire_time, int source) {
comment *new_comment = NULL; nagios_comment *new_comment = NULL;
comment *last_comment = NULL; nagios_comment *last_comment = NULL;
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
int result = OK; int result = OK;
/* make sure we have the data we need */ /* make sure we have the data we need */
@ -477,7 +420,7 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
return ERROR; return ERROR;
/* allocate memory for the comment */ /* allocate memory for the comment */
if((new_comment = (comment *)calloc(1, sizeof(comment))) == NULL) if((new_comment = (nagios_comment *)calloc(1, sizeof(nagios_comment))) == NULL)
return ERROR; return ERROR;
/* duplicate vars */ /* duplicate vars */
@ -522,13 +465,7 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
comment_list = new_comment; comment_list = new_comment;
} }
else { else {
/* add new comment to comment list, sorted by comment id, /* add new comment to comment list, sorted by comment id */
* but lock the list first so broker threads doesn't crash
* out in case they're modifying this list too
*/
#ifdef NSCORE
pthread_mutex_lock(&nagios_comment_lock);
#endif
last_comment = comment_list; last_comment = comment_list;
for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) { for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
if(new_comment->comment_id < temp_comment->comment_id) { if(new_comment->comment_id < temp_comment->comment_id) {
@ -550,9 +487,6 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
new_comment->next = NULL; new_comment->next = NULL;
last_comment->next = new_comment; last_comment->next = new_comment;
} }
#ifdef NSCORE
pthread_mutex_unlock(&nagios_comment_lock);
#endif
} }
#ifdef NSCORE #ifdef NSCORE
@ -566,13 +500,13 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
} }
static int comment_compar(const void *p1, const void *p2) { static int comment_compar(const void *p1, const void *p2) {
comment *c1 = *(comment **)p1; nagios_comment *c1 = *(nagios_comment **)p1;
comment *c2 = *(comment **)p2; nagios_comment *c2 = *(nagios_comment **)p2;
return (c1->comment_id < c2->comment_id) ? -1 : (c1->comment_id - c2->comment_id); return c1->comment_id - c2->comment_id;
} }
int sort_comments(void) { int sort_comments(void) {
comment **array, *temp_comment; nagios_comment **array, *temp_comment;
unsigned long i = 0, unsorted_comments = 0; unsigned long i = 0, unsorted_comments = 0;
if(!defer_comment_sorting) if(!defer_comment_sorting)
@ -612,8 +546,8 @@ int sort_comments(void) {
/* frees memory allocated for the comment data */ /* frees memory allocated for the comment data */
void free_comment_data(void) { void free_comment_data(void) {
comment *this_comment = NULL; nagios_comment *this_comment = NULL;
comment *next_comment = NULL; nagios_comment *next_comment = NULL;
/* free memory for the comment list */ /* free memory for the comment list */
for(this_comment = comment_list; this_comment != NULL; this_comment = next_comment) { for(this_comment = comment_list; this_comment != NULL; this_comment = next_comment) {
@ -642,7 +576,7 @@ void free_comment_data(void) {
/* get the number of comments associated with a particular host */ /* get the number of comments associated with a particular host */
int number_of_host_comments(char *host_name) { int number_of_host_comments(char *host_name) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
int total_comments = 0; int total_comments = 0;
if(host_name == NULL) if(host_name == NULL)
@ -659,7 +593,7 @@ int number_of_host_comments(char *host_name) {
/* get the number of comments associated with a particular service */ /* get the number of comments associated with a particular service */
int number_of_service_comments(char *host_name, char *svc_description) { int number_of_service_comments(char *host_name, char *svc_description) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
int total_comments = 0; int total_comments = 0;
if(host_name == NULL || svc_description == NULL) if(host_name == NULL || svc_description == NULL)
@ -679,14 +613,14 @@ int number_of_service_comments(char *host_name, char *svc_description) {
/********************* TRAVERSAL FUNCTIONS ************************/ /********************* TRAVERSAL FUNCTIONS ************************/
/******************************************************************/ /******************************************************************/
comment *get_first_comment_by_host(char *host_name) { nagios_comment *get_first_comment_by_host(char *host_name) {
return get_next_comment_by_host(host_name, NULL); return get_next_comment_by_host(host_name, NULL);
} }
comment *get_next_comment_by_host(char *host_name, comment *start) { nagios_comment *get_next_comment_by_host(char *host_name, nagios_comment *start) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
if(host_name == NULL || comment_hashlist == NULL) if(host_name == NULL || comment_hashlist == NULL)
return NULL; return NULL;
@ -711,22 +645,22 @@ comment *get_next_comment_by_host(char *host_name, comment *start) {
/******************************************************************/ /******************************************************************/
/* find a service comment by id */ /* find a service comment by id */
comment *find_service_comment(unsigned long comment_id) { nagios_comment *find_service_comment(unsigned long comment_id) {
return find_comment(comment_id, SERVICE_COMMENT); return find_comment(comment_id, SERVICE_COMMENT);
} }
/* find a host comment by id */ /* find a host comment by id */
comment *find_host_comment(unsigned long comment_id) { nagios_comment *find_host_comment(unsigned long comment_id) {
return find_comment(comment_id, HOST_COMMENT); return find_comment(comment_id, HOST_COMMENT);
} }
/* find a comment by id */ /* find a comment by id */
comment *find_comment(unsigned long comment_id, int comment_type) { nagios_comment *find_comment(unsigned long comment_id, int comment_type) {
comment *temp_comment = NULL; nagios_comment *temp_comment = NULL;
for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) { for(temp_comment = comment_list; temp_comment != NULL; temp_comment = temp_comment->next) {
if(temp_comment->comment_id == comment_id && temp_comment->comment_type == comment_type) if(temp_comment->comment_id == comment_id && temp_comment->comment_type == comment_type)
@ -735,8 +669,3 @@ comment *find_comment(unsigned long comment_id, int comment_type) {
return NULL; return NULL;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,106 @@
#include "../include/config.h" #include "../include/config.h"
#include "../include/common.h" #include "../include/common.h"
#include "../include/locations.h"
#include "../include/defaults.h"
/* /*
* This file holds random utility functions shared by cgi's and * This file holds random utility functions shared by cgi's and
* core. * core, as well as all global variables needed by both.
*/ */
extern int date_format; int date_format;
int interval_length;
char *illegal_output_chars;
char illegal_output_char_map[] = CHAR_MAP_INIT(0);
time_t program_start = 0L;
int check_external_commands;
int log_rotation_method;
char *object_cache_file;
struct object_count num_objects;
int process_performance_data;
char *status_file;
int nagios_pid = 0;
int daemon_mode = FALSE;
time_t last_log_rotation = 0L;
int check_external_commands;
int enable_timing_point = FALSE; /* cgi's never set this to TRUE */
int enable_flap_detection;
int enable_notifications;
int execute_service_checks;
int accept_passive_service_checks;
int execute_host_checks;
int accept_passive_host_checks;
int enable_event_handlers;
int obsess_over_services;
int obsess_over_hosts;
char *config_file_dir = NULL;
void init_shared_cfg_vars(int first_time) {
date_format = DATE_FORMAT_US;
interval_length = DEFAULT_INTERVAL_LENGTH;
if(first_time) {
/* Not sure why these are not reset in reset_variables() */
illegal_output_chars = NULL;
}
program_start = 0L;
log_rotation_method = LOG_ROTATION_NONE;
object_cache_file = strdup(DEFAULT_OBJECT_CACHE_FILE);
process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA;
status_file = NULL;
check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS;
enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION;
enable_notifications = TRUE;
execute_service_checks = TRUE;
accept_passive_service_checks = TRUE;
execute_host_checks = TRUE;
accept_passive_host_checks = TRUE;
enable_event_handlers = TRUE;
obsess_over_services = FALSE;
obsess_over_hosts = FALSE;
return;
}
/* silly debug-ish helper used to track down hotspots in config parsing */
void timing_point(const char *fmt, ...) {
static struct timeval last = {0, 0}, first = {0, 0};
struct timeval now;
va_list ap;
if(!enable_timing_point)
return;
if(first.tv_sec == 0) {
gettimeofday(&first, NULL);
last.tv_sec = first.tv_sec;
last.tv_usec = first.tv_usec;
printf("[0.0000 (+0.0000)] ");
}
else {
gettimeofday(&now, NULL);
printf("[%.4f (+%.4f)] ", tv_delta_f(&first, &now), tv_delta_f(&last, &now));
last.tv_sec = now.tv_sec;
last.tv_usec = now.tv_usec;
}
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
/* fix the problem with strtok() skipping empty options between tokens */ /* fix the problem with strtok() skipping empty options between tokens */
char *my_strtok(char *buffer, char *tokens) { char *my_strtok(char *buffer, const char *tokens) {
char *token_position = NULL; char *token_position = NULL;
char *sequence_head = NULL; char *sequence_head = NULL;
static char *my_strtok_buffer = NULL; static char *my_strtok_buffer = NULL;
@ -81,7 +173,7 @@ char *my_strsep(char **stringp, const char *delim) {
} }
/* open a file read-only via mmap() */ /* open a file read-only via mmap() */
mmapfile *mmap_fopen(char *filename) { mmapfile *mmap_fopen(const char *filename) {
mmapfile *new_mmapfile = NULL; mmapfile *new_mmapfile = NULL;
int fd = 0; int fd = 0;
void *mmap_buf = NULL; void *mmap_buf = NULL;
@ -400,12 +492,12 @@ void get_datetime_string(time_t * raw_time, char *buffer, int buffer_length,
int month; int month;
int day; int day;
int year; int year;
char *weekdays[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; const char *weekdays[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
char *months[12] = { const char *months[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec" "Oct", "Nov", "Dec"
}; };
char *tzone = ""; const char *tzone = "";
if(raw_time == NULL) if(raw_time == NULL)
time(&t); time(&t);
@ -425,7 +517,7 @@ void get_datetime_string(time_t * raw_time, char *buffer, int buffer_length,
year = tm_ptr->tm_year + 1900; year = tm_ptr->tm_year + 1900;
#ifdef HAVE_TM_ZONE #ifdef HAVE_TM_ZONE
tzone = (char *)(tm_ptr->tm_zone); tzone = tm_ptr->tm_zone;
#else #else
tzone = (tm_ptr->tm_isdst) ? tzname[1] : tzname[0]; tzone = (tm_ptr->tm_isdst) ? tzname[1] : tzname[0];
#endif #endif

View File

@ -2,8 +2,6 @@
* *
* STATUSDATA.C - External status data for Nagios CGIs * STATUSDATA.C - External status data for Nagios CGIs
* *
* Copyright (c) 2000-2006 Ethan Galstad (egalstad@nagios.org)
* Last Modified: 10-19-2006
* *
* License: * License:
* *
@ -28,25 +26,15 @@
#include "../include/common.h" #include "../include/common.h"
#include "../include/objects.h" #include "../include/objects.h"
#include "../include/statusdata.h" #include "../include/statusdata.h"
#include "../xdata/xsddefault.h" /* default routines */
#ifdef NSCORE #ifdef NSCGI
#include "../include/cgiutils.h"
#else
#include "../include/nagios.h" #include "../include/nagios.h"
#include "../include/broker.h" #include "../include/broker.h"
#endif #endif
#ifdef NSCGI
#include "../include/cgiutils.h"
#endif
/**** IMPLEMENTATION SPECIFIC HEADER FILES ****/
#ifdef USE_XSDDEFAULT
#include "../xdata/xsddefault.h" /* default routines */
#endif
#ifdef NSCORE
extern int aggregate_status_updates;
#endif
#ifdef NSCGI #ifdef NSCGI
hoststatus *hoststatus_list = NULL; hoststatus *hoststatus_list = NULL;
@ -69,15 +57,8 @@ extern int use_pending_states;
/******************************************************************/ /******************************************************************/
/* initializes status data at program start */ /* initializes status data at program start */
int initialize_status_data(char *config_file) { int initialize_status_data(const char *cfgfile) {
int result = OK; return xsddefault_initialize_status_data(cfgfile);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_initialize_status_data(config_file);
#endif
return result;
} }
@ -90,33 +71,19 @@ int update_all_status_data(void) {
broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_STARTDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL); broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_STARTDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif #endif
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_save_status_data(); result = xsddefault_save_status_data();
#endif
#ifdef USE_EVENT_BROKER #ifdef USE_EVENT_BROKER
/* send data to event broker */ /* send data to event broker */
broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_ENDDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL); broker_aggregated_status_data(NEBTYPE_AGGREGATEDSTATUS_ENDDUMP, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif #endif
return result;
if(result != OK)
return ERROR;
return OK;
} }
/* cleans up status data before program termination */ /* cleans up status data before program termination */
int cleanup_status_data(char *config_file, int delete_status_data) { int cleanup_status_data(int delete_status_data) {
int result = OK; return xsddefault_cleanup_status_data(delete_status_data);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_cleanup_status_data(config_file, delete_status_data);
#endif
return result;
} }
@ -130,12 +97,6 @@ int update_program_status(int aggregated_dump) {
broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, NULL); broker_program_status(NEBTYPE_PROGRAMSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, NULL);
#endif #endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if(aggregate_status_updates == FALSE)
update_all_status_data();
return OK; return OK;
} }
@ -150,12 +111,6 @@ int update_host_status(host *hst, int aggregated_dump) {
broker_host_status(NEBTYPE_HOSTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, NULL); broker_host_status(NEBTYPE_HOSTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, hst, NULL);
#endif #endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if(aggregate_status_updates == FALSE)
update_all_status_data();
return OK; return OK;
} }
@ -170,12 +125,6 @@ int update_service_status(service *svc, int aggregated_dump) {
broker_service_status(NEBTYPE_SERVICESTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, NULL); broker_service_status(NEBTYPE_SERVICESTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, svc, NULL);
#endif #endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if(aggregate_status_updates == FALSE)
update_all_status_data();
return OK; return OK;
} }
@ -190,12 +139,6 @@ int update_contact_status(contact *cntct, int aggregated_dump) {
broker_contact_status(NEBTYPE_CONTACTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cntct, NULL); broker_contact_status(NEBTYPE_CONTACTSTATUS_UPDATE, NEBFLAG_NONE, NEBATTR_NONE, cntct, NULL);
#endif #endif
/* currently a noop if aggregated updates is TRUE */
/* update all status data if we're not aggregating updates */
if(aggregate_status_updates == FALSE)
update_all_status_data();
return OK; return OK;
} }
#endif #endif
@ -212,18 +155,8 @@ int update_contact_status(contact *cntct, int aggregated_dump) {
/* reads in all status data */ /* reads in all status data */
int read_status_data(char *config_file, int options) { int read_status_data(const char *status_file_name, int options) {
int result = OK; return xsddefault_read_status_data(status_file_name, options);
/**** IMPLEMENTATION-SPECIFIC CALLS ****/
#ifdef USE_XSDDEFAULT
result = xsddefault_read_status_data(config_file, options);
#endif
#ifdef USE_XSDDB
result = xsddb_read_status_data(config_file, options);
#endif
return result;
} }
@ -333,16 +266,16 @@ int add_host_status(hoststatus *new_hoststatus) {
if(new_hoststatus != NULL) { if(new_hoststatus != NULL) {
switch(new_hoststatus->status) { switch(new_hoststatus->status) {
case 0: case 0:
new_hoststatus->status = HOST_UP; new_hoststatus->status = SD_HOST_UP;
break; break;
case 1: case 1:
new_hoststatus->status = HOST_DOWN; new_hoststatus->status = SD_HOST_DOWN;
break; break;
case 2: case 2:
new_hoststatus->status = HOST_UNREACHABLE; new_hoststatus->status = SD_HOST_UNREACHABLE;
break; break;
default: default:
new_hoststatus->status = HOST_UP; new_hoststatus->status = SD_HOST_UP;
break; break;
} }
if(new_hoststatus->has_been_checked == FALSE) { if(new_hoststatus->has_been_checked == FALSE) {
@ -569,7 +502,4 @@ int get_servicestatus_count(char *host_name, int type) {
return count; return count;
} }
#endif #endif

920
config.guess vendored

File diff suppressed because it is too large Load Diff

420
config.sub vendored
View File

@ -1,44 +1,40 @@
#! /bin/sh #! /bin/sh
# Configuration validation subroutine script. # Configuration validation subroutine script.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # Copyright 1992-2016 Free Software Foundation, Inc.
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
timestamp='2006-12-08' timestamp='2016-06-20'
# This file is (in principle) common to ALL GNU software. # This file is free software; you can redistribute it and/or modify it
# The presence of a machine in this file suggests that SOME GNU software # under the terms of the GNU General Public License as published by
# can handle that machine. It does not imply ALL GNU software can. # the Free Software Foundation; either version 3 of the License, or
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful, but
# but WITHOUT ANY WARRANTY; without even the implied warranty of # WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# GNU General Public License for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, see <http://www.gnu.org/licenses/>.
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
# 02110-1301, USA.
# #
# As a special exception to the GNU General Public License, if you # As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a # distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under # configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program. # the same distribution terms that you use for the rest of that
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
# Please send patches to <config-patches@gnu.org>. Submit a context # Please send patches to <config-patches@gnu.org>.
# diff and a properly formatted ChangeLog entry.
# #
# Configuration subroutine to validate and canonicalize a configuration type. # Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument. # Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1. # If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed. # Otherwise, we print the canonical config type on stdout and succeed.
# You can get the latest version of this script from:
# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
# This file is supposed to be the same for all GNU packages # This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases # and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software. # that are meaningful with *any* GNU software.
@ -57,8 +53,7 @@ timestamp='2006-12-08'
me=`echo "$0" | sed -e 's,.*/,,'` me=`echo "$0" | sed -e 's,.*/,,'`
usage="\ usage="\
Usage: $0 [OPTION] CPU-MFR-OPSYS Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
$0 [OPTION] ALIAS
Canonicalize a configuration name. Canonicalize a configuration name.
@ -72,8 +67,7 @@ Report bugs and patches to <config-patches@gnu.org>."
version="\ version="\
GNU config.sub ($timestamp) GNU config.sub ($timestamp)
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Copyright 1992-2016 Free Software Foundation, Inc.
Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@ -120,12 +114,18 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations. # Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in case $maybe_os in
nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \ nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
kopensolaris*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*) storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;; ;;
android-linux)
os=-linux-android
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
;;
*) *)
basic_machine=`echo $1 | sed 's/-[^-]*$//'` basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ] if [ $basic_machine != $1 ]
@ -148,10 +148,13 @@ case $os in
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-apple | -axis | -knuth | -cray) -apple | -axis | -knuth | -cray | -microblaze*)
os= os=
basic_machine=$1 basic_machine=$1
;; ;;
-bluegene*)
os=-cnk
;;
-sim | -cisco | -oki | -wec | -winbond) -sim | -cisco | -oki | -wec | -winbond)
os= os=
basic_machine=$1 basic_machine=$1
@ -166,10 +169,10 @@ case $os in
os=-chorusos os=-chorusos
basic_machine=$1 basic_machine=$1
;; ;;
-chorusrdb) -chorusrdb)
os=-chorusrdb os=-chorusrdb
basic_machine=$1 basic_machine=$1
;; ;;
-hiux*) -hiux*)
os=-hiuxwe2 os=-hiuxwe2
;; ;;
@ -214,6 +217,12 @@ case $os in
-isc*) -isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;; ;;
-lynx*178)
os=-lynxos178
;;
-lynx*5)
os=-lynxos5
;;
-lynx*) -lynx*)
os=-lynxos os=-lynxos
;; ;;
@ -238,59 +247,91 @@ case $basic_machine in
# Some are omitted here because they have special meanings below. # Some are omitted here because they have special meanings below.
1750a | 580 \ 1750a | 580 \
| a29k \ | a29k \
| aarch64 | aarch64_be \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \ | am33_2.0 \
| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \ | arc | arceb \
| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
| avr | avr32 \
| ba \
| be32 | be64 \
| bfin \ | bfin \
| c4x | clipper \ | c4x | c8051 | clipper \
| d10v | d30v | dlx | dsp16xx \ | d10v | d30v | dlx | dsp16xx \
| fido | fr30 | frv \ | e2k | epiphany \
| fido | fr30 | frv | ft32 \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i860 | i960 | ia64 \ | i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \ | ip2k | iq2000 \
| k1om \
| le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \ | m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | mcore \ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
| mips | mipsbe | mipseb | mipsel | mipsle \ | mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \ | mips16 \
| mips64 | mips64el \ | mips64 | mips64el \
| mips64vr | mips64vrel \ | mips64octeon | mips64octeonel \
| mips64orion | mips64orionel \ | mips64orion | mips64orionel \
| mips64r5900 | mips64r5900el \
| mips64vr | mips64vrel \
| mips64vr4100 | mips64vr4100el \ | mips64vr4100 | mips64vr4100el \
| mips64vr4300 | mips64vr4300el \ | mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \ | mips64vr5000 | mips64vr5000el \
| mips64vr5900 | mips64vr5900el \ | mips64vr5900 | mips64vr5900el \
| mipsisa32 | mipsisa32el \ | mipsisa32 | mipsisa32el \
| mipsisa32r2 | mipsisa32r2el \ | mipsisa32r2 | mipsisa32r2el \
| mipsisa32r6 | mipsisa32r6el \
| mipsisa64 | mipsisa64el \ | mipsisa64 | mipsisa64el \
| mipsisa64r2 | mipsisa64r2el \ | mipsisa64r2 | mipsisa64r2el \
| mipsisa64r6 | mipsisa64r6el \
| mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \ | mipsisa64sr71k | mipsisa64sr71kel \
| mipsr5900 | mipsr5900el \
| mipstx39 | mipstx39el \ | mipstx39 | mipstx39el \
| mn10200 | mn10300 \ | mn10200 | mn10300 \
| moxie \
| mt \ | mt \
| msp430 \ | msp430 \
| nios | nios2 \ | nds32 | nds32le | nds32be \
| nios | nios2 | nios2eb | nios2el \
| ns16k | ns32k \ | ns16k | ns32k \
| or32 \ | open8 | or1k | or1knd | or32 \
| pdp10 | pdp11 | pj | pjl \ | pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ | powerpc | powerpc64 | powerpc64le | powerpcle \
| pyramid \ | pyramid \
| riscv32 | riscv64 \
| rl78 | rx \
| score \ | score \
| sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \ | sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| spu | strongarm \ | spu \
| tahoe | thumb | tic4x | tic80 | tron \ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| v850 | v850e \ | ubicom32 \
| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
| visium \
| we32k \ | we32k \
| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \ | x86 | xc16x | xstormy16 | xtensa \
| z8k) | z8k | z80)
basic_machine=$basic_machine-unknown basic_machine=$basic_machine-unknown
;; ;;
m6811 | m68hc11 | m6812 | m68hc12) c54x)
# Motorola 68HC11/12. basic_machine=tic54x-unknown
;;
c55x)
basic_machine=tic55x-unknown
;;
c6x)
basic_machine=tic6x-unknown
;;
leon|leon[3-9])
basic_machine=sparc-$basic_machine
;;
m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
basic_machine=$basic_machine-unknown basic_machine=$basic_machine-unknown
os=-none os=-none
;; ;;
@ -300,6 +341,21 @@ case $basic_machine in
basic_machine=mt-unknown basic_machine=mt-unknown
;; ;;
strongarm | thumb | xscale)
basic_machine=arm-unknown
;;
xgate)
basic_machine=$basic_machine-unknown
os=-none
;;
xscaleeb)
basic_machine=armeb-unknown
;;
xscaleel)
basic_machine=armel-unknown
;;
# We use `pc' rather than `unknown' # We use `pc' rather than `unknown'
# because (1) that's what they normally are, and # because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users. # (2) the word "unknown" tends to confuse beginning users.
@ -314,64 +370,89 @@ case $basic_machine in
# Recognize the basic CPU types with company name. # Recognize the basic CPU types with company name.
580-* \ 580-* \
| a29k-* \ | a29k-* \
| aarch64-* | aarch64_be-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \ | avr-* | avr32-* \
| ba-* \
| be32-* | be64-* \
| bfin-* | bs2000-* \ | bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \
| clipper-* | craynv-* | cydra-* \ | c8051-* | clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \ | d10v-* | d30v-* | dlx-* \
| elxsi-* \ | e2k-* | elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \ | h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| hexagon-* \
| i*86-* | i860-* | i960-* | ia64-* \ | i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \ | ip2k-* | iq2000-* \
| k1om-* \
| le32-* | le64-* \
| lm32-* \
| m32c-* | m32r-* | m32rle-* \ | m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
| m88110-* | m88k-* | maxq-* | mcore-* \ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
| microblaze-* | microblazeel-* \
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
| mips16-* \ | mips16-* \
| mips64-* | mips64el-* \ | mips64-* | mips64el-* \
| mips64vr-* | mips64vrel-* \ | mips64octeon-* | mips64octeonel-* \
| mips64orion-* | mips64orionel-* \ | mips64orion-* | mips64orionel-* \
| mips64r5900-* | mips64r5900el-* \
| mips64vr-* | mips64vrel-* \
| mips64vr4100-* | mips64vr4100el-* \ | mips64vr4100-* | mips64vr4100el-* \
| mips64vr4300-* | mips64vr4300el-* \ | mips64vr4300-* | mips64vr4300el-* \
| mips64vr5000-* | mips64vr5000el-* \ | mips64vr5000-* | mips64vr5000el-* \
| mips64vr5900-* | mips64vr5900el-* \ | mips64vr5900-* | mips64vr5900el-* \
| mipsisa32-* | mipsisa32el-* \ | mipsisa32-* | mipsisa32el-* \
| mipsisa32r2-* | mipsisa32r2el-* \ | mipsisa32r2-* | mipsisa32r2el-* \
| mipsisa32r6-* | mipsisa32r6el-* \
| mipsisa64-* | mipsisa64el-* \ | mipsisa64-* | mipsisa64el-* \
| mipsisa64r2-* | mipsisa64r2el-* \ | mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64r6-* | mipsisa64r6el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \ | mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \ | mipsisa64sr71k-* | mipsisa64sr71kel-* \
| mipsr5900-* | mipsr5900el-* \
| mipstx39-* | mipstx39el-* \ | mipstx39-* | mipstx39el-* \
| mmix-* \ | mmix-* \
| mt-* \ | mt-* \
| msp430-* \ | msp430-* \
| nios-* | nios2-* \ | nds32-* | nds32le-* | nds32be-* \
| nios-* | nios2-* | nios2eb-* | nios2el-* \
| none-* | np1-* | ns16k-* | ns32k-* \ | none-* | np1-* | ns16k-* | ns32k-* \
| open8-* \
| or1k*-* \
| orion-* \ | orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
| pyramid-* \ | pyramid-* \
| romp-* | rs6000-* \ | riscv32-* | riscv64-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | rl78-* | romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \ | sparclite-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
| tahoe-* | thumb-* \ | tahoe-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tile*-* \
| tron-* \ | tron-* \
| v850-* | v850e-* | vax-* \ | ubicom32-* \
| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
| vax-* \
| visium-* \
| we32k-* \ | we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \
| xstormy16-* | xtensa-* \ | xstormy16-* | xtensa*-* \
| ymp-* \ | ymp-* \
| z8k-*) | z8k-* | z80-*)
;;
# Recognize the basic CPU types without company name, with glob match.
xtensa*)
basic_machine=$basic_machine-unknown
;; ;;
# Recognize the various machine names and aliases which stand # Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS. # for a CPU type and a company and sometimes even an OS.
@ -389,7 +470,7 @@ case $basic_machine in
basic_machine=a29k-amd basic_machine=a29k-amd
os=-udi os=-udi
;; ;;
abacus) abacus)
basic_machine=abacus-unknown basic_machine=abacus-unknown
;; ;;
adobe68k) adobe68k)
@ -435,6 +516,13 @@ case $basic_machine in
basic_machine=m68k-apollo basic_machine=m68k-apollo
os=-bsd os=-bsd
;; ;;
aros)
basic_machine=i386-pc
os=-aros
;;
asmjs)
basic_machine=asmjs-unknown
;;
aux) aux)
basic_machine=m68k-apple basic_machine=m68k-apple
os=-aux os=-aux
@ -443,10 +531,35 @@ case $basic_machine in
basic_machine=ns32k-sequent basic_machine=ns32k-sequent
os=-dynix os=-dynix
;; ;;
blackfin)
basic_machine=bfin-unknown
os=-linux
;;
blackfin-*)
basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
bluegene*)
basic_machine=powerpc-ibm
os=-cnk
;;
c54x-*)
basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c55x-*)
basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c6x-*)
basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c90) c90)
basic_machine=c90-cray basic_machine=c90-cray
os=-unicos os=-unicos
;; ;;
cegcc)
basic_machine=arm-unknown
os=-cegcc
;;
convex-c1) convex-c1)
basic_machine=c1-convex basic_machine=c1-convex
os=-bsd os=-bsd
@ -475,8 +588,8 @@ case $basic_machine in
basic_machine=craynv-cray basic_machine=craynv-cray
os=-unicosmp os=-unicosmp
;; ;;
cr16c) cr16 | cr16-*)
basic_machine=cr16c-unknown basic_machine=cr16-unknown
os=-elf os=-elf
;; ;;
crds | unos) crds | unos)
@ -514,6 +627,10 @@ case $basic_machine in
basic_machine=m88k-motorola basic_machine=m88k-motorola
os=-sysv3 os=-sysv3
;; ;;
dicos)
basic_machine=i686-pc
os=-dicos
;;
djgpp) djgpp)
basic_machine=i586-pc basic_machine=i586-pc
os=-msdosdjgpp os=-msdosdjgpp
@ -526,6 +643,14 @@ case $basic_machine in
basic_machine=m68k-bull basic_machine=m68k-bull
os=-sysv3 os=-sysv3
;; ;;
e500v[12])
basic_machine=powerpc-unknown
os=$os"spe"
;;
e500v[12]-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
os=$os"spe"
;;
ebmon29k) ebmon29k)
basic_machine=a29k-amd basic_machine=a29k-amd
os=-ebmon os=-ebmon
@ -629,7 +754,6 @@ case $basic_machine in
i370-ibm* | ibm*) i370-ibm* | ibm*)
basic_machine=i370-ibm basic_machine=i370-ibm
;; ;;
# I'm not sure what "Sysv32" means. Should this be sysv3.2?
i*86v32) i*86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32 os=-sysv32
@ -668,6 +792,17 @@ case $basic_machine in
basic_machine=m68k-isi basic_machine=m68k-isi
os=-sysv os=-sysv
;; ;;
leon-*|leon[3-9]-*)
basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`
;;
m68knommu)
basic_machine=m68k-unknown
os=-linux
;;
m68knommu-*)
basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
m88k-omron*) m88k-omron*)
basic_machine=m88k-omron basic_machine=m88k-omron
;; ;;
@ -679,10 +814,21 @@ case $basic_machine in
basic_machine=ns32k-utek basic_machine=ns32k-utek
os=-sysv os=-sysv
;; ;;
microblaze*)
basic_machine=microblaze-xilinx
;;
mingw64)
basic_machine=x86_64-pc
os=-mingw64
;;
mingw32) mingw32)
basic_machine=i386-pc basic_machine=i686-pc
os=-mingw32 os=-mingw32
;; ;;
mingw32ce)
basic_machine=arm-unknown
os=-mingw32ce
;;
miniframe) miniframe)
basic_machine=m68000-convergent basic_machine=m68000-convergent
;; ;;
@ -704,6 +850,10 @@ case $basic_machine in
basic_machine=powerpc-unknown basic_machine=powerpc-unknown
os=-morphos os=-morphos
;; ;;
moxiebox)
basic_machine=moxie-unknown
os=-moxiebox
;;
msdos) msdos)
basic_machine=i386-pc basic_machine=i386-pc
os=-msdos os=-msdos
@ -711,10 +861,18 @@ case $basic_machine in
ms1-*) ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;; ;;
msys)
basic_machine=i686-pc
os=-msys
;;
mvs) mvs)
basic_machine=i370-ibm basic_machine=i370-ibm
os=-mvs os=-mvs
;; ;;
nacl)
basic_machine=le32-unknown
os=-nacl
;;
ncr3000) ncr3000)
basic_machine=i486-ncr basic_machine=i486-ncr
os=-sysv4 os=-sysv4
@ -779,6 +937,12 @@ case $basic_machine in
np1) np1)
basic_machine=np1-gould basic_machine=np1-gould
;; ;;
neo-tandem)
basic_machine=neo-tandem
;;
nse-tandem)
basic_machine=nse-tandem
;;
nsr-tandem) nsr-tandem)
basic_machine=nsr-tandem basic_machine=nsr-tandem
;; ;;
@ -809,6 +973,14 @@ case $basic_machine in
basic_machine=i860-intel basic_machine=i860-intel
os=-osf os=-osf
;; ;;
parisc)
basic_machine=hppa-unknown
os=-linux
;;
parisc-*)
basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
pbd) pbd)
basic_machine=sparc-tti basic_machine=sparc-tti
;; ;;
@ -853,9 +1025,10 @@ case $basic_machine in
;; ;;
power) basic_machine=power-ibm power) basic_machine=power-ibm
;; ;;
ppc) basic_machine=powerpc-unknown ppc | ppcbe) basic_machine=powerpc-unknown
;; ;;
ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;; ;;
ppcle | powerpclittle | ppc-le | powerpc-little) ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown basic_machine=powerpcle-unknown
@ -880,7 +1053,11 @@ case $basic_machine in
basic_machine=i586-unknown basic_machine=i586-unknown
os=-pw32 os=-pw32
;; ;;
rdos) rdos | rdos64)
basic_machine=x86_64-pc
os=-rdos
;;
rdos32)
basic_machine=i386-pc basic_machine=i386-pc
os=-rdos os=-rdos
;; ;;
@ -949,6 +1126,9 @@ case $basic_machine in
basic_machine=i860-stratus basic_machine=i860-stratus
os=-sysv4 os=-sysv4
;; ;;
strongarm-* | thumb-*)
basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
sun2) sun2)
basic_machine=m68000-sun basic_machine=m68000-sun
;; ;;
@ -1005,17 +1185,9 @@ case $basic_machine in
basic_machine=t90-cray basic_machine=t90-cray
os=-unicos os=-unicos
;; ;;
tic54x | c54x*) tile*)
basic_machine=tic54x-unknown basic_machine=$basic_machine-unknown
os=-coff os=-linux-gnu
;;
tic55x | c55x*)
basic_machine=tic55x-unknown
os=-coff
;;
tic6x | c6x*)
basic_machine=tic6x-unknown
os=-coff
;; ;;
tx39) tx39)
basic_machine=mipstx39-unknown basic_machine=mipstx39-unknown
@ -1084,6 +1256,9 @@ case $basic_machine in
xps | xps100) xps | xps100)
basic_machine=xps100-honeywell basic_machine=xps100-honeywell
;; ;;
xscale-* | xscalee[bl]-*)
basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
;;
ymp) ymp)
basic_machine=ymp-cray basic_machine=ymp-cray
os=-unicos os=-unicos
@ -1092,6 +1267,10 @@ case $basic_machine in
basic_machine=z8k-unknown basic_machine=z8k-unknown
os=-sim os=-sim
;; ;;
z80-*-coff)
basic_machine=z80-unknown
os=-sim
;;
none) none)
basic_machine=none-none basic_machine=none-none
os=-none os=-none
@ -1130,7 +1309,7 @@ case $basic_machine in
we32k) we32k)
basic_machine=we32k-att basic_machine=we32k-att
;; ;;
sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
basic_machine=sh-unknown basic_machine=sh-unknown
;; ;;
sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v) sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
@ -1177,9 +1356,12 @@ esac
if [ x"$os" != x"" ] if [ x"$os" != x"" ]
then then
case $os in case $os in
# First match some system type aliases # First match some system type aliases
# that might get confused with valid system types. # that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception. # -solaris* is a basic system type, with this one exception.
-auroraux)
os=-auroraux
;;
-solaris1 | -solaris1.*) -solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'` os=`echo $os | sed -e 's|solaris1|sunos4|'`
;; ;;
@ -1200,29 +1382,32 @@ case $os in
# Each alternative MUST END IN A *, to match a version number. # Each alternative MUST END IN A *, to match a version number.
# -sysv* is not here because it comes later, after sysvr4. # -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* \ | -aos* | -aros* | -cloudabi* | -sortix* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
| -openbsd* | -solidbsd* \ | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
| -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
| -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* \ | -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
| -uxpv* | -beos* | -mpeix* | -udk* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos* | -toppers*) | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
| -onefs* | -tirtos* | -phoenix*)
# Remember, each alternative MUST END IN *, to match a version number. # Remember, each alternative MUST END IN *, to match a version number.
;; ;;
-qnx*) -qnx*)
@ -1261,7 +1446,7 @@ case $os in
-opened*) -opened*)
os=-openedition os=-openedition
;; ;;
-os400*) -os400*)
os=-os400 os=-os400
;; ;;
-wince*) -wince*)
@ -1310,7 +1495,7 @@ case $os in
-sinix*) -sinix*)
os=-sysv4 os=-sysv4
;; ;;
-tpf*) -tpf*)
os=-tpf os=-tpf
;; ;;
-triton*) -triton*)
@ -1346,12 +1531,16 @@ case $os in
-aros*) -aros*)
os=-aros os=-aros
;; ;;
-kaos*)
os=-kaos
;;
-zvmoe) -zvmoe)
os=-zvmoe os=-zvmoe
;; ;;
-dicos*)
os=-dicos
;;
-nacl*)
;;
-ios)
;;
-none) -none)
;; ;;
*) *)
@ -1374,10 +1563,10 @@ else
# system, and we'll never get to this point. # system, and we'll never get to this point.
case $basic_machine in case $basic_machine in
score-*) score-*)
os=-elf os=-elf
;; ;;
spu-*) spu-*)
os=-elf os=-elf
;; ;;
*-acorn) *-acorn)
@ -1389,8 +1578,23 @@ case $basic_machine in
arm*-semi) arm*-semi)
os=-aout os=-aout
;; ;;
c4x-* | tic4x-*) c4x-* | tic4x-*)
os=-coff os=-coff
;;
c8051-*)
os=-elf
;;
hexagon-*)
os=-elf
;;
tic54x-*)
os=-coff
;;
tic55x-*)
os=-coff
;;
tic6x-*)
os=-coff
;; ;;
# This must come before the *-dec entry. # This must come before the *-dec entry.
pdp10-*) pdp10-*)
@ -1410,13 +1614,13 @@ case $basic_machine in
;; ;;
m68000-sun) m68000-sun)
os=-sunos3 os=-sunos3
# This also exists in the configure program, but was not the
# default.
# os=-sunos4
;; ;;
m68*-cisco) m68*-cisco)
os=-aout os=-aout
;; ;;
mep-*)
os=-elf
;;
mips*-cisco) mips*-cisco)
os=-elf os=-elf
;; ;;
@ -1441,7 +1645,7 @@ case $basic_machine in
*-ibm) *-ibm)
os=-aix os=-aix
;; ;;
*-knuth) *-knuth)
os=-mmixware os=-mmixware
;; ;;
*-wec) *-wec)
@ -1546,7 +1750,7 @@ case $basic_machine in
-sunos*) -sunos*)
vendor=sun vendor=sun
;; ;;
-aix*) -cnk*|-aix*)
vendor=ibm vendor=ibm
;; ;;
-beos*) -beos*)

10056
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -5,13 +5,14 @@ define([AC_CACHE_LOAD],)
define([AC_CACHE_SAVE],) define([AC_CACHE_SAVE],)
AC_INIT(base/nagios.c) AC_INIT(base/nagios.c)
AC_CONFIG_HEADER(include/config.h include/snprintf.h) AC_CONFIG_HEADER(include/config.h lib/snprintf.h lib/iobroker.h)
AC_PREFIX_DEFAULT(/usr/local/nagios) AC_PREFIX_DEFAULT(/usr/local/nagios)
PKG_NAME=nagios PKG_NAME=nagios
PKG_VERSION="3.5.1"
PKG_HOME_URL="http://www.nagios.org/" PKG_VERSION="4.3.2"
PKG_REL_DATE="08-30-2013" PKG_HOME_URL="https://www.nagios.org/"
PKG_REL_DATE="2017-05-09"
dnl Figure out how to invoke "install" and what install options to use. dnl Figure out how to invoke "install" and what install options to use.
AC_PROG_INSTALL AC_PROG_INSTALL
@ -20,16 +21,25 @@ AC_SUBST(INSTALL)
dnl What OS are we running? dnl What OS are we running?
AC_CANONICAL_HOST AC_CANONICAL_HOST
AC_CONFIG_FILES([html/index.php])
dnl Checks for programs. dnl Checks for programs.
AC_PROG_CC AC_PROG_CC
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
AC_PROG_LN_S
AC_PATH_PROG([STRIP],[strip],[true]) AC_PATH_PROG([STRIP],[strip],[true])
dnl Checks for header files. dnl Checks for header files.
AC_HEADER_STDC AC_HEADER_STDC
AC_HEADER_TIME AC_HEADER_TIME
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(arpa/inet.h ctype.h dirent.h errno.h fcntl.h getopt.h grp.h libgen.h limits.h math.h netdb.h netinet/in.h pthread.h pthreads.h pwd.h regex.h signal.h socket.h stdarg.h string.h strings.h sys/mman.h sys/types.h sys/time.h sys/resource.h sys/wait.h sys/socket.h sys/stat.h sys/timeb.h sys/un.h sys/ipc.h sys/msg.h sys/poll.h syslog.h uio.h unistd.h locale.h wchar.h) AC_CHECK_HEADERS(arpa/inet.h ctype.h dirent.h errno.h fcntl.h getopt.h grp.h)
AC_CHECK_HEADERS(libgen.h limits.h math.h netdb.h netinet/in.h pwd.h regex.h)
AC_CHECK_HEADERS(signal.h socket.h stdarg.h string.h strings.h sys/loadavg.h)
AC_CHECK_HEADERS(sys/mman.h sys/types.h sys/time.h sys/resource.h sys/wait.h)
AC_CHECK_HEADERS(sys/socket.h sys/stat.h sys/timeb.h sys/un.h sys/ipc.h)
AC_CHECK_HEADERS(sys/msg.h sys/poll.h syslog.h uio.h unistd.h locale.h wchar.h)
AC_CHECK_HEADERS(sys/prctl.h)
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
@ -61,10 +71,11 @@ else
fi fi
fi fi
AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O=../common/snprintf.o) AC_CHECK_FUNC(vsnprintf,,SNPRINTF_O=../lib/snprintf.o)
AC_CHECK_FUNC(snprintf,,SNPRINTF_O=../common/snprintf.o) AC_CHECK_FUNC(snprintf,,SNPRINTF_O=../lib/snprintf.o)
AC_CHECK_FUNC(asprintf,,SNPRINTF_O=../common/snprintf.o) AC_CHECK_FUNC(asprintf,,SNPRINTF_O=../lib/snprintf.o)
AC_CHECK_FUNC(vasprintf,,SNPRINTF_O=../common/snprintf.o) AC_CHECK_FUNC(vasprintf,,SNPRINTF_O=../lib/snprintf.o)
AC_CHECK_FUNCS(sigaction)
AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[ AC_CACHE_CHECK([for C99 vsnprintf],ac_cv_HAVE_C99_VSNPRINTF,[
AC_TRY_RUN([ AC_TRY_RUN([
@ -122,79 +133,26 @@ AC_TRY_COMPILE([#include <stdlib.h>
[AC_DEFINE(SOCKET_SIZE_TYPE, int, [typedef for socket size]) AC_MSG_RESULT(int)]) [AC_DEFINE(SOCKET_SIZE_TYPE, int, [typedef for socket size]) AC_MSG_RESULT(int)])
dnl Test for pthreads support - taken from ICU FreeBSD Port configure script
THREADLIBS=""
have_pthreads="no"
dnl FreeBSD: Try ports/linuxthreads first - Mammad Zadeh <mammad@yahoo-inc.com>
dnl FreeBSD -pthread check - Jonathan McDowell <noodles@earth.li>
AC_DEFUN([AC_PTHREAD_FREEBSD],[
AC_CHECK_LIB(lthread,pthread_create,[
CFLAGS="-D_THREAD_SAFE -I/usr/local/include/pthread/linuxthreads -I/usr/include $CFLAGS"
THREADLIBS="-L/usr/local/lib -llthread -llgcc_r"
],[
AC_MSG_CHECKING([if we need -pthread for threads])
AC_CACHE_VAL(ac_ldflag_pthread,[
ac_save_LDFLAGS="$LDFLAGS"
LDFLAGS="-pthread $LDFLAGS"
AC_TRY_LINK([
char pthread_create();
],
pthread_create();,
eval "ac_ldflag_pthread=yes",
eval "ac_ldflag_pthread=no"
),
THREADLIBS="$ac_save_LDFLAGS"
])
if eval "test \"`echo $ac_ldflag_pthread`\" = yes"; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
fi
],-L/usr/local/lib)
])
dnl Test for HPUX cma threads first..
AC_CHECK_LIB(cma,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_cma_pthread_create = yes; then
have_pthreads="yes"
fi
dnl special pthread handling
dnl AIX uses pthreads instead of pthread, and HP/UX uses cma
dnl FreeBSD users -pthread
AC_CHECK_LIB(pthread,pthread_create,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_pthread_pthread_create = yes; then
have_pthreads="yes"
else
dnl For HP 11
AC_CHECK_LIB(pthread,pthread_mutex_init,THREADLIBS="$THREADLIBS -lpthread")
if test $ac_cv_lib_pthread_pthread_mutex_init = yes; then
have_pthreads="yes"
fi
fi
dnl AIX uses pthreads instead of pthread
if test $have_pthreads = "no"; then
AC_CHECK_LIB(pthreads,pthread_create,THREADLIBS="$THREADLIBS -lpthreads")
if test $ac_cv_lib_pthreads_pthread_create = yes; then
have_pthreads="yes"
fi
fi
dnl all other thread tests fail, try BSD's -pthread
if test $have_pthreads = "no"; then
AC_PTHREAD_FREEBSD
fi
AC_SUBST(THREADLIBS)
dnl Solaris needs rt or posix4 libraries for nanosleep() dnl Solaris needs rt or posix4 libraries for nanosleep()
AC_SEARCH_LIBS(nanosleep,[rt posix4],,[ AC_SEARCH_LIBS(nanosleep,[rt posix4],,[
echo "Error: nanosleep() needed for timing operations." echo "Error: nanosleep() needed for timing operations."
exit 1 exit 1
]) ])
case $host_os in
*bsd*|darwin*)
root_grp=wheel
;;
*)
root_grp=root
;;
esac
AC_ARG_WITH(root_group,AC_HELP_STRING([--with-root-group=<grp>],[sets group name for installing init]),root_grp=$withval)
AC_SUBST(root_grp)
INIT_OPTS="-o root -g $root_grp"
AC_SUBST(INIT_OPTS)
AC_ARG_WITH(nagios_user,AC_HELP_STRING([--with-nagios-user=<user>],[sets user name to run nagios]),nagios_user=$withval,nagios_user=nagios) AC_ARG_WITH(nagios_user,AC_HELP_STRING([--with-nagios-user=<user>],[sets user name to run nagios]),nagios_user=$withval,nagios_user=nagios)
AC_ARG_WITH(nagios_group,AC_HELP_STRING([--with-nagios-group=<grp>],[sets group name to run nagios]),nagios_grp=$withval,nagios_grp=nagios) AC_ARG_WITH(nagios_group,AC_HELP_STRING([--with-nagios-group=<grp>],[sets group name to run nagios]),nagios_grp=$withval,nagios_grp=nagios)
AC_SUBST(nagios_user) AC_SUBST(nagios_user)
@ -213,7 +171,12 @@ AC_SUBST(COMMAND_OPTS)
dnl Check for location of mail program dnl Check for location of mail program
MAIL_PROG=no MAIL_PROG=no
AC_ARG_WITH(mail,--with-mail=<path_to_mail> sets path to equivalent program to mail,MAIL_PROG=$withval,MAIL_PROG=no) AC_ARG_WITH(mail,
AC_HELP_STRING([--with-mail=<path_to_mail>],
[sets path to equivalent program to mail]),
MAIL_PROG=$withval,
MAIL_PROG=no
)
if test x$MAIL_PROG = xno; then if test x$MAIL_PROG = xno; then
AC_PATH_PROG(MAIL_PROG,mail) AC_PATH_PROG(MAIL_PROG,mail)
fi fi
@ -225,12 +188,25 @@ AC_SUBST(MAIL_PROG)
dnl Check for location of Apache conf.d directory dnl Check for location of Apache conf.d directory
HTTP_CONF=no HTTP_CONF=no
AC_ARG_WITH(httpd_conf,--with-httpd-conf=<path_to_conf> sets path to Apache conf.d directory,HTTPD_CONF=$withval,HTTPD_CONF=no) AC_ARG_WITH(httpd_conf,
AC_HELP_STRING([--with-httpd-conf=<path_to_conf>],
[sets path to Apache conf.d directory]),
HTTPD_CONF=$withval,
HTTPD_CONF=no
)
LN_HTTPD_SITES_ENABLED=0
if test x$HTTPD_CONF = xno; then if test x$HTTPD_CONF = xno; then
if test -d /etc/httpd/conf.d; then if test -d /etc/httpd/conf.d; then
HTTPD_CONF="/etc/httpd/conf.d" HTTPD_CONF="/etc/httpd/conf.d"
elif test -d /etc/apache2/conf.d; then elif test -d /etc/apache2/conf.d; then
HTTPD_CONF="/etc/apache2/conf.d" HTTPD_CONF="/etc/apache2/conf.d"
elif test -d /etc/apache2/sites-available; then
HTTPD_CONF="/etc/apache2/sites-available"
if test -d /etc/apache2/sites-enabled; then
LN_HTTPD_SITES_ENABLED=1
fi
elif test -d /etc/apache2/sites-enabled; then
HTTPD_CONF="/etc/apache2/sites-enabled"
elif test -d /etc/apache/conf.d; then elif test -d /etc/apache/conf.d; then
HTTPD_CONF="/etc/apache/conf.d" HTTPD_CONF="/etc/apache/conf.d"
else else
@ -238,10 +214,16 @@ if test x$HTTPD_CONF = xno; then
fi fi
fi fi
AC_SUBST(HTTPD_CONF) AC_SUBST(HTTPD_CONF)
AC_SUBST(LN_HTTPD_SITES_ENABLED)
dnl Location of check result path dnl Location of check result path
CHECKRESULTDIR=no CHECKRESULTDIR=no
AC_ARG_WITH(checkresult-dir,--with-checkresult-dir=<path> sets path to check results spool directory,CHECKRESULTDIR=$withval,CHECKRESULTDIR=no) AC_ARG_WITH(checkresult-dir,
AC_HELP_STRING([--with-checkresult-dir=<path>],
[sets path to check results spool directory]),
CHECKRESULTDIR=$withval,
CHECKRESULTDIR=no
)
if test x$CHECKRESULTDIR = xno; then if test x$CHECKRESULTDIR = xno; then
CHECKRESULTDIR="$localstatedir/spool/checkresults" CHECKRESULTDIR="$localstatedir/spool/checkresults"
fi fi
@ -249,7 +231,12 @@ AC_SUBST(CHECKRESULTDIR)
dnl Location of check result path dnl Location of check result path
TMPDIR=no TMPDIR=no
AC_ARG_WITH(temp-dir,--with-temp-dir=<path> sets path to temp directory,TMPDIR=$withval,TMPDIR=no) AC_ARG_WITH(temp-dir,
AC_HELP_STRING([--with-temp-dir=<path>],
[sets path to temp directory]),
TMPDIR=$withval,
TMPDIR=no
)
if test x$TMPDIR = xno; then if test x$TMPDIR = xno; then
TMPDIR="/tmp" TMPDIR="/tmp"
fi fi
@ -270,114 +257,150 @@ elif test -d /sbin/init.d; then
fi fi
dnl User can override init script location dnl User can override init script location
AC_ARG_WITH(init_dir,--with-init-dir=<path> sets directory to place init script into,init_dir=$withval) AC_ARG_WITH(init_dir,
AC_HELP_STRING([--with-init-dir=<path>],
[sets directory to place init script into]),
init_dir=$withval
)
AC_SUBST(init_dir) AC_SUBST(init_dir)
dnl User can override lock file location dnl User can override lock file location
AC_ARG_WITH(lockfile,--with-lockfile=<path> sets path and file name for lock file,lockfile=$withval,lockfile=$localstatedir/nagios.lock) AC_ARG_WITH(lockfile,
AC_HELP_STRING([--with-lockfile=<path>],
[sets path and file name for lock file]),
lockfile=$withval,
lockfile=$localstatedir/nagios.lock
)
AC_SUBST(lockfile) AC_SUBST(lockfile)
dnl Determine the library to be used by the iobroker
dnl Default xdata routines... dnl epoll_*() is linux specific and was added to glibc 2.3.2, so we
XSDTYPE=default dnl check for 2.4 and use epoll() if we're on that version or later.
XCDTYPE=default
XRDTYPE=default
XODTYPE=template
XPDTYPE=default
XDDTYPE=default
XSDCOMMENT= case $host_os in
XCDCOMMENT= linux*)
XRDCOMMENT= AC_MSG_CHECKING(for glibc at least version 2.4)
XODCOMMENT= AC_TRY_CPP(
XPDCOMMENT= [
XDDCOMMENT= #include <stdio.h>
#if defined(__GLIBC__) && defined(__linux)
#include <features.h>
# if !__GLIBC_PREREQ(2, 4)
# error GLIBC too old
# endif
#else
# error Not using GLIBC
#endif
],
[GLIBC_NEWER_2_4=1; AC_MSG_RESULT(yes)],
[GLIBC_NEWER_2_4=0; AC_MSG_RESULT(no)]
)
if test $GLIBC_NEWER_2_4 -eq 1; then
AC_CHECK_HEADER([sys/epoll.h])
fi
;;
esac
AC_CHECK_HEADER([sys/select.h])
USE_MYSQL=no AC_ARG_WITH(iobroker,
USE_PGSQL=no AC_HELP_STRING([--with-iobroker=<method>],
[specify the method to use with iobroker: epoll, poll, or select]),
dnl Status data IOBROKER_METHOD=$withval,
AC_DEFINE_UNQUOTED(USE_XSDDEFAULT,,[use default routines (in xdata/xsddefault.*) for status data I/O...]) IOBROKER_METHOD="none"
XSDC="xsddefault.c" )
XSDH="xsddefault.h"
XSDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xsddefault.*) for status data I/O..."
AC_SUBST(XSDC)
AC_SUBST(XSDH)
dnl Comment data
AC_DEFINE_UNQUOTED(USE_XCDDEFAULT,,[use default routines (in xdata/xcddefault.*) for comment data I/O...])
XCDC="xcddefault.c"
XCDH="xcddefault.h"
XCDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xcddefault.*) for comment data I/O..."
AC_SUBST(XCDC)
AC_SUBST(XCDH)
dnl Retention data
AC_DEFINE_UNQUOTED(USE_XRDDEFAULT,,[use default routines (in xdata/xrddefault.*) for retention data I/O...])
XRDC="xrddefault.c"
XRDH="xrddefault.h"
XRDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xrddefault.*) for retention data I/O..."
AC_SUBST(XRDC)
AC_SUBST(XRDH)
dnl Object data
AC_DEFINE_UNQUOTED(USE_XODTEMPLATE,,[use template-based routines (in xdata/xodtemplate.*) for object data I/O...])
XODC="xodtemplate.c"
XODH="xodtemplate.h"
XODCOMMENT="Template-based (text file)"
echo "We'll use template-based routines (in xdata/xodtemplate.*) for object data I/O..."
AC_SUBST(XODC)
AC_SUBST(XODH)
dnl Performance data
AC_DEFINE_UNQUOTED(USE_XPDDEFAULT,,[use default routines (in xdata/xpddefault.*) for performance data I/O...])
XPDC="xpddefault.c"
XPDH="xpddefault.h"
XPDCOMMENT="Default (external commands)"
echo "We'll use default routines (in xdata/xpddefault.*) for performance data I/O..."
AC_SUBST(XPDC)
AC_SUBST(XPDH)
dnl Downtime data
AC_DEFINE_UNQUOTED(USE_XDDDEFAULT,,[use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O...])
XDDC="xdddefault.c"
XDDH="xdddefault.h"
XDDCOMMENT="Default (text file)"
echo "We'll use default routines (in xdata/xdddefault.*) for scheduled downtime data I/O..."
AC_SUBST(XDDC)
AC_SUBST(XDDH)
case $IOBROKER_METHOD in
epoll*)
if test $GLIBC_NEWER_2_4 -eq 1 -a x$ac_cv_header_sys_epoll_h = xyes ; then
AC_DEFINE([IOBROKER_USES_EPOLL])
else
echo "\"epoll\" is not available as an iobroker method."
echo "Please use one of the other options."
exit 1
fi
;;
poll*)
if test x$ac_cv_header_sys_poll_h = xyes -o x$ac_cv_header_poll_h = xyes ; then
AC_DEFINE([IOBROKER_USES_POLL])
else
echo "\"poll\" is not available as an iobroker method."
echo "Please use one of the other options."
exit 1
fi
;;
select*)
if test x$ac_cv_header_sys_select_h = xyes ; then
AC_DEFINE([IOBROKER_USES_SELECT])
else
echo "\"select\" is not available as an iobroker method."
echo "Please use one of the other options."
exit 1
fi
;;
none*)
if test $GLIBC_NEWER_2_4 -eq 1 -a x$ac_cv_header_sys_epoll_h = xyes ; then
AC_DEFINE([IOBROKER_USES_EPOLL])
IOBROKER_METHOD="epoll"
elif test x$ac_cv_header_sys_poll_h = xyes -o x$ac_cv_header_poll_h = xyes ; then
AC_DEFINE([IOBROKER_USES_POLL])
IOBROKER_METHOD="poll"
elif test x$ac_cv_header_sys_select_h = xyes ; then
AC_DEFINE([IOBROKER_USES_SELECT])
IOBROKER_METHOD="select"
else
echo "There are no available options for iobroker polling"
exit 1
fi
;;
*)
echo "\"$IOBROKER_METHOD\" is not a valid method for --with-iobroker"
exit 1
;;
esac
dnl Optional GD library and include paths dnl Optional GD library and include paths
AC_ARG_WITH(gd-lib,--with-gd-lib=DIR sets location of the gd library,[ AC_ARG_WITH(gd-lib,
LDFLAGS="${LDFLAGS} -L${withval}" AC_HELP_STRING([--with-gd-lib=DIR],[sets location of the gd library]),
LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}" [
]) LDFLAGS="${LDFLAGS} -L${withval}"
AC_ARG_WITH(gd-inc,--with-gd-inc=DIR sets location of the gd include files,[ LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"
CFLAGS="${CFLAGS} -I${withval}" ]
]) )
AC_ARG_WITH(gd-inc,
AC_HELP_STRING([--with-gd-inc=DIR],[sets location of the gd include files]),
[CFLAGS="${CFLAGS} -I${withval}"]
)
TRYGD=yep TRYGD=yep
dnl 'corewindow' is now disabled. Allow it to be enabled if someone wants it
COREWINDOW=no
AC_ARG_ENABLE(corewindow,
AC_HELP_STRING([--enable-corewindow],
[enables the 'corewindow' URL argument]),
COREWINDOW=yes
)
AC_SUBST(COREWINDOW)
dnl statusmap CGI enabled by default, unless users chooses not to use it dnl statusmap CGI enabled by default, unless users chooses not to use it
TRYSTATUSMAP=yep TRYSTATUSMAP=yep
AC_ARG_ENABLE(statusmap,--disable-statusmap=disables compilation of statusmap CGI,TRYSTATUSMAP=nope) AC_ARG_ENABLE(statusmap,
AC_HELP_STRING([--disable-statusmap],
[disables compilation of statusmap CGI]),
TRYSTATUSMAP=nope
)
dnl statuswrl CGI enabled by default, unless users chooses not to use it dnl statuswrl CGI enabled by default, unless users chooses not to use it
TRYSTATUSWRL=yep TRYSTATUSWRL=yep
AC_ARG_ENABLE(statuswrl,--disable-statuswrl=disables compilation of statuswrl (VRML) CGI,TRYSTATUSWRL=nope) AC_ARG_ENABLE(statuswrl,
AC_HELP_STRING([--disable-statuswrl],
[disables compilation of statuswrl (VRML) CGI]),
TRYSTATUSWRL=nope
)
if test x$TRYSTATUSWRL = xyep; then if test x$TRYSTATUSWRL = xyep; then
AC_DEFINE_UNQUOTED(USE_STATUSWRL,,[statuswrl CGI enabled by default, unless users chooses not to use it]) AC_DEFINE_UNQUOTED(USE_STATUSWRL,,[statuswrl CGI enabled by default, unless users chooses not to use it])
@ -527,19 +550,39 @@ if test x$TRYGD = xyep; then
fi fi
fi fi
AC_ARG_WITH(cgiurl,--with-cgiurl=<local-url> sets URL for cgi programs (do not use a trailing slash),cgiurl=$withval,cgiurl=/nagios/cgi-bin) AC_ARG_WITH(cgiurl,
AC_ARG_WITH(htmurl,--with-htmurl=<local-url> sets URL for public html,htmurl=$withval,htmurl=/nagios) AC_HELP_STRING([--with-cgiurl=<local-url>],
[sets URL for cgi programs (do not use a trailing slash)]),
cgiurl=$withval,
cgiurl=/nagios/cgi-bin
)
AC_ARG_WITH(htmurl,
AC_HELP_STRING([--with-htmurl=<local-url>],
[sets URL for public html]),
htmurl=$withval,
htmurl=/nagios
)
AC_SUBST(htmurl) AC_SUBST(htmurl)
AC_SUBST(cgiurl) AC_SUBST(cgiurl)
USE_NANOSLEEP=yes USE_NANOSLEEP=yes
AC_ARG_ENABLE(nanosleep,--enable-nanosleep enables use of nanosleep (instead of sleep) in event timing,USE_NANOSLEEP=$enableval,USE_NANOSLEEP=yes) AC_ARG_ENABLE(nanosleep,
AC_HELP_STRING([--enable-nanosleep],
[enables use of nanosleep (instead of sleep) in event timing]),
USE_NANOSLEEP=$enableval,
USE_NANOSLEEP=yes
)
if test x$USE_NANOSLEEP = xyes; then if test x$USE_NANOSLEEP = xyes; then
AC_DEFINE_UNQUOTED(USE_NANOSLEEP,,[enables use of nanosleep (instead of sleep)]) AC_DEFINE_UNQUOTED(USE_NANOSLEEP,,[enables use of nanosleep (instead of sleep)])
fi fi
USE_EVENTBROKER=yes USE_EVENTBROKER=yes
AC_ARG_ENABLE(event-broker,--enable-event-broker enables integration of event broker routines,USE_EVENTBROKER=$enableval,USE_EVENTBROKER=yes) AC_ARG_ENABLE(event-broker,
AC_HELP_STRING([--enable-event-broker],
[enables integration of event broker routines]),
USE_EVENTBROKER=$enableval,
USE_EVENTBROKER=yes
)
BROKER_LDFLAGS="" BROKER_LDFLAGS=""
BROKERLIBS=""; BROKERLIBS="";
@ -605,6 +648,7 @@ if test x$USE_EVENTBROKER = xyes; then
case $host_os in case $host_os in
solaris2*|sysv4*) solaris2*|sysv4*)
MOD_LDFLAGS="-G" MOD_LDFLAGS="-G"
MOD_CFLAGS="-fPIC"
;; ;;
aix4*|aix5*) aix4*|aix5*)
#MOD_LDFLAGS="-G -bnoentry -bexpall" #MOD_LDFLAGS="-G -bnoentry -bexpall"
@ -625,7 +669,7 @@ if test x$USE_EVENTBROKER = xyes; then
MOD_LDFLAGS="-shared" MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC" MOD_CFLAGS="-fPIC"
;; ;;
freebsd*) *bsd*)
MOD_LDFLAGS="-shared" MOD_LDFLAGS="-shared"
MOD_CFLAGS="-fPIC" MOD_CFLAGS="-fPIC"
;; ;;
@ -638,6 +682,11 @@ if test x$USE_EVENTBROKER = xyes; then
AC_SUBST(MOD_CFLAGS) AC_SUBST(MOD_CFLAGS)
AC_SUBST(MOD_LDFLAGS) AC_SUBST(MOD_LDFLAGS)
dnl - flags for compiling workers
WORKER_CFLAGS="-I ../../include -I ../.."
WORKER_LDFLAGS="-L ../../lib -l nagios"
AC_SUBST(WORKER_CFLAGS)
AC_SUBST(WORKER_LDFLAGS)
AC_DEFINE_UNQUOTED(USE_EVENT_BROKER,,[defined to bring in the event broker objects]) AC_DEFINE_UNQUOTED(USE_EVENT_BROKER,,[defined to bring in the event broker objects])
BROKER_O="broker.o nebmods.o" BROKER_O="broker.o nebmods.o"
@ -647,65 +696,15 @@ if test x$USE_EVENTBROKER = xyes; then
fi fi
USEPERL=no;
INSTALLPERLSTUFF=no;
AC_ARG_ENABLE(embedded-perl,--enable-embedded-perl will enable embedded Perl interpreter,[
USEPERL=$enableval
]
,USEPERL=no)
PERLCACHE=yes;
AC_ARG_WITH(perlcache,--with-perlcache turns on cacheing of internally compiled Perl scripts,[
PERLCACHE=$withval
]
,[
AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
PERLCACHE=yes;
])
dnl Is embedded Perl being compiled in?
if test x$USEPERL = xyes; then
AC_DEFINE_UNQUOTED(EMBEDDEDPERL,,[Is embedded Perl being compiled in?])
PERLLIBS="`perl -MExtUtils::Embed -e ldopts`"
PERLDIR="`perl -MConfig -e 'print $Config{installsitearch}'`"
CFLAGS="${CFLAGS} `perl -MExtUtils::Embed -e ccopts`"
USEPERL=yes
INSTALLPERLSTUFF=yes;
PERLXSI_O=perlxsi.o
OBJS="${OBJS} ${PERLXSI_O}"
echo "creating base/perlxsi.c"
perl -MExtUtils::Embed -e xsinit -- -o base/perlxsi.c
echo "Embedded Perl interpreter will be compiled in..."
dnl Is caching enabled?
if test x$PERLCACHE = xyes; then
AC_DEFINE(DO_CLEAN,"0",[whether to clean cached compiled perl])
PERLCACHE=yes;
echo "Internally compiled Perl scripts will be cached..."
else
AC_DEFINE(DO_CLEAN,"1",[whether to clean cached compiled perl])
echo "Internally compiled Perl scripts will NOT be cached..."
fi
fi
dnl Test if we're using threaded Perl (patch by Chip Ach)
if test x$USEPERL = xyes; then
if (perl -e 'use Config;exit -1 unless ($Config{'usethreads'});'); then
echo "Using threaded perl"
AC_DEFINE_UNQUOTED(THREADEDPERL,,[defined if we're using threaded Perl])
fi
fi
dnl Option for compiling under CYGWIN dnl Option for compiling under CYGWIN
nagios_name=nagios nagios_name=nagios
nagiostats_name=nagiostats nagiostats_name=nagiostats
cygwin=no cygwin=no
AC_ARG_ENABLE(cygwin,--enable-cygwin enables building under the CYGWIN environment,[ AC_ARG_ENABLE(cygwin,
cygwin=$enableval AC_HELP_STRING([--enable-cygwin],
]) [enables building under the CYGWIN environment]),
[cygwin=$enableval]
)
if test x$cygwin = xyes; then if test x$cygwin = xyes; then
CFLAGS="${CFLAGS} -DCYGWIN" CFLAGS="${CFLAGS} -DCYGWIN"
nagios_name=nagios.exe; nagios_name=nagios.exe;
@ -781,17 +780,21 @@ fi
AC_SUBST(USE_LIBTAP) AC_SUBST(USE_LIBTAP)
AC_SUBST(CGIEXTRAS) AC_SUBST(CGIEXTRAS)
AC_SUBST(GDLIBS) AC_SUBST(GDLIBS)
AC_SUBST(PERLLIBS)
AC_SUBST(PERLDIR)
AC_SUBST(PERLXSI_O)
AC_SUBST(BASEEXTRALIBS) AC_SUBST(BASEEXTRALIBS)
AC_SUBST(INITDIR) AC_SUBST(INITDIR)
AC_SUBST(INSTALLPERLSTUFF)
AC_SUBST(USE_EVENTBROKER) AC_SUBST(USE_EVENTBROKER)
AC_PATH_PROG(PERL,perl) AC_PATH_PROG(PERL,perl)
if test -z "$PERL"; then
AC_MSG_ERROR([Cannot continue without perl!])
fi
AC_OUTPUT(Makefile subst pkginfo base/Makefile common/Makefile contrib/Makefile cgi/Makefile html/Makefile module/Makefile xdata/Makefile daemon-init t/Makefile t-tap/Makefile) AC_PATH_PROG(UNZIP,unzip)
if test -z "$UNZIP"; then
AC_MSG_ERROR([Cannot continue without unzip!])
fi
AC_OUTPUT(Makefile lib/Makefile subst pkginfo base/Makefile common/Makefile contrib/Makefile cgi/Makefile html/Makefile module/Makefile worker/Makefile worker/ping/Makefile xdata/Makefile daemon-init t/Makefile t-tap/Makefile)
perl subst include/locations.h perl subst include/locations.h
@ -832,27 +835,24 @@ echo " -------------------------"
AC_MSG_RESULT([ Nagios executable: $nagios_name]) AC_MSG_RESULT([ Nagios executable: $nagios_name])
AC_MSG_RESULT([ Nagios user/group: $nagios_user,$nagios_grp]) AC_MSG_RESULT([ Nagios user/group: $nagios_user,$nagios_grp])
AC_MSG_RESULT([ Command user/group: $command_user,$command_grp]) AC_MSG_RESULT([ Command user/group: $command_user,$command_grp])
if test x$USEPERL = xyes; then
if test x$PERLCACHE = xyes; then
AC_MSG_RESULT([ Embedded Perl: yes, with caching])
else
AC_MSG_RESULT([ Embedded Perl: yes, without caching])
fi
else
AC_MSG_RESULT([ Embedded Perl: no])
fi
if test x$USE_EVENTBROKER = xyes; then if test x$USE_EVENTBROKER = xyes; then
AC_MSG_RESULT([ Event Broker: yes]) AC_MSG_RESULT([ Event Broker: yes])
else else
AC_MSG_RESULT([ Event Broker: no]) AC_MSG_RESULT([ Event Broker: no])
fi fi
AC_MSG_RESULT([ Install \${prefix}: $prefix]) AC_MSG_RESULT([ Install \${prefix}: $prefix])
incdir=`eval echo $includedir`
if test x$incdir = x$prefix/include; then
includedir=$prefix/include/nagios
fi
AC_MSG_RESULT([ Install \${includedir}: $includedir])
AC_MSG_RESULT([ Lock file: $lockfile]) AC_MSG_RESULT([ Lock file: $lockfile])
AC_MSG_RESULT([ Check result directory: $CHECKRESULTDIR]) AC_MSG_RESULT([ Check result directory: $CHECKRESULTDIR])
AC_MSG_RESULT([ Init directory: $init_dir]) AC_MSG_RESULT([ Init directory: $init_dir])
AC_MSG_RESULT([ Apache conf.d directory: $HTTPD_CONF]) AC_MSG_RESULT([ Apache conf.d directory: $HTTPD_CONF])
AC_MSG_RESULT([ Mail program: $MAIL_PROG]) AC_MSG_RESULT([ Mail program: $MAIL_PROG])
AC_MSG_RESULT([ Host OS: $host_os]) AC_MSG_RESULT([ Host OS: $host_os])
AC_MSG_RESULT([ IOBroker Method: $IOBROKER_METHOD])
echo "" echo ""
echo " Web Interface Options:" echo " Web Interface Options:"
@ -862,19 +862,8 @@ AC_MSG_RESULT([ HTML URL: http://localhost$htmurl/])
AC_MSG_RESULT([ CGI URL: http://localhost$cgiurl/]) AC_MSG_RESULT([ CGI URL: http://localhost$cgiurl/])
AC_MSG_RESULT([ Traceroute (used by WAP): $PATH_TO_TRACEROUTE]) AC_MSG_RESULT([ Traceroute (used by WAP): $PATH_TO_TRACEROUTE])
dnl echo ""
dnl echo " External Data Routines:"
dnl echo " ------------------------"
dnl AC_MSG_RESULT([ Status data: $XSDCOMMENT])
dnl AC_MSG_RESULT([ Comment data: $XCDCOMMENT])
dnl AC_MSG_RESULT([ Downtime data: $XDDCOMMENT])
dnl AC_MSG_RESULT([ Peformance data: $XPDCOMMENT])
echo "" echo ""
echo "" echo ""
echo "Review the options above for accuracy. If they look okay," echo "Review the options above for accuracy. If they look okay,"
echo "type 'make all' to compile the main program and CGIs." echo "type 'make all' to compile the main program and CGIs."
echo "" echo ""

4
contrib/.gitignore vendored
View File

@ -1,2 +1,4 @@
perlxsi.c
Makefile Makefile
convertcfg
daemon-chk.cgi
nagios-worker

View File

@ -5,13 +5,14 @@
############################### ###############################
CC=@CC@ CC=@CC@
CFLAGS=@CFLAGS@ @DEFS@ CFLAGS=-I.. @CFLAGS@ @DEFS@
LDFLAGS=@LDFLAGS@ @LIBS@ LDFLAGS=@LDFLAGS@ @LIBS@
# Source code directories # Source code directories
SRC_INCLUDE=../include SRC_INCLUDE=../include
SRC_COMMON=../common SRC_COMMON=../common
SRC_CGI=../cgi SRC_CGI=../cgi
SRC_LIB=../lib
# Generated automatically from configure script # Generated automatically from configure script
SNPRINTF_O=@SNPRINTF_O@ SNPRINTF_O=@SNPRINTF_O@
@ -25,7 +26,7 @@ CGIDIR=@sbindir@
BINDIR=@bindir@ BINDIR=@bindir@
CGIS=traceroute.cgi daemonchk.cgi CGIS=traceroute.cgi daemonchk.cgi
UTILS=mini_epn new_mini_epn convertcfg UTILS=convertcfg
ALL=$(CGIS) $(UTILS) ALL=$(CGIS) $(UTILS)
@ -40,10 +41,11 @@ COMMON_H=$(SRC_INCLUDE)/config.h $(SRC_INCLUDE)/common.h $(SRC_INCLUDE)/location
all: $(ALL) all: $(ALL)
clean: clean:
rm -f convertcfg daemonchk.cgi mini_epn new_mini_epn core *.o rm -f convertcfg daemonchk.cgi core *.o
rm -f */*/*~ rm -f */*/*~
rm -f */*~ rm -f */*~
rm -f *~ rm -f *~
rm -rf rpmbuild *.rpm
distclean: clean distclean: clean
rm -f Makefile rm -f Makefile
@ -59,23 +61,17 @@ install:
############################################################################## ##############################################################################
# rules and dependencies for actual target programs # rules and dependencies for actual target programs
daemonchk.cgi: daemonchk.o $(CGI_O) $(CGI_H) $(COMMON_H) $(SRC_LIB)/libnagios.a:
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(CGI_O) make -C $(SRC_LIB) libnagios.a
daemonchk.cgi: daemonchk.o $(CGI_O) $(CGI_H) $(COMMON_H) $(SRC_LIB)/libnagios.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(CGI_O) $(SRC_LIB)/libnagios.a
daemonchk.o: daemonchk.c daemonchk.o: daemonchk.c
$(CC) $(CLFAGS) -c -o $@ $< -I$(SRC_INCLUDE) $(CC) $(CFLAGS) -c -o $@ $< -I$(SRC_INCLUDE)
mini_epn: mini_epn.c nagios-worker: nagios-worker.c
perl -MExtUtils::Embed -e xsinit $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS) $(SRC_LIB)/libnagios.a
$(CC) $(CFLAGS) -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) -c mini_epn.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@
new_mini_epn: new_mini_epn.c
perl -MExtUtils::Embed -e xsinit
$(CC) $(CFLAGS) -c perlxsi.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) -c new_mini_epn.c `perl -MExtUtils::Embed -e ccopts`
$(CC) $(CFLAGS) $(LDFLAGS) perlxsi.o new_mini_epn.o `perl -MExtUtils::Embed -e ccopts -e ldopts` -o $@
############################################################################## ##############################################################################
# dependencies # dependencies
@ -88,3 +84,31 @@ $(CGI_O): $(CGI_C)
%.cgi : %.c %.cgi : %.c
$(CC) $(CFLAGS) $(LDFLAGS) $< $(CGI_O) -o $@ $(CC) $(CFLAGS) $(LDFLAGS) $< $(CGI_O) -o $@
##############################################################################
# rpm making automation for CentOS/RHEL.
ARCH ?= $(shell arch)
ifeq ($(ARCH),x86_64)
RPM_ARCH := x86_64
else
ifeq ($(ARCH),i686)
RPM_ARCH := i386
else
$(error Unknown arch "$(ARCH)".)
endif
endif
rpm:
# create nagios tar ball.
@(cd ..;rm -f nagios-@VERSION@)
@(cd ..;ln -s . nagios-@VERSION@)
@(cd ..;tar zhcf nagios-@VERSION@.tar.gz --exclude nagios-@VERSION@/nagios-@VERSION@.tar.gz --exclude nagios-@VERSION@/nagios-@VERSION@ --exclude RCS --exclude CVS --exclude build-* --exclude *~ --exclude .git* nagios-@VERSION@/)
@(cd ..;rm -f nagios-@VERSION@)
# build the rpm using rpmbuild from ./rmbuild as topdir
@rm -rf rpmbuild && mkdir -p rpmbuild/SOURCES
@cp ../nagios-@VERSION@.tar.gz rpmbuild/SOURCES/nagios-@VERSION@.tar.gz
@rpmbuild -ba --define "_topdir ${PWD}/rpmbuild" ../nagios.spec
@mv rpmbuild/RPMS/$(RPM_ARCH)/*.rpm .
@ls -l *.rpm

View File

@ -22,7 +22,7 @@ Additional CGIs:
---------------- ----------------
- traceroute.cgi is (surprise) a CGI that allows you to do a traceroute - traceroute.cgi is (surprise) a CGI that allows you to do a traceroute
to a specific IP address. Simply do a 'chmod +x' to make it executeable to a specific IP address. Simply do a 'chmod +x' to make it executable
and place it in the CGI directory (i.e. /usr/local/nagios/sbin). and place it in the CGI directory (i.e. /usr/local/nagios/sbin).
Requires Perl. Requires Perl.
@ -37,12 +37,7 @@ Miscellaneous Goodies:
Apache to require password authentication for access to the web Apache to require password authentication for access to the web
interface. interface.
- mini_epn.c is a mini embedded Perl interpreter that can be used to - Automated rpm making.
test the feasibility of running various Perl plugins with the 1. ./configure # to generate contrib/Makefile
embedded Perl interpreter compiled in. 2. cd contrib ; make rpm
3. *.rpm will be generated in contrib directory.

View File

@ -61,7 +61,7 @@ int main(int argc, char **argv) {
printf("\tcontactgroups\n"); printf("\tcontactgroups\n");
printf("\thosts\n"); printf("\thosts\n");
printf("\thostgroups\n"); printf("\thostgroups\n");
printf("\thostgroupescalationss\n"); printf("\thostgroupescalations\n");
printf("\tservices\n"); printf("\tservices\n");
printf("\tservicedependencies\n"); printf("\tservicedependencies\n");
printf("\tserviceescalations\n"); printf("\tserviceescalations\n");
@ -306,7 +306,6 @@ int main(int argc, char **argv) {
printf("\tnotifications_enabled\t\t1\t; Host notifications are enabled\n"); printf("\tnotifications_enabled\t\t1\t; Host notifications are enabled\n");
printf("\tevent_handler_enabled\t\t1\t; Host event handler is enabled\n"); printf("\tevent_handler_enabled\t\t1\t; Host event handler is enabled\n");
printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n"); printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n");
/*printf("\tfailure_prediction_enabled\t1\t; Failure prediction is enabled\n");*/
printf("\tprocess_perf_data\t\t1\t; Process performance data\n"); printf("\tprocess_perf_data\t\t1\t; Process performance data\n");
printf("\tretain_status_information\t1\t; Retain status information across program restarts\n"); printf("\tretain_status_information\t1\t; Retain status information across program restarts\n");
printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n"); printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n");
@ -427,7 +426,6 @@ int main(int argc, char **argv) {
printf("\tnotifications_enabled\t\t1\t; Service notifications are enabled\n"); printf("\tnotifications_enabled\t\t1\t; Service notifications are enabled\n");
printf("\tevent_handler_enabled\t\t1\t; Service event handler is enabled\n"); printf("\tevent_handler_enabled\t\t1\t; Service event handler is enabled\n");
printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n"); printf("\tflap_detection_enabled\t\t1\t; Flap detection is enabled\n");
/*printf("\tfailure_prediction_enabled\t1\t; Failure prediction is enabled\n");*/
printf("\tprocess_perf_data\t\t1\t; Process performance data\n"); printf("\tprocess_perf_data\t\t1\t; Process performance data\n");
printf("\tretain_status_information\t1\t; Retain status information across program restarts\n"); printf("\tretain_status_information\t1\t; Retain status information across program restarts\n");
printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n"); printf("\tretain_nonstatus_information\t1\t; Retain non-status information across program restarts\n");

View File

@ -174,7 +174,6 @@ static int process_cgivars(void) {
/* do some basic length checking on the variable identifier to prevent buffer overflows */ /* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) { if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
x++;
continue; continue;
} }
} }
@ -191,7 +190,7 @@ static void get_expire_time_string(time_t *raw_time, char *buffer, int buffer_le
int second; int second;
int year; int year;
char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; char *weekdays[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}; char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if(raw_time == NULL) if(raw_time == NULL)
time(&t); time(&t);

View File

@ -1,26 +0,0 @@
/******** BEGIN EMBEDDED PERL INTERPRETER DECLARATIONS ********/
#include <EXTERN.h>
#include <perl.h>
#include <fcntl.h>
#undef ctime /* don't need perl's threaded version */
#undef printf /* can't use perl's printf until initialized */
/* In perl.h (or friends) there is a macro that defines sighandler as Perl_sighandler, so we must #undef it so we can use our sighandler() function */
#undef sighandler
/* and we don't need perl's reentrant versions */
#undef localtime
#undef getpwnam
#undef getgrnam
#undef strerror
#ifdef aTHX
EXTERN_C void xs_init(pTHX);
#else
EXTERN_C void xs_init(void);
#endif
/******** END EMBEDDED PERL INTERPRETER DECLARATIONS ********/

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# OBSESSIVE_SVC_HANDLER # OBSESSIVE_SVC_HANDLER
# Written by Ethan Galstad (nagios@nagils.org) # Written by Ethan Galstad (nagios@nagios.org)
# Last Modified: 07-19-2001 # Last Modified: 07-19-2001
# #
# This script is intended to run as the OCSP command # This script is intended to run as the OCSP command

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -11,7 +11,7 @@ those from this tarball. For example:
cd /opt/nagios/share cd /opt/nagios/share
tar xvfz exfoliation.tgz tar xvfz exfoliation.tgz
On debian/unbuntu installations you might have to modify side.html to include On debian/ubuntu installations you might have to modify side.html to include
the common.css stylesheet by adding a line like this in the head section: the common.css stylesheet by adding a line like this in the head section:
<link rel="stylesheet" href="common.css" type="text/css" /> <link rel="stylesheet" href="common.css" type="text/css" />

View File

@ -96,6 +96,7 @@ div.navsectiontitle {
background-color: #efefef; background-color: #efefef;
border:1px solid #dddddd; border:1px solid #dddddd;
} }
div.navsectionlinks { div.navsectionlinks {
margin: 3px 0 0 0; margin: 3px 0 0 0;
} }
@ -105,7 +106,7 @@ ul.navsectionlinks {
padding: 0; padding: 0;
list-style: none; list-style: none;
} }
ul.navsectionlinks li { } ul.navsectionlinks li { }
ul.navsectionlinks li a { ul.navsectionlinks li a {
font-weight: bold; font-weight: bold;
font-size: 9pt; font-size: 9pt;
@ -138,6 +139,23 @@ ul.navsectionlinks li ul li ul {
list-style: none; list-style: none;
} }
div.navsectionheader {
padding: 0;
margin: 0;
}
div.navsectionheader ul {
margin: 0;
padding: 0;
list-style: none;
}
div.navsectionheader ul li {
font-size: 9pt;
font-weight: bold;
padding: 0 0 0 15px;
}
div.navsectionheader ul li ul li {
font-weight: normal;
}
.navbarsearch { .navbarsearch {
margin: 5px 0 0 0; margin: 5px 0 0 0;
@ -149,99 +167,97 @@ ul.navsectionlinks li ul li ul {
.navbarsearch fieldset legend { .navbarsearch fieldset legend {
font-size: 8pt; font-size: 8pt;
} }
.navbarsearch input{ .navbarsearch input {
font-size: 9pt; font-size: 9pt;
} }
#splashpage{ #splashpage {
text-align: center; text-align: center;
} }
#mainbrandsplash{ #mainbrandsplash {
font-size: 12pt; font-size: 12pt;
font-weight: bold; font-weight: bold;
margin: 0 0 35px 0; margin: 0 0 35px 0;
} }
#maincopy{ #maincopy {
margin: 0 0 15px 0; margin: 0 0 15px 0;
} }
#currentversioninfo{ #currentversioninfo {
font-size: 12pt; font-size: 12pt;
} }
#currentversioninfo .product{ #currentversioninfo .product {
font-size: 14pt; font-size: 14pt;
font-weight: bold; font-weight: bold;
} }
#currentversioninfo .version{ #currentversioninfo .version {
font-size: 14pt; font-size: 14pt;
font-weight: bold; font-weight: bold;
} }
#currentversioninfo .releasedate{ #currentversioninfo .releasedate {
font-size: 11pt; font-size: 11pt;
margin: 5px 0 0 0; margin: 5px 0 0 0;
} }
#currentversioninfo .checkforupdates{ #currentversioninfo .checkforupdates {
font-size: 11pt; font-size: 11pt;
font-weight: bold; font-weight: bold;
} }
#currentversioninfo .whatsnew{ #currentversioninfo .whatsnew {
font-size: 11pt; font-size: 11pt;
font-weight: bold; font-weight: bold;
margin: 50px 0 0 0; margin: 50px 0 0 0;
} }
#updateversioninfo{ #updateversioninfo {
margin: 15px auto 35px auto; margin: 15px auto 35px auto;
width: 400px; width: 400px;
} }
.updatechecksdisabled{ #updateversioninfo div.submessage {
clear: left;
}
.updatechecksdisabled {
background-color: #FF9F9F; background-color: #FF9F9F;
border: 1px solid red; border: 1px solid red;
padding: 10px; padding: 10px;
} }
.updatechecksdisabled div.warningmessage{ .updatechecksdisabled div.warningmessage {
font-weight: bold; font-weight: bold;
} }
#updateversioninfo div.submessage{ .updateavailable {
clear: left;
}
.updateavailable{
background-color: #9FD4FF; background-color: #9FD4FF;
border: 1px solid blue; border: 1px solid blue;
padding: 10px; padding: 10px;
} }
.updateavailable div.updatemessage{ .updateavailable div.updatemessage {
font-size: 12pt; font-size: 12pt;
font-weight: bold; font-weight: bold;
} }
#splashpage #mainfooter{ #splashpage #mainfooter {
/*margin: 100px 0 0 0;*/
clear: both; clear: both;
font-size: 8pt; font-size: 8pt;
padding-top: 35px; padding-top: 35px;
margin: auto;
width: 800px;
} }
#splashpage #mainfooter .disclaimer{ #splashpage #mainfooter .disclaimer {
/*width: 80%;*/
margin: auto; margin: auto;
} }
#splashpage #mainfooter .logos{ #splashpage #mainfooter .logos {
margin: 15px 0 0 0; margin: 15px 0 0 0;
} }
table.infoBox { width: 100%; } table.infoBox { width: 100%; }
td.infoBox { font-size: 8pt; padding: 0 0 1em 0; white-space: nowrap; } td.infoBox { font-size: 8pt; padding: 0 0 1em 0; white-space: nowrap; }
div.infoBoxTitle { font-size: 10pt; font-weight: bold; } div.infoBoxTitle { font-size: 10pt; font-weight: bold; }
div.infoBoxBadProcStatus { font-size: 8pt; font-weight: bold; color: red; } div.infoBoxBadProcStatus { font-size: 8pt; font-weight: bold; color: red; }
.linkBox { font-size: 8pt; padding: 1; } .linkBox { font-size: 8pt; padding: 1px; }
table.linkBox td { white-space: nowrap; } table.linkBox td { white-space: nowrap; }
.filter { font-size: 8pt; padding: 1; } .filter { font-size: 8pt; padding: 1px; }
.filterTitle { font-size: 9pt; font-weight: bold; } .filterTitle { font-size: 9pt; font-weight: bold; }
.filterName { font-size: 8pt; text-align: right; font-weight: bold; } .filterName { font-size: 8pt; text-align: right; font-weight: bold; }
.filterValue { font-size: 8pt; } .filterValue { font-size: 8pt; }
@ -255,19 +271,19 @@ table.linkBox td { white-space: nowrap; }
table.data { padding: 0; } table.data { padding: 0; }
th.data { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; border-bottom: 1px solid #777777; color: #333333; } th.data { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; border-bottom: 1px solid #777777; color: #333333; }
.dataOdd { font-size: 8pt; background-color: #e7e7e7; padding: 0 4 0 4; } .dataOdd { font-size: 8pt; background-color: #e7e7e7; padding: 0px 4px 0px 4px; }
.dataEven { font-size: 8pt; background-color: #f4f2f2; padding: 0 4 0 4; } .dataEven { font-size: 8pt; background-color: #f4f2f2; padding: 0px 4px 0px 4px; }
.dataTitle { font-size: 12pt; text-align: center; font-weight: bold; } .dataTitle { font-size: 12pt; text-align: center; font-weight: bold; }
.dataSubTitle { font-size: 10pt; text-align: center; font-weight: bold; } .dataSubTitle { font-size: 10pt; text-align: center; font-weight: bold; }
.optBox { font-size: 9pt; white-space: nowrap; padding: 2 0 0 0; } .optBox { font-size: 9pt; white-space: nowrap; padding: 2px 0px 0px 0px; }
.optBoxTitle { font-size: 10pt; font-weight: bold; text-align: center; } .optBoxTitle { font-size: 10pt; font-weight: bold; text-align: center; }
.optBoxRequiredItem { font-size: 9pt; text-align: right; padding: 0 5 0 5; color: red; } .optBoxRequiredItem { font-size: 9pt; text-align: right; padding: 0px 5px 0px 5px; color: red; }
.optBoxItem { font-size: 9pt; text-align: right; padding: 0 5 0 5; } .optBoxItem { font-size: 9pt; text-align: right; padding: 0px 5px 0px 5px; }
.optBoxValue { font-size: 9pt; } .optBoxValue { font-size: 9pt; }
.optionBoxTitle { font-size: 10pt; text-align: center; font-weight: bold; } .optionBoxTitle { font-size: 10pt; text-align: center; font-weight: bold; }
.optionBox { font-size: 10pt; padding: 2; } .optionBox { font-size: 10pt; padding: 2px; }
.navBoxTitle { font-size: 10pt; font-weight: bold; white-space: nowrap; } .navBoxTitle { font-size: 10pt; font-weight: bold; white-space: nowrap; }
.navBoxItem { font-size: 8pt; } .navBoxItem { font-size: 8pt; }
@ -293,16 +309,16 @@ th.data { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; border-b
.dateSelectSubTitle { font-size: 9pt; text-align: right; } .dateSelectSubTitle { font-size: 9pt; text-align: right; }
.dateSelectItem { font-size: 9pt; } .dateSelectItem { font-size: 9pt; }
.popupText { font-size: 8pt; background-color: #eeeeaa; border: 1px solid #777777; padding: 10 10 10 10; } .popupText { font-size: 8pt; background-color: #eeeeaa; border: 1px solid #777777; padding: 10px 10px 10px 10px; }
.hostImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0 5 0 5; } .hostImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0px 5px 0px 5px; }
.hostUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0 5 0 5; } .hostUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0px 5px 0px 5px; }
.serviceImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0 5 0 5; } .serviceImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0px 5px 0px 5px; }
.serviceUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0 5 0 5; } .serviceUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0px 5px 0px 5px; }
.outageImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0 5 0 5; } .outageImportantProblem { font-size: 8pt; background-color: #88aadd; border: 1px solid #aaaaaa; padding: 0px 5px 0px 5px; }
.outageUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0 5 0 5; } .outageUnimportantProblem { font-size: 8pt; background-color: #aaccff; border: 1px solid #888888; padding: 0px 5px 0px 5px; }
/* Some nagios configurations have side.html rather than side.php and define */ /* Some nagios configurations have side.html rather than side.php and define */
@ -313,7 +329,7 @@ th.data { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; border-b
margin: 5px 0 10px 0; margin: 5px 0 10px 0;
padding: 2px; padding: 2px;
background-color: #efefef; background-color: #efefef;
border:v1px solid #dddddd; border: 1px solid #dddddd;
} }
.NavBarItem { .NavBarItem {
@ -332,39 +348,54 @@ th.data { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; border-b
#splashboxes { #splashboxes {
/*border: 1px solid blue;*/ margin: auto;
margin: auto; width: 794px;
width: 90%; }
}
.splashbox{ .splashbox {
padding: 5px; padding: 5px;
margin: 5px 5px 5px; margin: 5px;
border: 1px solid #AAAAAA; border: 1px solid #AAAAAA;
float: left; float: left;
text-align: left; text-align: left;
height: 140px; height: 140px;
} }
.splashbox h2{ .splashbox h2 {
margin: 0px; margin: 0;
font-size: 12pt; font-size: 12pt;
} }
.splashbox ul{ .splashbox ul {
margin: 0; margin: 0;
padding: 5px 5px 5px 15px; padding: 5px 5px 5px 15px;
} }
.splashbox ul li{ .splashbox ul li {
clear: both; clear: both;
} }
#splashbox1 {
width: 250px; .splashbox-media {
} margin: 5px;
#splashbox2 { }
width: 500px; .splashbox3-empty {
} margin: 5px;
border: 1px solid #AAAAAA;
width: 238px;
height: 150px;
}
.splashbox3-full {
margin: 5px;
width: 240px;
height: 152px;
}
.splashbox-clear {
clear: both;
}
#splashbox1, #splashbox2, #splashbox4 {
width: 250px;
}
#splashbox3 { #splashbox3 {
width: 250px; float: left;
clear: both; }
} #splashbox5 {
#splashbox4 { width: 500px;
width: 500px; }
}

View File

@ -19,6 +19,7 @@ TH.notifications { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; bo
.notificationsCRITICAL { background-color: #f88888; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsCRITICAL { background-color: #f88888; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsACKNOWLEDGEMENT { background-color: #aaaaaa; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsACKNOWLEDGEMENT { background-color: #aaaaaa; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsCUSTOM { background-color: #778899; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsCUSTOM { background-color: #778899; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsDOWNTIME { background-color: #aaccff; border: 1px solid #777777; padding: 0 4 0 4; }
/* these are dark colors */ /* these are dark colors */
.notificationsHOSTUP { background-color: #88d066; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsHOSTUP { background-color: #88d066; border: 1px solid #777777; padding: 0 4 0 4; }
@ -26,4 +27,5 @@ TH.notifications { font-size: 9pt; text-align: left; padding: 0 3px 0 3px; bo
.notificationsHOSTUNREACHABLE { background-color: #ffbb55; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsHOSTUNREACHABLE { background-color: #ffbb55; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsHOSTACKNOWLEDGEMENT { background-color: #aaaaaa; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsHOSTACKNOWLEDGEMENT { background-color: #aaaaaa; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsHOSTCUSTOM { background-color: #778899; border: 1px solid #777777; padding: 0 4 0 4; } .notificationsHOSTCUSTOM { background-color: #778899; border: 1px solid #777777; padding: 0 4 0 4; }
.notificationsHOSTDOWNTIME { background-color: #aaccff; border: 1px solid #777777; padding: 0 4 0 4; }

View File

@ -1,122 +0,0 @@
/*
mini_epn.c
*/
#include <EXTERN.h>
#include <perl.h>
#include "epn_nagios.h"
#define MAX_INPUT_CHARS 1024
static PerlInterpreter *my_perl = NULL;
int main(int argc, char **argv, char **env) {
/*
#ifdef aTHX
dTHX;
#endif
*/
char *embedding[] = { "", "p1.pl" };
char *plugin_output ;
char fname[MAX_INPUT_CHARS];
char *args[] = {"", "0", "", "", NULL };
char command_line[MAX_INPUT_CHARS];
int exitstatus;
int pclose_result;
if((my_perl = perl_alloc()) == NULL) {
printf("%s\n", "Error: Could not allocate memory for embedded Perl interpreter!");
exit(1);
}
perl_construct(my_perl);
exitstatus = perl_parse(my_perl, xs_init, 2, embedding, NULL);
if(!exitstatus) {
exitstatus = perl_run(my_perl);
while(printf("Enter file name: ") && fgets(command_line, MAX_INPUT_CHARS - 1, stdin)) {
SV *plugin_hndlr_cr;
STRLEN n_a;
int count = 0 ;
dSP;
command_line[strlen(command_line) - 1] = '\0';
strncpy(fname, command_line, strcspn(command_line, " "));
fname[strcspn(command_line, " ")] = '\x0';
args[0] = fname ;
args[3] = command_line + strlen(fname) + 1 ;
args[2] = "";
/* call our perl interpreter to compile and optionally cache the command */
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(args[0], 0)));
XPUSHs(sv_2mortal(newSVpv(args[1], 0)));
XPUSHs(sv_2mortal(newSVpv(args[2], 0)));
XPUSHs(sv_2mortal(newSVpv(args[3], 0)));
PUTBACK;
count = call_pv("Embed::Persistent::eval_file", G_SCALAR | G_EVAL);
SPAGAIN;
/* check return status */
if(SvTRUE(ERRSV)) {
(void) POPs;
pclose_result = -2;
printf("embedded perl ran %s with error %s\n", fname, SvPVX(ERRSV));
continue;
}
else {
plugin_hndlr_cr = newSVsv(POPs);
PUTBACK;
FREETMPS;
LEAVE;
}
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(args[0], 0)));
XPUSHs(sv_2mortal(newSVpv(args[1], 0)));
XPUSHs(plugin_hndlr_cr);
XPUSHs(sv_2mortal(newSVpv(args[3], 0)));
PUTBACK;
count = perl_call_pv("Embed::Persistent::run_package", G_EVAL | G_ARRAY);
SPAGAIN;
plugin_output = POPpx ;
pclose_result = POPi ;
printf("embedded perl plugin return code and output was: %d & '%s'\n", pclose_result, plugin_output);
PUTBACK;
FREETMPS;
LEAVE;
}
}
PL_perl_destruct_level = 0;
perl_destruct(my_perl);
perl_free(my_perl);
exit(exitstatus);
}

139
contrib/nagios-qh.rb Executable file
View File

@ -0,0 +1,139 @@
#!/usr/bin/env ruby
# Simple interface to interact with the Query Handler
# Daniel Wittenberg <dwittenberg2008@gmail.com>
require "socket"
require 'optparse'
$DEBUG="false"
$DEBUGLOG=""
def debug(msg)
if($DEBUG == "true")
if($DEBUGLOG != "")
File.open("#{$DEBUGLOG}",'a') {|f| f.puts("DEBUG: #{msg}")}
else
puts("DEBUG: #{msg}")
end
end
end
def send_cmd(cmd, mysock)
mysock="/var/nagios/rw/nagios.qh" if mysock.nil?
cmd=cmd.chomp
debug("Starting send_cmd with command: #{cmd}")
if(cmd == "quit" or cmd == "exit")
exit(0)
end
# If we forget to start with a command type assume #
if(! cmd.start_with?('#') and ! cmd.start_with?('@'))
cmd = "##{cmd}"
end
# Cleanup the space if they forget you can't have one
cmd.gsub!(/^#\s+/,"#")
cmd.gsub!(/^@\s+/,"@")
# If no socket we might as well bail
if(! File.socket?(mysock))
puts "Not a socket (#{mysock}) sucker!"
exit(1)
end
debug("Writing command to socket: #{cmd}")
# open socket and lets get to work!
UNIXSocket.open("#{mysock}") do |socket|
cmd=cmd + ''
socket.send("#{cmd}\000", 0)
socket.flush
while line = socket.gets # Read lines from the socket
puts line.chop # And print with platform line terminator
end
if(! cmd.start_with?('#'))
socket.close
puts ""
end
end
end
def print_usage()
puts "
Simple command-line interface to Nagios Query Handler
-h, --help Show this help message.
-d, --debug Turn on debug mode
-s, --socket Specify the query handler socket
(default: /var/nagios/rw/nagios.qh)
-c, --cmd <cmd> Run a specific command and exit
"
exit
end
#######################################
# __ __ _____ _ _
# | \/ | /\ |_ _| \ | |
# | \ / | / \ | | | \| |
# | |\/| | / /\ \ | | | . ` |
# | | | |/ ____ \ _| |_| |\ |
# |_| |_/_/ \_\_____|_| \_|
#
#######################################
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: $0 [options]"
opts.on('-d','--debug','Debugging mode on') do
options[:debug] = true
$DEBUG="true"
end
opts.on('-h','--help','Help') do
print_usage()
end
opts.on('-s','--socket [socket]','Query Handler Socket') do |socket|
options[:socket] = socket
end
opts.on('-c','--command command','Command') do|command|
options[:cmd] = command
end
end
optparse.parse!
# If debug mode let's print our options so we confirm what our input was
options.each do |o,v|
debug("#{o}=#{v}")
end
if(options[:cmd])
send_cmd("##{options[:cmd]}", options[:socket])
exit
puts "Command not specified"
print_usage()
end
puts "Welcome to Nagios Query handler, here's a list of handlers available:"
puts ""
# We'll give the users a nudge to know what to type next
send_cmd("#help list", options[:socket])
puts "use @<handler> <cmd> for running queries such as '@nerd subscribe servicechecks'"
puts ""
puts "quit or exit will quit interactive mode"
puts ""
STDOUT.sync = true
print("qh> ")
while input = STDIN.gets
send_cmd(input, options[:socket])
STDOUT.sync = true
print("qh> ")
end

92
contrib/nagios-worker.c Normal file
View File

@ -0,0 +1,92 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include "../lib/snprintf.h"
#include "../lib/nsock.h"
#include "../lib/worker.h"
void usage(char *progname)
{
printf("Usage: %s [--name <worker_name>] <nagsock_path>\n", progname);
}
int main(int argc, char *argv[])
{
int sd, i, ret;
char *path = NULL, *name = NULL, *cmd = NULL, response[128];
if (argc < 2) {
usage(argv[0]);
return 1;
}
for (i = 1; i < argc; i++) {
char *opt, *arg = argv[i];
if (*arg != '-') {
if (!path) {
path = arg;
continue;
}
usage(argv[0]);
}
if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) {
usage(argv[0]);
return 0;
}
if ((opt = strchr(arg, '='))) {
opt = '\0';
opt++;
}
else if (i < argc - 1) {
opt = argv[i + 1];
i++;
}
else {
usage(argv[0]);
return 1;
}
if (!strcmp(arg, "--name")) {
name = opt;
}
}
if (!path)
usage(argv[0]);
if (!name)
name = basename(argv[0]);
sd = nsock_unix(path, NSOCK_TCP | NSOCK_CONNECT);
if (sd < 0) {
printf("Couldn't open socket: %s\n", nsock_strerror(sd));
return 1;
}
nsock_printf_nul(sd, "@wproc register name=%s\n", name);
/*
* we read only 3 bytes here, as we don't want to read any
* commands from Nagios before we've entered the worker loop
*/
ret = read(sd, response, 3);
if (ret <= 0) {
printf("Failed to read response: %s\n", strerror(errno));
return 1;
}
if (ret == 3 && !memcmp(response, "OK", 3))
printf("Connected. Wahoo\n");
else {
ret = read(sd, response + 3, sizeof(response) - 3);
printf("Error: %s\n", response);
return 1;
}
enter_worker(sd, start_cmd);
return 0;
}

View File

@ -1,255 +0,0 @@
/*
new_mini_epn.c
*/
#include <EXTERN.h>
#include <perl.h>
#include "epn_nagios.h"
/*
* DO_CLEAN must be a pointer to a char string
*/
#define DO_CLEAN "0"
static PerlInterpreter *my_perl = NULL;
/*
* <=== Align Right
* 56 spaces from left margin
* Do N O T use T A B S in #define code.
*
* Indent level == 4 spaces
*/
#define DO_READLINE \
"$_ = defined($term) " \
" ? $term->readline($prompt) " \
" : do { " \
" print $prompt; " \
" chomp($_ = <>); " \
" $_; " \
" }; " \
"die qq(That's all folks.\\n) " \
" unless $_ && ! /^\\s*$/ ; " \
"$_; "
#define INIT_TERM_READLINE \
"use vars qw($term $prompt $OUT); " \
\
"eval { require Term::ReadLine; }; " \
"unless ($@) { " \
" $term = new Term::ReadLine 'new_mini_epn'; " \
"} else { " \
" warn qq(Install Term::ReadLine for arrow key access to history, filename completion etc.); " \
"} " \
\
"$OUT = $term->OUT " \
" if defined($term); " \
"$prompt = 'plugin command line: '; "
void run_plugin(char *command_line) {
#ifdef aTHX
dTHX;
#endif
SV *plugin_hndlr_cr ;
STRLEN n_a ;
int count = 0 ;
int pclose_result;
char *plugin_output;
char fname[128];
char *args[] = {"", "", "", "", NULL };
dSP;
strncpy(fname, command_line, strcspn(command_line, " "));
fname[strcspn(command_line, " ")] = '\0';
/*
* Arguments passsed to Perl sub Embed::Persistent::run_package
*/
/*
* filename containing plugin
*/
args[0] = fname ;
/*
* Do _not_ cache the compiled plugin
*/
args[1] = DO_CLEAN ;
/*
* pointer to plugin arguments
*/
args[3] = command_line + strlen(fname) + 1 ;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(args[0], 0)));
XPUSHs(sv_2mortal(newSVpv(args[1], 0)));
XPUSHs(sv_2mortal(newSVpv(args[2], 0)));
XPUSHs(sv_2mortal(newSVpv(args[3], 0)));
PUTBACK;
call_pv("Embed::Persistent::eval_file", G_SCALAR | G_EVAL);
SPAGAIN ;
if(SvTRUE(ERRSV)) {
(void) POPs;
printf("embedded perl compiled plugin %s with error: %s - skipping plugin\n", fname, SvPVX(ERRSV));
return;
}
else {
plugin_hndlr_cr = newSVsv(POPs);
PUTBACK ;
FREETMPS ;
LEAVE ;
}
/*
* Push the arguments to Embed::Persistent::run_package onto
* the Perl stack.
*/
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(args[0], 0)));
XPUSHs(sv_2mortal(newSVpv(args[1], 0)));
XPUSHs(plugin_hndlr_cr);
XPUSHs(sv_2mortal(newSVpv(args[3], 0)));
PUTBACK;
count = call_pv("Embed::Persistent::run_package", G_ARRAY);
SPAGAIN;
plugin_output = POPpx ;
pclose_result = POPi ;
printf("embedded perl plugin return code and output was: %d & %s\n", pclose_result, plugin_output) ;
PUTBACK;
FREETMPS;
LEAVE;
return ;
}
SV * my_eval_pv(char *pv) {
SV* result;
/*
* eval_pv(..., TRUE) means die if Perl traps an error
*/
result = eval_pv(pv, TRUE) ;
return result ;
}
char * get_command_line(void) {
/* debug
* printf("%s\n", INIT_TERM_READLINE) ;
*/
SV *cmd_line ;
char *command_line ;
cmd_line = my_eval_pv(DO_READLINE) ;
command_line = SvPVX(cmd_line) ;
/* command_line = SvPV(cmd_line, n_a) ; */
return command_line ;
}
void init_term_readline(void) {
(void) my_eval_pv(INIT_TERM_READLINE) ;
}
void init_embedded_perl(void) {
char *embedding[] = { "", "p1.pl" };
/* embedding takes the place of argv[] ($argv[0] is the program name.
* - which is not given to Perl).
* Note that the number of args (ie the number of elements in embedding
* [argc] is the third argument of perl_parse().
*/
int exitstatus;
char buffer[132];
if((my_perl = perl_alloc()) == NULL) {
snprintf(buffer, sizeof(buffer), "Error: Could not allocate memory for embedded Perl interpreter!\n");
buffer[sizeof(buffer) - 1] = '\x0';
printf("%s\n", buffer);
exit(1);
}
perl_construct(my_perl);
exitstatus = perl_parse(my_perl, xs_init, 2, embedding, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
/* Why is perl_run() necessary ?
* It is needed if the code parsed by perl_parse() has
* any runtime semantics (eg code that gets eval'd,
* behaviour that depends on constants etc).
*/
exitstatus = perl_run(my_perl);
if(exitstatus) {
printf("%s\n", "perl_run() failed.");
exit(1);
}
}
void deinit_embedded_perl(void) {
PL_perl_destruct_level = 0;
perl_destruct(my_perl);
perl_free(my_perl);
}
int main(int argc, char **argv, char **env) {
init_embedded_perl();
/* Calls Perl to load and construct a new
* Term::ReadLine object.
*/
init_term_readline();
while(1) {
/*
* get_command_line calls Perl to get a scalar from stdin
*/
/* Perl Term::ReadLine::readline() method chomps the "\n"
* from the end of the input.
*/
char *cmd, *end;
/* Allow any length command line */
cmd = (get_command_line()) ;
// Trim leading whitespace
while(isspace(*cmd)) cmd++;
// Trim trailing whitespace
end = cmd + strlen(cmd) - 1;
while(end > cmd && isspace(*end)) end--;
// Write new null terminator
*(end + 1) = 0;
run_plugin(cmd) ;
}
deinit_embedded_perl();
}

View File

@ -1,851 +0,0 @@
package Embed::Persistent;
# $Id$
# $Log$
# Revision 1.5 2005-01-18 13:52:15+11 anwsmh
# 1 Set log level back to RETICENT and log file name to a placeholder for dist.
#
# Revision 1.4 2005-01-18 13:26:12+11 anwsmh
# 1 Major changes for Perl >= 5.6
# 1.1 tieing STDERR to ErrorTrap caused a SEGV in libperl because of
# misuse of the open statement.
# 1.2 STDERR is now aliased to the handle associated with a log file
# opened if logging is enabled.
#
# p1.pl for Nagios 2.0
# Only major changes are that STDOUT is redirected to a scalar
# by means of a tied filehandle so that it can be returned to Nagios
# without the need for a syscall to read()
#
use strict ;
use vars '%Cache' ;
use Text::ParseWords qw(parse_line) ;
use constant RETICENT => 1 ;
use constant GARRULOUS => 0 ;
use constant DEBUG => 0 ;
use constant EPN_STDERR_LOG => '/Path/to/embedded/Perl/Nagios/Logfile' ;
use constant TEXT_RETICENT => <<'RETICENT' ;
package OutputTrap;
#
# Methods for use by tied STDOUT in embedded PERL module.
#
# Simply ties STDOUT to a scalar and emulates serial semantics.
#
sub TIEHANDLE {
my ($class) = @_;
my $me ;
bless \$me, $class;
}
sub PRINT {
my $self = shift;
$$self .= join("",@_);
}
sub PRINTF {
my $self = shift;
my $fmt = shift;
$$self .= sprintf($fmt,@_);
}
sub READLINE {
my $self = shift;
# Perl code other than plugins may print nothing; in this case return "(No output!)\n".
return(defined $$self ? $$self : "(No output!)\n");
}
sub CLOSE {
my $self = shift;
}
package Embed::Persistent;
sub valid_package_name {
my($string) = @_;
$string =~ s/([^A-Za-z0-9\/])/sprintf("_%2x",unpack("C",$1))/eg;
# second pass only for words starting with a digit
$string =~ s|/(\d)|sprintf("/_%2x",unpack("C",$1))|eg;
# Dress it up as a real package name
$string =~ s|/|::|g;
return "Embed::" . $string;
}
# Perl 5.005_03 only traps warnings for errors classed by perldiag
# as Fatal (eg 'Global symbol """"%s"""" requires explicit package name').
# Therefore treat all warnings as fatal.
sub throw_exception {
my $warn = shift ;
return if $warn =~ /^Subroutine CORE::GLOBAL::exit redefined/ ;
die $warn ;
}
sub eval_file {
my $filename = shift;
my $delete = shift;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $mtime = -M $filename ;
if ( defined $Cache{$package}{mtime} &&
$Cache{$package}{mtime} <= $mtime) {
# we have compiled this subroutine already,
# it has not been updated on disk, nothing left to do
}
else {
local *FH;
# FIXME - error handling
open FH, $filename or die "'$filename' $!";
local($/) = undef;
my $sub = <FH>;
close FH;
# cater for routines that expect to get args without progname
# and for those using @ARGV
$sub = qq(\nshift(\@_);\n\@ARGV=\@_;\nlocal \$^W=1;\n$sub) ;
# cater for scripts that have embedded EOF symbols (__END__)
$sub =~ s/__END__/\;}\n__END__/;
# wrap the code into a subroutine inside our unique package
my $eval = qq{
package main;
use subs 'CORE::GLOBAL::exit';
sub CORE::GLOBAL::exit { die "ExitTrap: \$_[0] ($package)"; }
package $package; sub hndlr { $sub }
};
$Cache{$package}{plugin_error} = 0 ;
# suppress warning display.
local $SIG{__WARN__} = \&throw_exception ;
{
# hide our variables within this block
my ($filename, $mtime, $package, $sub);
eval $eval;
}
# $@ is set for any warning and error. This guarantees that the plugin will not be run.
if ($@) {
# Log eval'd text of plugin.
# Correct the line number of the error by removing the lines added (the subroutine prologue) by Embed::eval_file.
my $i = 1 ;
$eval =~ s/^/sprintf('%10d ', $i++)/meg ;
$Cache{$package}{plugin_error} = $@ ;
$Cache{$package}{mtime} = $mtime unless $delete;
# If the compilation fails, leave nothing behind that may affect subsequent compilations.
die;
}
#cache it unless we're cleaning out each time
$Cache{$package}{mtime} = $mtime unless $delete;
}
}
sub run_package {
my $filename = shift;
my $delete = shift;
my $tmpfname = shift;
my $ar = shift;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $res = 3;
tie (*STDOUT, 'OutputTrap');
my @a = &parse_line('\s+', 0, $ar) ;
if ( $Cache{$package}{plugin_error} ) {
untie *STDOUT;
# return unknown
return (3, '**ePN' . " '$pn' " . $Cache{$package}{plugin_error} . "\n") ;
}
local $SIG{__WARN__} = \&throw_exception ;
eval { $package->hndlr(@a); };
if ($@) {
if ($@ =~ /^ExitTrap: /) {
# For normal plugin exit the ExitTrap string is set by the
# redefined CORE::GLOBAL::exit sub calling die to return a string =~ /^ExitTrap: -?\d+ $package/
# However, there is only _one_ exit sub so the last plugin to be compiled sets _its_
# package name.
$res = 0;
} else {
# get return code (which may be negative)
if ($@ =~ /^ExitTrap: (-?\d+)/) {
$res = $1;
} else {
# run time error/abnormal plugin termination; exit was not called in plugin
# return unknown
$res = 3;
chomp $@ ;
# correct line number reported by eval for the prologue added by eval_file
$@ =~ s/(\d+)\.$/($1 - 8)/e ;
print STDOUT '**ePN', " '$pn' ", $@, "\n" ;
# Don't run it again until the plugin is recompiled (clearing $Cache{$package}{plugin_error})
# Note that the plugin should be handle any run time errors (such as timeouts)
# that may occur in service checking.
# FIXME - doesn't work under both 5.005 and 5.8.0. The cached value of plugin error is reset somehow.
# $Cache{$package}{plugin_error} = $@ ;
}
}
}
# !!
my $plugin_output = <STDOUT> ;
untie *STDOUT;
return ($res, $plugin_output) ;
}
1;
RETICENT
use constant TEXT_GARRULOUS => <<'GARRULOUS' ;
BEGIN {
open STDERRLOG, '>> ' . EPN_STDERR_LOG
or die "Can't open '" . EPN_STDERR_LOG . " for append: $!" ;
}
package OutputTrap;
#
# Methods for use by tied STDOUT in embedded PERL module.
#
# Simply ties STDOUT to a scalar and emulates serial semantics.
#
sub TIEHANDLE {
my ($class) = @_;
my $me ;
bless \$me, $class;
}
sub PRINT {
my $self = shift;
$$self .= join("",@_);
}
sub PRINTF {
my $self = shift;
my $fmt = shift;
$$self .= sprintf($fmt,@_);
}
sub READLINE {
my $self = shift;
# Perl code other than plugins may print nothing; in this case return "(No output!)\n".
return(defined $$self ? $$self : "(No output!)\n");
}
sub CLOSE {
my $self = shift;
}
package Embed::Persistent;
sub valid_package_name {
my($string) = @_;
$string =~ s/([^A-Za-z0-9\/])/sprintf("_%2x",unpack("C",$1))/eg;
# second pass only for words starting with a digit
$string =~ s|/(\d)|sprintf("/_%2x",unpack("C",$1))|eg;
# Dress it up as a real package name
$string =~ s|/|::|g;
return "Embed::" . $string;
}
# Perl 5.005_03 only traps warnings for errors classed by perldiag
# as Fatal (eg 'Global symbol """"%s"""" requires explicit package name').
# Therefore treat all warnings as fatal.
sub throw_exception {
my $warn = shift ;
return if $warn =~ /^Subroutine CORE::GLOBAL::exit redefined/ ;
die $warn ;
}
sub eval_file {
my $filename = shift;
my $delete = shift;
*STDERR = *STDERRLOG ;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $mtime = -M $filename ;
if ( defined $Cache{$package}{mtime} &&
$Cache{$package}{mtime} <= $mtime) {
# we have compiled this subroutine already,
# it has not been updated on disk, nothing left to do
}
else {
local *FH;
# FIXME - error handling
open FH, $filename or die "'$filename' $!";
local($/) = undef;
my $sub = <FH>;
close FH;
# cater for routines that expect to get args without progname
# and for those using @ARGV
$sub = qq(\nshift(\@_);\n\@ARGV=\@_;\nlocal \$^W=1;\n$sub) ;
# cater for scripts that have embedded EOF symbols (__END__)
$sub =~ s/__END__/\;}\n__END__/;
# wrap the code into a subroutine inside our unique package
my $eval = qq{
package main;
use subs 'CORE::GLOBAL::exit';
sub CORE::GLOBAL::exit { die "ExitTrap: \$_[0] ($package)"; }
package $package; sub hndlr { $sub }
};
$Cache{$package}{plugin_error} = 0 ;
# suppress warning display.
local $SIG{__WARN__} = \&throw_exception ;
{
# hide our variables within this block
my ($filename, $mtime, $package, $sub);
eval $eval;
}
# $@ is set for any warning and error. This guarantees that the plugin will not be run.
if ($@) {
# Log eval'd text of plugin.
# Correct the line number of the error by removing the lines added (the subroutine prologue) by Embed::eval_file.
my $i = 1 ;
$eval =~ s/^/sprintf('%10d ', $i++)/meg ;
print STDERR '[', time(), ']', qq( **ePN '$pn' error '$@' in text "\n$eval"\n) ;
$Cache{$package}{plugin_error} = $@ ;
$Cache{$package}{mtime} = $mtime unless $delete;
# If the compilation fails, leave nothing behind that may affect subsequent compilations.
die;
}
#cache it unless we're cleaning out each time
$Cache{$package}{mtime} = $mtime unless $delete;
}
}
sub run_package {
my $filename = shift;
my $delete = shift;
my $tmpfname = shift;
my $ar = shift;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $res = 3;
tie (*STDOUT, 'OutputTrap');
my @a = &parse_line('\s+', 0, $ar) ;
if ( $Cache{$package}{plugin_error} ) {
untie *STDOUT;
# return unknown
return (3, '**ePN' . " '$pn' " . $Cache{$package}{plugin_error} . "\n") ;
}
local $SIG{__WARN__} = \&throw_exception ;
eval { $package->hndlr(@a); };
if ($@) {
if ($@ =~ /^ExitTrap: /) {
# For normal plugin exit the ExitTrap string is set by the
# redefined CORE::GLOBAL::exit sub calling die to return a string =~ /^ExitTrap: -?\d+ $package/
# However, there is only _one_ exit sub so the last plugin to be compiled sets _its_
# package name.
$res = 0;
} else {
# get return code (which may be negative)
if ($@ =~ /^ExitTrap: (-?\d+)/) {
$res = $1;
} else {
# run time error/abnormal plugin termination; exit was not called in plugin
# return unknown
$res = 3;
chomp $@ ;
# correct line number reported by eval for the prologue added by eval_file
$@ =~ s/(\d+)\.$/($1 - 8)/e ;
print STDOUT '**ePN', " '$pn' ", $@, "\n" ;
# Don't run it again until the plugin is recompiled (clearing $Cache{$package}{plugin_error})
# Note that the plugin should be handle any run time errors (such as timeouts)
# that may occur in service checking.
# FIXME - doesn't work under both 5.005 and 5.8.0. The cached value of plugin error is reset somehow.
# $Cache{$package}{plugin_error} = $@ ;
}
}
}
# !!
my $plugin_output = <STDOUT> ;
untie *STDOUT;
return ($res, $plugin_output) ;
}
1;
GARRULOUS
use constant TEXT_DEBUG => <<'DEBUG' ;
BEGIN {
open STDERRLOG, '>> ' . EPN_STDERR_LOG
or die "Can't open '" . EPN_STDERR_LOG . " for append: $!" ;
}
package OutputTrap;
#
# Methods for use by tied STDOUT in embedded PERL module.
#
# Simply ties STDOUT to a scalar and emulates serial semantics.
#
sub TIEHANDLE {
my ($class) = @_;
my $me ;
bless \$me, $class;
}
sub PRINT {
my $self = shift;
$$self .= join("",@_);
}
sub PRINTF {
my $self = shift;
my $fmt = shift;
$$self .= sprintf($fmt,@_);
}
sub READLINE {
my $self = shift;
# Perl code other than plugins may print nothing; in this case return "(No output!)\n".
return(defined $$self ? $$self : "(No output!)\n");
}
sub CLOSE {
my $self = shift;
}
package Embed::Persistent;
sub valid_package_name {
my($string) = @_;
$string =~ s/([^A-Za-z0-9\/])/sprintf("_%2x",unpack("C",$1))/eg;
# second pass only for words starting with a digit
$string =~ s|/(\d)|sprintf("/_%2x",unpack("C",$1))|eg;
# Dress it up as a real package name
$string =~ s|/|::|g;
return "Embed::" . $string;
}
# Perl 5.005_03 only traps warnings for errors classed by perldiag
# as Fatal (eg 'Global symbol """"%s"""" requires explicit package name').
# Therefore treat all warnings as fatal.
sub throw_exception {
my $warn = shift ;
return if $warn =~ /^Subroutine CORE::GLOBAL::exit redefined/ ;
print STDERR " ... throw_exception: calling die $warn\n" ;
die $warn ;
}
sub eval_file {
my $filename = shift;
my $delete = shift;
*STDERR = *STDERRLOG ;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $mtime = -M $filename ;
if ( defined $Cache{$package}{mtime} &&
$Cache{$package}{mtime} <= $mtime) {
# we have compiled this subroutine already,
# it has not been updated on disk, nothing left to do
print STDERR "(I) \$mtime: $mtime, \$Cache{$package}{mtime}: '$Cache{$package}{mtime}' - already compiled $package->hndlr.\n";
}
else {
print STDERR "(I) \$mtime: $mtime, \$Cache{$package}{mtime}: '$Cache{$package}{mtime}' - Compiling or recompiling \$filename: $filename.\n" ;
local *FH;
# FIXME - error handling
open FH, $filename or die "'$filename' $!";
local($/) = undef;
my $sub = <FH>;
close FH;
# cater for routines that expect to get args without progname
# and for those using @ARGV
$sub = qq(\nshift(\@_);\n\@ARGV=\@_;\nlocal \$^W=1;\n$sub) ;
# cater for scripts that have embedded EOF symbols (__END__)
$sub =~ s/__END__/\;}\n__END__/;
# wrap the code into a subroutine inside our unique package
my $eval = qq{
package main;
use subs 'CORE::GLOBAL::exit';
sub CORE::GLOBAL::exit { die "ExitTrap: \$_[0] ($package)"; }
package $package; sub hndlr { $sub }
};
$Cache{$package}{plugin_error} = 0 ;
# suppress warning display.
local $SIG{__WARN__} = \&throw_exception ;
{
# hide our variables within this block
my ($filename, $mtime, $package, $sub);
eval $eval;
}
# $@ is set for any warning and error. This guarantees that the plugin will not be run.
if ($@) {
# Log eval'd text of plugin.
# Correct the line number of the error by removing the lines added (the subroutine prologue) by Embed::eval_file.
# $@ =~ s/line (\d+)\.\n/'line ' . ($1 - 8) . ".\n"/ge ;
my $i = 1 ;
$eval =~ s/^/sprintf('%10d ', $i++)/meg ;
print STDERR '[', time(), ']', qq( **ePN '$pn' error '$@' in text "\n$eval"\n) ;
$Cache{$package}{plugin_error} = $@ ;
$Cache{$package}{mtime} = $mtime unless $delete;
# If the compilation fails, leave nothing behind that may affect subsequent compilations.
die;
}
#cache it unless we're cleaning out each time
$Cache{$package}{mtime} = $mtime unless $delete;
}
}
sub run_package {
my $filename = shift;
my $delete = shift;
my $tmpfname = shift;
my $ar = shift;
my $pn = substr($filename, rindex($filename,"/")+1);
my $package = valid_package_name($pn);
my $res = 3;
use Data::Dumper ;
print STDERR Data::Dumper->Dump([\%Cache], [qw(%Cache)]) ;
tie (*STDOUT, 'OutputTrap');
my @a = &parse_line('\s+', 0, $ar) ;
if ( $Cache{$package}{plugin_error} ) {
untie *STDOUT;
# return unknown
print STDERR " ... eval failed in eval_file, run_package returning (3, **ePN '$pn' '$Cache{$package}{plugin_error}'\\n)\n" ;
return (3, '**ePN' . " '$pn' " . $Cache{$package}{plugin_error} . "\n") ;
}
local $SIG{__WARN__} = \&throw_exception ;
eval { $package->hndlr(@a); };
if ($@) {
if ($@ =~ /^ExitTrap: /) {
# For normal plugin exit the ExitTrap string is set by the
# redefined CORE::GLOBAL::exit sub calling die to return a string =~ /^ExitTrap: -?\d+ $package/
# However, there is only _one_ exit sub so the last plugin to be compiled sets _its_
# package name.
$res = 0;
} else {
# get return code (which may be negative)
if ($@ =~ /^ExitTrap: (-?\d+)/) {
$res = $1;
} else {
# run time error/abnormal plugin termination; exit was not called in plugin
# return unknown
$res = 3;
chomp $@ ;
# correct line number reported by eval for the prologue added by eval_file
$@ =~ s/(\d+)\.$/($1 - 8)/e ;
print STDOUT '**ePN', " '$pn' ", $@, "\n" ;
# Don't run it again until the plugin is recompiled (clearing $Cache{$package}{plugin_error})
# Note that the plugin should be handle any run time errors (such as timeouts)
# that may occur in service checking.
# FIXME - doesn't work under both 5.005 and 5.8.0. The cached value of plugin error is reset somehow.
# $Cache{$package}{plugin_error} = $@ ;
}
}
}
# !!
my $plugin_output = <STDOUT> ;
untie *STDOUT;
print STDERR " ... run_package returning ('$res', '$plugin_output')\n" ;
return ($res, $plugin_output) ;
}
1;
DEBUG
SWITCH: {
eval TEXT_RETICENT, last SWITCH if RETICENT ;
eval TEXT_GARRULOUS, last SWITCH if GARRULOUS ;
eval TEXT_DEBUG, last SWITCH if DEBUG ;
die "Please set one of (use constant statements) RETICENT, GARRULOUS or DEBUG in code.\n" ;
}
1 ;
=head1 NAME
p1.pl - Perl program to provide Perl code persistence for the Nagios project (http://www.Nagios.Org).
This program attempts to provide a mod_perl like facility for Nagios.
=head1 SYNOPSIS
Edit the text to set the values of (the 'use constant' statements) the log path, B<EPN_STDERR_LOG>, and any one
(only) of the boolean log level flags B<GARRULOUS>, B<DEBUG>, and B<RETICENT>. The default is to set RETICENT, and
to use S<<path_to_Nagios>/var/epn_stderr.log> as the log path.
The log level flags determine the amount and type of messages logged in the log path.
The RETICENT log level results in similar behaviour to former versions of p1.pl.
In particular, the log file EPN_STDERR_LOG will B<not> be opened.
=head1 DESCRIPTION
Nagios is a program to monitor service availability; it does this by scheduling 'plugins' - discrete programs
that check a service and output a line of text describing the service state intended for
those responsible for the service and exit with a coded value to relay the same information to Nagios.
Plugins, like CGIs, can be coded in Perl. The persistence framework embeds a Perl interpreter in Nagios to
=over 4
=item * reduce the time taken for the Perl compile and execute cycle.
=item * eliminate the need for the shell to fork and exec Perl.
=item * eliminate the need for Nagios to fork a process (with popen) to run the Perl code.
=item * eliminate reloading of frequently used modules.
=back
and all the good things mentioned in the B<perlembed> man page under 'Maintaining a persistent interpreter'.
Plugin syntax errors (possibly introduced when the plugin is transformed by the persistence framework) and run-time
errors are logged depending on the log level flags.
Regardless of the log level, plugin run-time and syntax errors, are returned to Nagios as the 'plugin output'. These messages
appear in the Nagios log like S<**ePN 'check_test' Global symbol "$status" requires explicit package name at (eval 54) line 15.>
=over 4
=item * GARRULOUS
=over 8
=item 1 opens an extra output stream in the path given by the value of EPN_STDERR_LOG.
=item 2 logs a listing of plugin errors, followed by a dump of the plugin source - as transformed by
the persistence framework - each time the plugin source file modification time stamp is changed (either
by correcting the syntax error or touching the file).
=back
An example of such a listing is
[1074760243] **ePN 'check_test' error 'Global symbol "$status" requires explicit package name at (eval 54) line 15. ' in text "
1
2 package main;
3 use subs 'CORE::GLOBAL::exit';
4 sub CORE::GLOBAL::exit { die "ExitTrap: $_[0] (Embed::check_5ftest)"; }
5 package Embed::check_5ftest; sub hndlr {
6 shift(@_);
7 @ARGV=@_;
8 local $^W=1;
9 #!/usr/bin/perl -w
10
11 # This plugin always does what it is told.
12
13 use strict ;
14
15 $status = shift @ARGV ;
16 # my $status = shift @ARGV ;
17 $status ||= 'fail' ;
18
19 my $invert = 1 ;
20
21 $status = lc($status) ;
22
23 $status = ( ( $invert and $status eq 'ok' ) ? 'fail' :
24 ( $invert and $status eq 'fail' ) ? 'ok' :
25 $status ) ;
26
27 $status eq 'ok' and do {
28 print "Ok. Got a \"$status\". Expecting \"OK\".\n" ;
29 exit 0 ;
30 } ;
31
32 $status eq 'fail' and do {
33 print "Failed. Got a \"$status\". Expecting \"FAIL\".\n" ;
34 exit 2 ;
35 } ;
36
37 # print "Mmmm. Looks like I got an "$status\" when expecting an \"ok\" or \"fail\".\n" ;
38 print "Mmmm. Looks like I got an \"$status\" when expecting an \"ok\" or \"fail\".\n" ;
39 exit 3 ;
40 }
41 "
Note that the plugin text (lines 9 to 39 inclusive) has been transformed by the persistence frame work to
E<10>1 override the exit sub in package main
E<10>2 create a new package from the plugin file name, here Embed::check_5ftest
E<10>3 wrap the plugin in a subroutine named hndlr within the new package
E<10>4 handle the argument list the same way as for a method call, restoring @ARGV from the remaining
arguments
E<10>5 Setting the warning level to trap all warnings (note that the -w option to Perl is no
longer significant because the shebang line is not fed to exec()).
=item * DEBUG
This setting is intended only for hacking this code. In addition to the garrulous messages
=over 8
=item 1 enter, leave messages
=item 2 dump of %Cache data structure
=back
=item * RETICENT
This is the default verbosity level and recommended for production use. One line only of compile or run
time errors is reported in the Nagios log. There are no other output streams.
=back
=head1 SUBROUTINES
Unless otherwise stated, all subroutines take two (2) arguments :-
=over 4
=item 1 plugin_filename - string (called from C) or scalar(called from Perl): the path to the plugin.
=item 2 DO_CLEAN - boolean: set if plugin is not to be cached. Defaults to 0.
Setting this flag means that the plugin is compiled each time it is executed. Nagios B<never> sets this flag when the
Nagios is compiled with the configure setting --with-perlcache.
=back
=over 4
=item Embed::Persistent::eval_file( plugin_filename, DO_CLEAN )
E<10>
Returns nothing.
eval_file() transforms the plugin to a subroutine in a package, compiles the string containing the
transformed plugin, caches the plugin file modification time (to avoid recompiling it), and caches
any errors returned by the compilation.
If the plugin has been modified or has not been compiled before, the plugin is transformed to a subroutine in a new package by
creating a package name from the plugin file name (C<Embed::Persistent::valid_package_name>)
turning off subroutine redefinition warnings (C<use subs 'CORE::GLOBAL::exit'>)
overriding CORE::GLOBAL::exit from within package main (C<sub CORE::GLOBAL::exit { die "ExitTrap: \$_[0] ($package)"; }>)
This allows the plugin to call exit without taking down the persistence framework.
prepending the plugin text with code to let the plugin function as a subroutine. This code sets up
the plugin argument vector (@ARGV) from the subroutine arguments and turns on warnings.
(C<$sub = qq(\nshift(\@_);\n\@ARGV=\@_;\nlocal \$^W=1;\n$sub)>).
writing the plugin as the subroutine named 'hndlr' in the new package (C<package $package; sub hndlr { $sub }>)
The plugin compilation, performed by C<eval $eval>, caches C<$@> if the transformed plugin has syntax errors.
=item Embed::Persistent::run_package( plugin_filename, DO_CLEAN, '', plugin_argument_string )
E<10>
Returns (plugin_return_code, plugin_output)
run_package()
=back
=head1 BUGS
This framework does nothing to prevent the memory leaks mentioned in B<perlembed>, relying on operator intervention.
Probably the best way of doing so is by periodically scheduling
=over 4
=item 1 A check of the memory used by the Nagios process (by running for example the standard Nagios plugin check_vsz)
=item 2 Restarting Nagios with the (supplied with Nagios) startup script (restart command).
=back
If you do periodocally restart Nagios, make sure that
=over 4
=item 1 plugins all set the PATH environment variable if they need other system binaries (otherwise, if the
init script is excec'd by cron, the PATH will be reset and the plugins will fail - but only when reatsrted by cron).
=item 2 that the group owning the Nagios command pipe is the same as the Nagios group (otherwise, the restarted
Nagios will not be able to read from the command pipe).
=back
Nagios installations using the persistence framework must monitor the memory use of the Nagios process and stop/start it when
the usage is exorbidant (eg, for a site with 400 services on 200 hosts and custom Perl plugins used for about 10% of the
service checks, the Nagios process uses ~80 MB after 20-30 days runningi with Perl 5.005 [Memory usage is
B<much> greater with recent Perls]. It is usually stopped and started at this point).
Note that a HUP signal is B<not> sufficient to deallocate the Perl memory; the Nagios process must be stopped and started.
=head1 AUTHOR
Originally by Stephen Davies.
Now maintained by Stanley Hopcroft <hopcrofts@cpan.org> who retains responsibility for the 'bad bits'.
=head1 COPYRIGHT
Copyright (c) 2004 Stanley Hopcroft. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut

View File

@ -66,10 +66,10 @@ print "</head>\n<body>\n";
print "<table class='infoBox' border=1 cellspacing=0 cellpadding=0>"; print "<table class='infoBox' border=1 cellspacing=0 cellpadding=0>";
print "<tr><td class='infoBox'>"; print "<tr><td class='infoBox'>";
print "<div class='infoBoxTitle'>traceroute</div>"; print "<div class='infoBoxTitle'>traceroute</div>";
print "Genereated by $self<br>"; print "Generated by $self<br>";
print "Last Updated: $mdate<br>"; print "Last Updated: $mdate<br>";
print "Updated every $refresh seconds<br>"; print "Updated every $refresh seconds<br>";
print "Nagios&reg; - <a href='http://www.nagios.org' target='_new' class='homepageURL'>www.nagios.org</a><br>"; print "Nagios&reg; - <a href='https://www.nagios.org' target='_new' class='homepageURL'>www.nagios.org</a><br>";
print "Logged in as <i>$ENV{'REMOTE_USER'}</i><br>"; print "Logged in as <i>$ENV{'REMOTE_USER'}</i><br>";
print "</td></tr>"; print "</td></tr>";
print "</table>"; print "</table>";

View File

@ -2,7 +2,7 @@
# #
# chkconfig: 345 99 01 # chkconfig: 345 99 01
# description: Nagios network monitor # description: Nagios network monitor
# # processname: nagios
# File : nagios # File : nagios
# #
# Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl) # Author : Jorge Sanchez Aymar (jsanchez@lanchile.cl)
@ -28,76 +28,22 @@
# Description: Starts and stops the Nagios monitor # Description: Starts and stops the Nagios monitor
# used to provide network services status. # used to provide network services status.
# #
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts and stops the Nagios monitoring server
# Description: Starts and stops the Nagios monitoring server
### END INIT INFO
# Load any extra environment variables for Nagios and its plugins # Our install-time configuration.
if test -f /etc/sysconfig/nagios; then
. /etc/sysconfig/nagios
fi
status_nagios ()
{
if test -x $NagiosCGI/daemonchk.cgi; then
if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile; then
return 0
else
return 1
fi
else
if ps -p $NagiosPID > /dev/null 2>&1; then
return 0
else
return 1
fi
fi
return 1
}
printstatus_nagios()
{
if status_nagios $1 $2; then
echo "nagios (pid $NagiosPID) is running..."
else
echo "nagios is not running"
fi
}
killproc_nagios ()
{
kill $2 $NagiosPID
}
pid_nagios ()
{
if test ! -f $NagiosRunFile; then
echo "No lock file found in $NagiosRunFile"
exit 1
fi
NagiosPID=`head -n 1 $NagiosRunFile`
}
# Source function library
# Solaris doesn't have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
prefix=@prefix@ prefix=@prefix@
exec_prefix=@exec_prefix@ exec_prefix=@exec_prefix@
NagiosBin=@bindir@/nagios NagiosBin=@bindir@/nagios
NagiosCfgFile=@sysconfdir@/nagios.cfg NagiosCfgFile=@sysconfdir@/nagios.cfg
NagiosCfgtestFile=@localstatedir@/nagios.configtest
NagiosStatusFile=@localstatedir@/status.dat NagiosStatusFile=@localstatedir@/status.dat
NagiosRetentionFile=@localstatedir@/retention.dat NagiosRetentionFile=@localstatedir@/retention.dat
NagiosCommandFile=@localstatedir@/rw/nagios.cmd NagiosCommandFile=@localstatedir@/rw/nagios.cmd
@ -108,17 +54,139 @@ NagiosLockFile=nagios
NagiosCGIDir=@sbindir@ NagiosCGIDir=@sbindir@
NagiosUser=@nagios_user@ NagiosUser=@nagios_user@
NagiosGroup=@nagios_grp@ NagiosGroup=@nagios_grp@
checkconfig="true"
# Source function library
# Some *nix do not have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi
# Load any extra environment variables for Nagios and its plugins.
if test -f /etc/sysconfig/nagios; then
. /etc/sysconfig/nagios
fi
# Automate addition of RAMDISK based on environment variables
USE_RAMDISK=${USE_RAMDISK:-0}
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
ramdisk=`mount |grep "${RAMDISK_DIR} type tmpfs"`
if [ "$ramdisk"X == "X" ]; then
mkdir -p -m 0755 ${RAMDISK_DIR}
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs ${RAMDISK_DIR}
mkdir -p -m 0755 ${RAMDISK_DIR}/checkresults
chown -h -R $NagiosUser:$NagiosGroup ${RAMDISK_DIR}
fi
fi
check_config ()
{
rm -f "$NagiosCfgtestFile";
if test -e "$NagiosCfgtestFile"; then
echo "ERROR: Could not delete '$NagiosCfgtestFile'"
exit 8
fi
TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
$NagiosBin -vp $NagiosCfgFile > "$TMPFILE"
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
if test "$WARN" = "0" && test "${ERR}" = "0"; then
echo "OK - Configuration check verified" > $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown -h $NagiosUser:$NagiosGroup $NagiosCfgtestFile
/bin/rm "$TMPFILE"
return 0
elif test "${ERR}" = "0"; then
# Write the errors to a file we can have a script watching for.
echo "WARNING: Warnings in config files - see log for details: $NagiosCfgtestFile" > $NagiosCfgtestFile
egrep -i "(^warning|^error)" "$TMPFILE" >> $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown -h $NagiosUser:$NagiosGroup $NagiosCfgtestFile
/bin/rm "$TMPFILE"
return 0
else
# Write the errors to a file we can have a script watching for.
echo "ERROR: Errors in config files - see log for details: $NagiosCfgtestFile" > $NagiosCfgtestFile
egrep -i "(^warning|^error)" "$TMPFILE" >> $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown -h $NagiosUser:$NagiosGroup $NagiosCfgtestFile
cat "$TMPFILE"
exit 8
fi
}
status_nagios ()
{
if test -x $NagiosCGI/daemonchk.cgi; then
if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile > /dev/null 2>&1; then return 0; fi
else
if ps -p $NagiosPID > /dev/null 2>&1; then return 0; fi
fi
return 1
}
printstatus_nagios ()
{
if status_nagios; then
echo "nagios (pid $NagiosPID) is running..."
else
echo "nagios is not running"
fi
}
killproc_nagios ()
{
kill -s "$1" $NagiosPID
}
pid_nagios ()
{
if test ! -f $NagiosRunFile; then
echo "No lock file found in $NagiosRunFile"
exit 1
fi
NagiosPID=`head -n 1 $NagiosRunFile`
}
remove_commandfile ()
{
# Removing a stalled command file, while there are processes trying/waiting to write into it,
# will deadlock those processes in a blocking open() system call. To allow such processes to
# die on a broken pipe, the pipe must be opened for reading without actually reading from it,
# which is what dd does here. To avoid a chicken-egg problem, the pipe is renamed beforehand.
# In order for the dd to not deadlock when there is no writing process, it is executed in the
# background in a subshell together with an empty echo to have at least one writing process.
# see http://unix.stackexchange.com/questions/335406/opening-named-pipe-blocks-forever-if-pipe-is-deleted-without-being-connected
if [ -p $NagiosCommandFile ]; then
mv -f $NagiosCommandFile $NagiosCommandFile~
(dd if=$NagiosCommandFile~ count=0 2>/dev/null & echo -n "" >$NagiosCommandFile~)
fi
rm -f $NagiosCommandFile $NagiosCommandFile~
}
# Check that nagios exists. # Check that nagios exists.
if [ ! -f $NagiosBin ]; then if [ ! -f $NagiosBin ]; then
echo "Executable file $NagiosBin not found. Exiting." echo "Executable file $NagiosBin not found. Exiting."
exit 1 exit 1
fi fi
# Check that nagios.cfg exists. # Check that nagios.cfg exists.
if [ ! -f $NagiosCfgFile ]; then if [ ! -f $NagiosCfgFile ]; then
echo "Configuration file $NagiosCfgFile not found. Exiting." echo "Configuration file $NagiosCfgFile not found. Exiting."
exit 1 exit 1
fi fi
@ -127,60 +195,73 @@ case "$1" in
start) start)
echo -n "Starting nagios:" echo -n "Starting nagios:"
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
if [ $? -eq 0 ]; then if test "$checkconfig" = "true"; then
su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile" check_config
rm -f $NagiosCommandFile # check_config exits on configuration errors.
touch $NagiosRunFile
chown $NagiosUser:$NagiosGroup $NagiosRunFile
$NagiosBin -d $NagiosCfgFile
if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
echo " done."
exit 0
else
echo "CONFIG ERROR! Start aborted. Check your Nagios configuration."
exit 1
fi fi
if test -f $NagiosRunFile; then
NagiosPID=`head -n 1 $NagiosRunFile`
if status_nagios; then
echo " another instance of nagios is already running."
exit 0
fi
fi
touch $NagiosVarDir/nagios.log $NagiosRetentionFile
remove_commandfile
touch $NagiosRunFile
chown -h $NagiosUser:$NagiosGroup $NagiosRunFile $NagiosVarDir/nagios.log $NagiosRetentionFile
$NagiosBin -d $NagiosCfgFile
if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
echo " done."
;; ;;
stop) stop)
echo -n "Stopping nagios: " echo -n "Stopping nagios:"
pid_nagios pid_nagios
killproc_nagios nagios killproc_nagios TERM
# now we have to wait for nagios to exit and remove its # now we have to wait for nagios to exit and remove its
# own NagiosRunFile, otherwise a following "start" could # own NagiosRunFile, otherwise a following "start" could
# happen, and then the exiting nagios will remove the # happen, and then the exiting nagios will remove the
# new NagiosRunFile, allowing multiple nagios daemons # new NagiosRunFile, allowing multiple nagios daemons
# to (sooner or later) run - John Sellens # to (sooner or later) run - John Sellens
#echo -n 'Waiting for nagios to exit .' #echo -n 'Waiting for nagios to exit .'
for i in 1 2 3 4 5 6 7 8 9 10 ; do for i in {1..90}; do
if status_nagios > /dev/null; then if status_nagios > /dev/null; then
echo -n '.' echo -n '.'
sleep 1 sleep 1
else else
break break
fi fi
done done
if status_nagios > /dev/null; then if status_nagios > /dev/null; then
echo '' echo ''
echo 'Warning - nagios did not exit in a timely manner' echo 'Warning - nagios did not exit in a timely manner - Killing it!'
else killproc_nagios KILL
echo 'done.' else
fi echo ' done.'
fi
rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile remove_commandfile
rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile
;; ;;
status) status)
pid_nagios pid_nagios
printstatus_nagios nagios printstatus_nagios
;; ;;
checkconfig) checkconfig)
printf "Running configuration check..." if test "$checkconfig" = "true"; then
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1; printf "Running configuration check...\n"
check_config
fi
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo " OK." echo " OK."
else else
@ -190,44 +271,42 @@ case "$1" in
;; ;;
restart) restart)
printf "Running configuration check..." if test "$checkconfig" = "true"; then
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1; printf "Running configuration check...\n"
if [ $? -eq 0 ]; then check_config
echo "done."
$0 stop
$0 start
else
echo " CONFIG ERROR! Restart aborted. Check your Nagios configuration."
exit 1
fi fi
$0 stop
$0 start
;; ;;
reload|force-reload) reload|force-reload)
printf "Running configuration check..." if test "$checkconfig" = "true"; then
$NagiosBin -v $NagiosCfgFile > /dev/null 2>&1; printf "Running configuration check...\n"
if [ $? -eq 0 ]; then check_config
echo "done." fi
if test ! -f $NagiosRunFile; then
$0 start if test ! -f $NagiosRunFile; then
else $0 start
pid_nagios
if status_nagios > /dev/null; then
printf "Reloading nagios configuration..."
killproc_nagios nagios -HUP
echo "done"
else
$0 stop
$0 start
fi
fi
else else
echo " CONFIG ERROR! Reload aborted. Check your Nagios configuration." pid_nagios
exit 1 if status_nagios > /dev/null; then
printf "Reloading nagios configuration...\n"
killproc_nagios HUP
echo "done"
else
$0 stop
$0 start
fi
fi fi
;; ;;
configtest)
$NagiosBin -vp $NagiosCfgFile
;;
*) *)
echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig}" echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig|configtest}"
exit 1 exit 1
;; ;;

73
docs/api-incompat3to4.dox Normal file
View File

@ -0,0 +1,73 @@
/**@page api_incompat3to4 API incompatibilities between Nagios 3 and 4
A list of API incompatibilities between Nagios 3 and 4.
[TOC]
@section globalvars Global Variables
@li event_list_{high,low} and event_list_{high,low}_tail are no more.
Instead there is "squeue_t *nagios_squeue", which is a single queue
to handle all timed events.
@li last_command_check, command_check_interval, external_command_buffer
and external_command_buffer_slots are no more.
@li check_result_list is no more
@li passive_check_result_list and passive_check_result_list_tail are no
more.
@section datastructures Data Structures
@li All primary objects have been given an 'id' field, which can be
used to store additional data about each object, or mark them in
bitmaps, or...
@li Container-ish pointers have been removed pretty much everywhere in
favour of testable libraries with specific lookup properties and
containers. This means 'next_hash' etc no longer exist in any object.
The 'next' pointers in primary objects still remain, but you should
avoid using them in favour of iterating over objects using the object
arrays.
@li next and prev have been removed from timed_event. It's no longer
possible to sanely loop over all queued elements, since the squeue
library keeps its types opaque. Adding an "squeue_foreach()" thing
would be as simple as running a breadth-first search in the pqueue
library that drives the squeue implementation.
@li The scheduled_downtime data type now has start_event and
stop_event.
@li nebstruct_program_status_data no longer has a last_command_check
var.
@li The passive_service_check data type is no more.
@li The data type circular_buffer has been removed.
@li The host object's notify_on_down, notify_on_up, notify_on_blablah
variables have been replaced with a single "notification_options" field
instead, which is a small hand-managed bitmask of the states we should
notify on, based on 1 << current_state.
@li As per above, with flap_detection_options
@li As per above, with stalking_options
@li As per the three above, with services
@li As per above, with dependencies which now have a "failure_options"
field instead of multiple "fail_on_foo" fields.
@li As per above with escalations, which now have an
"escalation_options" field instead of multiple "escalate on foo" fields.
@section functions Functions
@li Event queue management functions have been significantly altered
to match the new scheduling queue implementation. add_event(),
remove_event(), reschedule_event() and schedule_new_event() are the
primary ones.
@li submit_external_command() and submit_raw_external_command() have
been removed, as has check_for_external_commands().
@li All functions handling adding and removing objects to circular
buffers or other types of linked lists used for searching have been
removed.
@li The *host*_3x() functions are gone. They have been replaced with
versions without the _3x suffix.
@li run_sync_host_check_3x() is gone. perform_on_demand_host_check(),
which previously only called run_sync_host_check_3x(), now does
something sensible instead of calling out to a single helper.
@li Using the 'struct host_struct *foo' form of type-naming has been
obsoleted and will no longer work. Use 'struct host' instead.
@li Use of typedef'ed typenames for non-opaque structures is now
deprecated. The typedef's will be removed in Nagios 5, and modules
that wish to continue using them after that will have to add them
themselves. The new preferred form is 'struct host *foo', which
clearly shows that we're dealing with a non-opaque type.
*/

View File

@ -0,0 +1,119 @@
/** @page configincompat3to4 Configuration Incompatibilities 3->4
This page lists configuration incompatibilities between Nagios 3
and Nagios 4.
[TOC]
@section mainconfig Main Config File Options
Since command file handling has been redone, embedded perl has been
removed and the event execution loop now sits and waits on input from
worker processes rather than spending any time sleeping, the following
variables have been obsoleted, will yield a warning when encountered
and no longer have any effect on monitoring:
@li command_check_interval
@li external_command_buffer_slots
@li sleep_time
@li enable_failure_prediction
@li enable_embedded_perl
@li use_embedded_perl_implicitly
@li auth_file
@li p1_file
@section nestedgroups Nested Group Includes
In Nagios 3, it's possible to have groups include each other
cyclically, like this:
@verbatim
define hostgroup{
hostgroup_name HG1
alias Hostgroup 1
hostgroup_members HG3
}
define hostgroup{
hostgroup_name HG2
alias Hostgroup 2
hostgroup_members HG1
}
define hostgroup{
hostgroup_name HG3
alias Hostgroup 3
hostgroup_members HG2
}
@endverbatim
With Nagios 4, that will generate an error. The Nagios 3 behaviour
is that the first hostgroup, as determined by alphabetical sorting,
will get the members of its included groups, but the later ones in
the sorting will not get the members of the previous ones. Since
that is an error-prone and illogical way of assigning group members,
we now disallow it.
This will work the same for all grouptypes.
@section groupinherits Group Inheritance
Groups no longer inherit each others exclusions. Consider the
following scenario:
@verbatim
define host{
use default-host-template
host_name A
alias linux Server1
address 127.0.0.1
hostgroups HG1
contact_groups support-group
}
define hostgroup{
hostgroup_name HG1
alias Hostgroup 1
hostgroup_members HG3
}
define hostgroup{
hostgroup_name HG3
alias Hostgroup 3
members E,F,H,!A
hostgroup_members HG2
}
@endverbatim
In Nagios 3, A would *not* be a member of HG1. In Nagios 4, it will,
because the logic has been fixed so that group inclusion works only
with the actual members, and not the rules concerning how those
members were chosen.
If you want to carry over exclusions, you can instead make a template
and 'use' one hostgroup from another.
The same goes for all group types, and not just hostgroups.
@section oconfchanges Object Configuration Changes
@subsection Deprecations
The "obsess_over_host" (for hosts) and "obsess_over_service" (for
services) configuration variables have been renamed to simply "obsess".
The old values will serve as aliases for the duration of the Nagios 4
lifetime and will be removed in Nagios 5. Users should adjust their
configurations accordingly.
@subsection additions Additions
Services have two new configurable values:
@li parents
@li hourly_value
The 'parents' directive can be used to suppress notifications for a
service in much the same way that it can be used for hosts. If all
parents of a particular service are in a non-OK state when the child
service enters a HARD state (and should have notified), notifications
will be suppressed for the child service.
The 'hourly_value' directive can be used to set a service 'value' of
the service in question. It works in tandem with a new directive for
contacts ("minimum_value") in order to suppress notifications, and
UI's are encouraged to take it into account to display the most severe
and valuable errors in a more prominent fashion. Note that it has no
currency attached to it, so whether you interpret it as affected_users,
business_value or whatever is entirely up to you.
Contacts have one new configurable value, namely 'minimum_value', which
sets the minimum notification value for which the contact should get
notified. The notification value is determined by the total value of
all objects affected by the problem.
*/

4
docs/mainpage.dox Normal file
View File

@ -0,0 +1,4 @@
/** @mainpage
Technical and api documentation for Nagios.
*/

130
docs/queryhandlers.dox Normal file
View File

@ -0,0 +1,130 @@
/** @page qh Query Handler
A brief intro to the Nagios query handler system
[TOC]
@section purpose Purpose
The purpose of the query handler is to provide Nagios Core and its
eventbroker modules with the ability to communicate directly with
the outside world through a well-defined API, as well as allowing
external apps a way to help out with various Nagios tasks.
@section caveats Caveats
The query handlers run in the main thread. Nagios doesn't provide any
parallelism here and main Nagios will be blocked while a query is
running. As such, it's a very good idea to make ones queryhandlers
complete in as little time as possible.
@section qh_registering Registering a query handler
This is really for module authors only.
To register a query handler, you *must* have a function like the one
below:
the following arguments:
@code
int lala_query_handler(int sd, char *query, unsigned int query_len)
@endcode
The parameters don't have to have those exact names, and the function
certainly doesn't have to be called "lala_query_handler()". We're not
quite that childish (well, we are, but we like to pretend we're not).
They will suffice for this explanation, however.
@li sd - The socket you should respond to.
@li query - The query, minus the address and the magic byte.
@li query_len - Length of the query, in bytes.
The call to register it with Nagios so you get all queries directed
to the 'lala' address is then:
@code
qh_register_handler("lala", "The LaLa query handler", 0,
lala_query_handler);
@endcode
The second argument is a description, which will be printed when
someone sends a help request.
@note It's a good idea to handle queries such as "help" and take
them to mean "print me some text telling me at least the basics
of how to use this query handler".
@section syntax Syntax
The query language is remarkably simple (although each handler may
implement its own parsers that handle and do pretty much whatever
they want). The first byte is magic. If it's an at-sign, we expect
the queryer to persist and issue more queries after the first one.
If it's a hash-sign, the query handler will disconnect the client
as soon as it regains control from whatever handler registered for
the particular address. Each particular handler has some control
over this behaviour though, and can use specific return codes to
denote that it will take over the socket from the query handler.
If no at-sign and no hash-sign is present at the first byte, the
-1'th byte will be considered an at-sign, and the connection will
consequently be considered persistent.
@subsection qh_examples Example queries
Subscribe for real-time push-events for servicechecks from the NERD radio:
@verbatim
@nerd subscribe servicechecks\0
@endverbatim
One-shot query the core query handler for current load-control options:
@verbatim
#core loadctl\0
@endverbatim
Get Nagios to say hi to you:
@verbatim
#echo Greetings, Exalted One
@endverbatim
Ask the help handler to list registered handlers:
@verbatim
#help list
@endverbatim
@section icqh In-core query handlers
There are a few in-core query handlers.
@subsection help The help service
The help query handler is quite possibly the most important one. It
can be used to list registered handlers (with short descriptions),
and can be used to get help about registered handlers (assuming
they've implemented it, that is). It should be noted that the ones
that *have* implemented it can also be queried directly for their
help output, like so:
@verbatim
@core help
@endverbatim
@subsection echo The echo service
As I'm sure you've already guessed, the echo service just prints the
inbound data right back at you. While that's not exactly nobel prize
winning material, it's actually pretty nifty to figure out how fast
Nagios can parse its inbound data, which in turn shows how fast it can
handle its inbound checkresults, which puts an upper cap on how many
checks Nagios can handle at any given time (although short bursts that
exceed that limit are ok and will be handled just fine).
It can be addressed as such:
@verbatim
@echo foo bar baz said the bunny\0
@endverbatim
@subsection nerd Nagios Event Radio Dispatcher
The nerd radio is subscribed in fuller detail at @see nerd, but its
worth knowing that it's a core part of Nagios 4 and that it will
always be available.
@subsection wproc Worker process manager
The worker process manager lets you register workers that can help out
with running checks, send notifications, run eventhandlers or whatever.
In order to register a worker that only handles checks supposed to be
run by the plugins check_foo and check_bar (irrespective of where in
the paths they are), you'd do something like this:
@verbatim
@wproc register name=foobar;plugin=check_foo;plugin=check_bar\0
@endverbatim
*/

269
docs/workers.dox Normal file
View File

@ -0,0 +1,269 @@
/** @page wprocs Worker Processes
Everything related to worker processes.
[TOC]
@section philosophy Philosophy
The idea behind separate worker processes is to achieve protected
parallelization. Protected because a worker being naughty shouldn't
affect the core process, and parallel because we use multiple
workers. Ideally between 1.5 and 3 per CPU core available to us.
Workers are free-standing processes, kept small, and with no
knowledge about Nagios' object structure or logic. The reason for
this is that small processes can achieve a lot more fork()s per
second than large processes (800/sec for a 300MB process against
13900/sec for a 1MB process). While workers can (and do) grow a
little bit in memory usage when it's running many checks in
parallel, they will still be a lot smaller than the primar Nagios
daemon, and the memory they occupy should be released once the
checks they're running are done.
@section protocol Protocol
Workers use a text-based protocol to communicate with workers. It's
fairly simple and very easy to debug. The breakdown goes as follows:
@li A request consists of a sequence of key/value pairs.
@li A key is separated from its value with an equal sign ('=').
@li A key/value pair is separated from the next key/value pair with a
nul byte ('\0').
@li Each request is separated from the next with a message delimiter
sequence made up by a one-byte followed by three nul bytes: "\1\0\0\0".
@li Keys cannot contain equal signs.
underscores and numbers.
@li Values cannot contain nul bytes.
@li Neither keys nor values can contain the message delimiter.
@li A zero-length value is considered to be the empty string.
@note Even though it's technically legal to put almost anything in the
key field, you should stick to mnemonic names when extending the
protocol and just use lower case letters and underscores.
@note Keys are case sensitive. JOB_ID is *not* the same as job_id.
@subsection apis API's
Worker processes communicate with Nagios using libnagios API's
exclusively. Since you're looking at a subpage of the documentation
for that documentation right now, I'll just assume you've found it.
Although using the libnagios api's when writing a worker is
completely optional, it's highly recommended.
The key API's to use are:
@li nsock - for connecting to and communicating through the qh socket
@li kvvec - for parsing requests and building responses
@li worker - for utils and stuff nifty to have if you're a worker
@li runcmd - for spawning and reaping commands
@li squeue - for maintaining a queue of the running job's timeouts
@li iocache - for bulk-reading requests and parsing them
@li iobroker - for multiplexing between running tasks and the master
nagios process.
@note In particular, have a look at the "parse_command_kvvec()" and
"finish_job()" functions in lib/worker.c. They will do a large part
of the request/response handling for you.
@section registering Registering a worker - The handshake
Workers register with Nagios through the queryhandler, using a query
sent to the wproc handler. Since the query handler reserves the nul
byte as a magic delimiter for its messages, this one time we use the
semicolon instead, as is almost-standard in the internal-only
queryhandlers. Typically, the default worker process registers with a
query such as this:
@verbatim
@wproc register name=Core Worker $pid;pid=$pid\0
@endverbatim
Nagios will then respond with
@verbatim
OK\0
@endverbatim
followed by a stream of commands.
Nagios currently understands the following (short) list of special
keys:
@li pid - The pid of the worker process. Sometimes used to check if a
worker is online
@li name - Used to set the name of the worker
@li max_jobs - Used to tell Nagios how many concurrent jobs this
worker can handle
@li plugin - basename() or absolute path of specific plugins that this
worker wants to handle checks for.
@note plugin can be given multiple times. It is valid for a single
single worker to say "plugin=check_snmp;plugin=check_iferrors", for
example.
@note Many workers can register for the same plugin(s). They will
share the load in round-robin fashion.
Complete C-code for registering a generic worker with Nagios follows:
@code
static int nagios_core_worker(const char *path)
{
int sd, ret;
char response[128];
is_worker = 1;
set_loadctl_defaults();
sd = nsock_unix(path, NSOCK_TCP | NSOCK_CONNECT);
if (sd < 0) {
printf("Failed to connect to query socket '%s': %s: %s\n",
path, nsock_strerror(sd), strerror(errno));
return 1;
}
ret = nsock_printf_nul(sd, "@wproc register name=Core Worker %d;pid=%d", getpid(), getpid());
if (ret < 0) {
printf("Failed to register as worker.\n");
return 1;
}
ret = read(sd, response, 3);
if (ret != 3) {
printf("Failed to read response from wproc manager\n");
return 1;
}
if (memcmp(response, "OK", 3)) {
read(sd, response + 3, sizeof(response) - 4);
response[sizeof(response) - 2] = 0;
printf("Failed to register with wproc manager: %s\n", response);
return 1;
}
enter_worker(sd, start_cmd);
return 0;
}
@endcode
The "enter_worker()" part actually refers to a libnagios function that
lives in worker.c. The set_loadctl_defaults() call can be ignored.
It's primarily intended to give sane defaults about how many jobs we
can run, so we (in theory) can tell Nagios that we're swamped in case
we run out of filedescriptors or child processes.
@subsection request Requests
A complete request looks like this (with C-style format codes
replaced with actual values, ofcourse):
@verbatim
job_id=%d\0type=%d\0command=%s\0timeout=%u\0\1\0\0\0
@endverbatim
Note that values can contain equal signs, but cannot contain nul
bytes, and cannot contain the message delimiter sequence.
By including nagios/lib/worker.h and using worker_ioc2msg() followed
by worker_kvvec2buf_prealloc(), you will get a parsed key/value vector
handed to you. Have a look in base/workers.c to see how it's done for
the core workers.
@subsection responses Responses
Once the worker is done running a task, it hands over the result to
the master Nagios process and forgets it ever ran the job. The workers
take no further action, regardless of how the task went. The exception
is if the job timed out, or if the worker failed to even start the job,
in which case it should report the error to Nagios and only *then*
forget it ever got the job.
The response is identical to the request in formatting but differs in
the understood keys. The request sent from Nagios to the worker must
precede the other result variables. In particular, the job_id must be
the first variable Nagios sees for it to parse the result as a job
result rather than as something else.
The variables required for the response to a successfully executed job
on a registered worker process are as follows:
@li job_id - The job id (as received by Nagios)
@li type - The job type (as Nagios sent it)
@li start - Timeval struct for start value in $sec.$usec format
@li stop - Timeval struct for stop time in $sec.$usec format
@li runtime - Floating point value of runtime, in seconds
@li outstd - Output caught on stdout
@li outerr - Output caught on stderr
@li exited_ok - Boolean flag to denote if the job exited ok. A
non-zero return code can still be achieved
@li wait_status - Integer, as set by the wait() family of system calls
The following should only be present when the worker is unable to
execute the check due to an error, or when it cannot provide all the
variables required for a successfully executed job due to arbitrary
system errors:
@li error_msg - An error message generated by the worker process
@li error_code - The error code generated by the worker process
error_code 62 (ETIME - Timer expired) is reserved and means that the
job timed out.
@note *never* invent error codes in the range 0-10000, since we'll
want to reserve that for special cases.
The following are completely optional (for now):
@li command - The command we executed
@li timeout - The timeout Nagios requested for this job
@li ru_nsignals - The ru_nsignals field from the rusage struct
@li ru_nswap - The ru_nswap field from the rusage struct
@li ru_minflt - The ru_minflt field from the rusage struct
@li ru_majflt - The ru_majflt field from the rusage struct
@li ru_stime - The ru_stime field from the rusage struct
@li ru_utime - The ru_utime field from the rusage struct
@li ru_inblock - The ru_inblock field from the rusage struct
@li ru_oublock - The ru_oublock field from the rusage struct
The meaning of the fields of the rusage struct can be viewed in the
section 2 man-page for the getrusage() system call. Normally, you
would access it by executing the following command:
@verbatim
man 2 getrusage
@endverbatim
Note that most systems do not support all the fields of the rusage
struct and may leave them empty if so.
@section logging Logging
Worker processes can send events to the main Nagios process that
will end up in the nagios.log file. The format is the same as that in
requests and responses, but a log-message consists of a single
key/value pair, where the key is always 'log'. Consequently, a request
from a worker to the main process to log something looks like this:
@verbatim
log=A random message that will get logged to nagios.log\0
@endverbatim
It's worth noting that Nagios will prefix the message with the worker
process name, so as to make grep'ing easy when debugging experimental
workers.
@section xchgexample Protocol Exchange Example
A register + execution of one job on a worker process will, with the
standard Nagios core worker look like this, after the worker process
has connected to the query handler socket but before it has sent
anything. Note that the nul-bytes separating key/value pairs have been
replaced with newline to enhance readability. Also note that this
depicts only the required steps, which go as follows:
@verbatim
Step 1, Worker:
@wproc register name=Worker Hoopla;max_jobs=100;pid=6196\0
Step 2, Nagios:
OK\0
Step 3, Nagios:
job_id=0
type=2
timeout=60
command=/opt/plugins/check_ping -H localhost -w 40%,100.0 -c 60%,200.0
\1\0\0\0
Step 4, Worker:
job_id=0
type=2
timeout=60
start=1355231532.000123
stop=1355231532.994343
runtime=0.994120
exited_ok=1
outstd=OK: RTA: 12.6ms; PL: 0%|rta=12.6ms;100.0;200.0;0;; pl=0%;40;60
wait_status=0
outerr=
\1\0\0\0
@endverbatim
Steps 3 and 4 in this chain repeat indefinitely.
*/

32
doxy.conf Normal file
View File

@ -0,0 +1,32 @@
PROJECT_NAME = Nagios
PROJECT_NUMBER = 4.3.2
PROJECT_BRIEF = "Dev docs for Nagios core and neb-module hackers"
INPUT = lib/ docs/
FILE_PATTERNS = *.h *.dox
EXCLUDE_PATTERNS = worker.h
OUTPUT_DIRECTORY = Documentation
GENERATE_TAGFILE = Documentation/classes.tag
QUIET = YES
RECURSIVE = YES
GENERATE_LATEX = NO
GENERATE_HTML = YES
TAB_SIZE = 4
JAVADOC_AUTOBRIEF = YES
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
OPTIMIZE_OUTPUT_FOR_C = YES
STRIP_CODE_COMMENTS = NO
FULL_PATH_NAMES = NO
CASE_SENSE_NAMES = YES
ENABLE_PREPROCESSING = YES
PREDEFINED = NODOXY "NAGIOS_DEPRECATED(a, b)="
SEARCH_INCLUDES = YES
INCLUDE_GRAPH = YES
CLASS_GRAPH = YES
CLASS_DIAGRAMS = YES
COLLABORATION_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = YES
GRAPHICAL_HIERARCHY = YES

View File

@ -9,6 +9,7 @@ CFGDIR=@sysconfdir@
BINDIR=@bindir@ BINDIR=@bindir@
CGIDIR=@sbindir@ CGIDIR=@sbindir@
HTMLDIR=@datadir@ HTMLDIR=@datadir@
datarootdir=@datarootdir@
INSTALL=@INSTALL@ INSTALL=@INSTALL@
INSTALL_OPTS=@INSTALL_OPTS@ INSTALL_OPTS=@INSTALL_OPTS@
COMMAND_OPTS=@COMMAND_OPTS@ COMMAND_OPTS=@COMMAND_OPTS@
@ -16,6 +17,11 @@ COMMAND_OPTS=@COMMAND_OPTS@
CP=@CP@ CP=@CP@
all html: all html:
(cd angularjs && unzip -u angular-1.3.9.zip)
(cd angularjs && unzip -u ui-utils-0.2.1.zip)
if [ ! -d bootstrap-3.3.0 ] ; then mkdir -p bootstrap-3.3.0 && ( cd bootstrap-3.3.0 && unzip -u ../bootstrap-3.3.0-dist.zip && mv dist/* . && rmdir dist ) ; fi
mkdir -p d3
(cd d3 && unzip -u ../d3-3.5.3.zip)
clean: clean:
rm -f *.cfg *.sub core rm -f *.cfg *.sub core
@ -27,6 +33,10 @@ clean:
rm -f docs/images/*.jbf rm -f docs/images/*.jbf
rm -f stylesheets/*~ rm -f stylesheets/*~
rm -f js/*~ rm -f js/*~
rm -rf angularjs/angular-1.3.9
rm -rf angularjs/ui-utils-0.2.1
rm -rf bootstrap-3.3.0
rm -rf d3
distclean: clean distclean: clean
rm -f Makefile config.inc.php rm -f Makefile config.inc.php
@ -44,15 +54,45 @@ install:
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images/logos $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/images/logos
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/includes $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/includes
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/includes/rss
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/includes/rss/extlib
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/ssi $(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/ssi
# Directories for new CGI pages
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/angularjs
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/angularjs/angular-1.3.9
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/angularjs/ui-utils-0.2.1
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/bootstrap-3.3.0
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/bootstrap-3.3.0/css
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/d3
$(INSTALL) -m 775 $(INSTALL_OPTS) -d $(DESTDIR)$(HTMLDIR)/spin
# End of directories for new CGI pages
$(INSTALL) -m 664 $(INSTALL_OPTS) robots.txt $(DESTDIR)$(HTMLDIR) $(INSTALL) -m 664 $(INSTALL_OPTS) robots.txt $(DESTDIR)$(HTMLDIR)
# $(INSTALL) -m 664 $(INSTALL_OPTS) docs/robots.txt $(DESTDIR)$(HTMLDIR)/docs # $(INSTALL) -m 664 $(INSTALL_OPTS) docs/robots.txt $(DESTDIR)$(HTMLDIR)/docs
# Remove old HTML files (PHP files are used now) # Remove old files
rm -f $(DESTDIR)$(HTMLDIR)/index.html rm -f $(DESTDIR)$(HTMLDIR)/index.html
rm -f $(DESTDIR)$(HTMLDIR)/main.html rm -f $(DESTDIR)$(HTMLDIR)/main.html
rm -f $(DESTDIR)$(HTMLDIR)/side.html rm -f $(DESTDIR)$(HTMLDIR)/side.html
rm -f $(DESTDIR)$(HTMLDIR)/map.html
rm -f $(DESTDIR)$(HTMLDIR)/rss-*
rm -rf $(DESTDIR)$(HTMLDIR)/include/rss
$(INSTALL) -m 664 $(INSTALL_OPTS) jsonquery.html $(DESTDIR)$(HTMLDIR)
# New graphical CGI pages
$(INSTALL) -m 664 $(INSTALL_OPTS) graph-header.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) histogram.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) histogram-form.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) histogram-graph.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) histogram-links.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) infobox.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) map.php $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) map-directive.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) map-form.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) map-links.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) map-popup.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends-form.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends-graph.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends-host-yaxis.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends-links.html $(DESTDIR)$(HTMLDIR)
$(INSTALL) -m 664 $(INSTALL_OPTS) trends-service-yaxis.html $(DESTDIR)$(HTMLDIR)
# End of new graphical CGI pages
for file in *.php; \ for file in *.php; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR); done do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR); done
# for file in media/*.wav; \ # for file in media/*.wav; \
@ -79,10 +119,16 @@ install:
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/images/logos; done do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/images/logos; done
for file in includes/*.*; \ for file in includes/*.*; \
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes; done do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes; done
for file in includes/rss/*.*; \ # Support files for new graphical CGIs
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss; done $(INSTALL) -m 664 $(INSTALL_OPTS) angularjs/angular-1.3.9/angular.min.js $(DESTDIR)$(HTMLDIR)/angularjs/angular-1.3.9
for file in includes/rss/extlib/*.*; \ $(INSTALL) -m 664 $(INSTALL_OPTS) angularjs/angular-1.3.9/angular.min.js.map $(DESTDIR)$(HTMLDIR)/angularjs/angular-1.3.9
do $(INSTALL) -m 664 $(INSTALL_OPTS) $$file $(DESTDIR)$(HTMLDIR)/includes/rss/extlib; done $(INSTALL) -m 664 $(INSTALL_OPTS) angularjs/ui-bootstrap-tpls-0.12.0.min.js $(DESTDIR)$(HTMLDIR)/angularjs
$(INSTALL) -m 664 $(INSTALL_OPTS) angularjs/ui-utils-0.2.1/ui-utils.js $(DESTDIR)$(HTMLDIR)/angularjs/ui-utils-0.2.1
$(INSTALL) -m 664 $(INSTALL_OPTS) bootstrap-3.3.0/css/bootstrap.min.css $(DESTDIR)$(HTMLDIR)/bootstrap-3.3.0/css
$(INSTALL) -m 664 $(INSTALL_OPTS) bootstrap-3.3.0/css/bootstrap-theme.min.css $(DESTDIR)$(HTMLDIR)/bootstrap-3.3.0/css
$(INSTALL) -m 664 $(INSTALL_OPTS) d3/d3.min.js $(DESTDIR)$(HTMLDIR)/d3
$(INSTALL) -m 664 $(INSTALL_OPTS) spin/spin.min.js $(DESTDIR)$(HTMLDIR)/spin
# End of support files for new graphical CGIs
install-unstripped: install-unstripped:
$(MAKE) install $(MAKE) install

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More