Showing posts with label nagios. Show all posts
Showing posts with label nagios. Show all posts

Wednesday, February 27, 2013

Nagios MS SQL Server Plugin

I recently attempted to use the  check_mssql_database.py plugin. It doesn't give much feedback for errors. I was typically seeing something like this while attempting to connect to SQL Server 2005 from a Nagios Xi installation:

CRITICAL:Unable to access SQL Server.
I did some research, including looking at the Python script. After looking into the DB connection method, I discovered that I had to configure the freetds.conf file (in /etc, in my case.)

I added a stanza like this (you might need a more exotic configuration or configurations):

[MYSERVERNAME]
     host = myservers_IP_ADDRESS
     port = my_port_number 
     tds version = 7.0


After doing this, I was able to connect (not all the checks return sane values, but that's a problem for a different day.) My connection string goes like so:
check_mssql_server.py -H 'hostname_or_IP'    --warning 20 --critical 30 -U 'MYDOMAIN\username' -P 'MYPASSWORD' --deadlocks

You can specify instance with -I, but I was using the default instance of 'MSSQLSERVER'


The plugin's install document is here:
Install doc

Edit: it would appear that most of the tests are not going to be useful. Quite a few of them return nonsensical, large values and other return the same value consistently, no matter what the conditions on the server.

Also, Nagios Xi does something funny where it auto escapes the \ in the domain\username combo. The plugin ends up running DOMAINNAME\\username (which it can't handle.) I tried removing the quotes and several other things.

I ended up finally modifying the plugin to add my domain name to the user name and then I used the short username in Nagios Xi without the domain preface. If I knew Python better, I would have had it strip off the extra \ - but I had to get it working quickly. I might go back and make that change later.

 To be honest, I'm not very familiar with Nagios Xi - having used the original Nagios since 2002 or so, so it could be something I'm overlooking. 

Sunday, August 28, 2011

Nagios Group Service Checks and Exclusions

Using hostgroup_name in service checks is very, very useful. However, I find that I often want to include the Nagios server in one of the hostgroups, but don't necessarily want to configure nrpe for the nagios host. An easy way around this is to use Nagios's exclude feature. You can exclude a group (or host) by prefacing it with "!"

For instance:

1. create a group that contains only your nagios host

define hostgroup {
        hostgroup_name localhost-monitor-hosts
        members         mynagiosserver
}


2. create the service:

define service {
        hostgroup_name          unix-hosts,!localhost-monitor-hosts
        use                             critical-service
        service_description             check_disk
        check_command                   check_nrpe!check_disk!80!85
        check_freshness                 1
        register                        1
        }

This will check all hosts in the unix-hosts group, excluding any in localhost-monitor-hosts. You can obviously create multiple groups, each with a different purpose.

Note, you can also define a service with more than one host, and exclude hosts that way:

define service {
         host_name www1, www2, !www3
         use generic-service
         service_description check_ping
         check_command check_ping!100.0,20%!500.0,60%
}

but I find that more taxing, as you have to maintain the host_name... which is kind ignoring the whole point of groups.




Tuesday, January 5, 2010

Nagios, Passive Service and Host Checks

I recently had to set up a remote nagios installation that would connect back to a central server via NSCA. I followed the standard Nagios documentation for distributed monitoring here. The passive service checks worked fine.


The problem was that I wanted passive checks for hosts, too, and not just services, as the central server would not be able to ping the remote hosts directly in the event that the data is considered stale. I set up all the checks on the central server side to be the service-is-stale check - so any staleness results in an alert, "the check data is stale." Unfortunately, the nagios documentation is a little vague about the ohcp command (the final paragraph on the nagios link above.) I couldn't find any real answer on passive host checks on the web, either.




Here's what I did on the remote side (and not the central collector server.) I copied the submit_check_result script in the documentation, modified it, and saved it as /etc/nagios/bin/submit_host_result. The final version:

# Arguments:
# $1 = host_name (Short name of host that the service is
# associated with)
# $2 = host check output (0, 1, 2, etc.)
# $3 = plugin_output (A text string that should be used
# as the plugin output for the service checks)
#
# Convert the state string to the corresponding return code
central_server=ip.address.or.hostname.of.your.central.nsca.server

/usr/bin/printf "%s\t%s\t%s\n" "$1" "$2" "$3" | /usr/sbin/send_nsca -H $central_server -c /etc/nagios/send_nsca.cfg


I then added the following entry to the command definition file:

define command{
command_name submit_host_result
command_line /etc/nagios/bin/submit_host_result $HOSTNAME$ $HOSTSTATEID$ '$HOSTOUTPUT$'


}

I then modified the nagios.cfg file like so:

obsess_over_hosts=1
# OBSESSIVE COMPULSIVE HOST PROCESSOR COMMAND
# This is the command that is run for every host check that is
# processed by Nagios. This command is executed only if the
# obsess_over_hosts option (above) is set to 1. The command
# argument is the short name of a command definition that you
# define in your host configuration file. Read the HTML docs for
# more information on implementing distributed monitoring.
ochp_command=submit_host_result

Of course, it took a bit of work to figure that out. So, the end result is that both service and host checks are passive on the central server. You might want to make the remote server the parent of all the other remote servers as if it's down, inaccessible, there's no way you'll receive check data for the other hosts, and you'll probably get some unnecessary alerts. I'm sure I'll see some more issues, and will likely post again on this issue.

Monday, July 6, 2009

1-Wire Temperature Sensors...

I recently bought a 1-Wire serial interface (Link45) and two T-sensors from iButtonlink as well as a power injector and power adapter. The power adapter was back-ordered, but arrived today. Using a USB serial adapter and Digitemp, I get results like:

user@testmachine$ sudo digitemp_DS9097U -s /dev/ttyUSB0 -a
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Jul 06 22:26:20 Sensor 0 C: 22.81 F: 73.06
Jul 06 22:26:21 Sensor 1 C: 22.56 F: 72.61

One of the nice things is that you can add more sensors and also things like humidity sensors.

It's pretty useful. I discovered that someone had written a little plugin/wrapper for Nagios here.

Tuesday, May 12, 2009

Nagios, FreeBSD, and Lilac

In the earlier post, I talked about setting up nconf on FreeBSD. I decided to give Fruity/Lilac a try. It's been around longer, anyway, and it supports imports of existing configs. It also can use nmap to generate a basic configuration.

Anyway, the rough steps are:

1. install mysql50-server

2. install apache22

3. install php5

4. install php5-extensions with the following modules enabled:

json, pcntl, posix, mysql, curl

5. install php5-pdo_mysql

6. install nmap

7. untar the lilac source to /usr/local/www/apache22/data/lilac

8. sudo chown www:www /usr/local/www/apache22/data/lilac/includes

9. restart apache.

Note: in order to get apache to work with php, I created a php config file in /usr/local/etc/apache22/Includes/php.conf:

DirectoryIndex index.php index.html index.htm
AddType application/x-httpd-php .php .htm .html
AddType application/x-httpd-php-source .phps

Thursday, May 7, 2009

Nagios, FreeBSD, and nconf

I just noticed nconf on the Nagios.org site the other day. Another GUI for configuration. Anyway, I was building a new VM for use by our consultants to run nagios, RT, and cacti, and I figured I would give it a shot.

Nconf is yet another web frontend for the configuration of Nagios. It seems to work okay. It's PHP based. It's not in the ports tree, but then again, it hasn't been around very long. Here's what I did to install it:

1. install nagios, apache, php5, php5-extensions, mysql (It can't use PostgreSQL at this point) etc.

2. Create an appropriate php5.ini in /usr/local/etc and make sure it contains at least:

short_open_tag = On
register_globals = Off
magic_quotes_gpc = Off

3. untar nconf into /usr/local/www/apache22/data/nconf

4. cd to that dir

chown www config output temp

5. sudo mysql (-p if you have a root password set at this point, if not it's a good idea)

CREATE DATABASE nconf;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP on nconf.* to 'nconf_user'@'localhost' identified by 'difficult_password';
flush privileges;


6. add www to nagios group

7. restart apache (I also had to add:

AddType application/x-httpd-php .php .htm .html
AddType application/x-httpd-php-source .phps

to /usr/local/etc/apache22/httpd.conf)

8. Browse to http://your-host-ip-or-name/nconf and go through the setup (set the path to nagios to be /usr/local/bin/nagios)

9. remove INSTALL.php and the INSTALL directory in nconf

10. Download the default imagepak-base.tar.tar from here.)

11. rename the image pack to imagepak-base.tar.gz

12. cd /usr/local/www/nagios/images/logos
sudo gunzip /path/to/the/imagepak.tar.gz
sudo tar -xf /path/to/the/imagepak.tar

The base install is done.

It will generate a tarball with the configs in /usr/local/www/apache22/data/nconf/output. You'll need to untar it into /usr/local/etc/nagios and configure nagios.conf to parse the directories for configs.

I hope the project lasts. There have certainly been a lot of webguis for Nagios that have died. Hopefully, they will add the ability to import existing configs at some point.