• Zur Hauptnavigation springen
  • Skip to main content
  • Zur Fußzeile springen

Sebastian Mogilowski's Blog

Just another blog about administration, linux and other stuff

  • Home
  • Contact
  • Imprint
  • Projects & HOWTOs
  • Publications

Racktables has problems with NDOUtils from Nagios

11. Februar 2013 by sebastian 1 Kommentar

Small script reads nagios problems from ndo database and set has_problems flag in racktables:

Works with plain Nagios and NDOUtils Setup or an Centreon installation. But you have to use the same name of a server in both system !

#!/usr/bin/perl

use strict;
use DBI;

# NDO Database Settings
my $ndoHost = 'localhost';
my $ndoUser = 'racktables';
my $ndoPass = 'passw0rd';
my $ndoDatabase = 'ndoutils'; # Use centreon_status if you have an centreon based setup

# Racktables Database Settings
my $racktablesHost = 'localhost';
my $racktablesUser = 'rackuser';
my $racktablesPass = 'passw0rd';
my $racktablesDatabase = 'racktables';

# ----------------------------------------------------------------------------------------------------------------------------------------

my $ndoDSN = "DBI:mysql:$ndoDatabase:$ndoHost";
my $racktablesDSN = "DBI:mysql:$racktablesDatabase:$racktablesHost";

my $ndoConnection = DBI->connect($ndoDSN, $ndoUser, $ndoPass) || die "Could not connect to NDO database.";

my $racktablesConnection = DBI->connect($racktablesDSN, $racktablesUser, $racktablesPass) || die "Could not connect to Racktables database.";

# Reset all has_problems in racktables
my $query = 'UPDATE RackObject SET has_problems=0;';
$racktablesConnection->do($query) || die "Could not reset racktables problems.";

# Set all host problems to has_problems in racktables
$query = 'Select h.alias, h.display_name, s.current_state from nagios_hoststatus s inner join nagios_hosts h ON h.host_object_id = s.host_object_id WHERE s.current_state=1 OR s.current_state=2;';
my $hostStatement = $ndoConnection->prepare($query);
$hostStatement->execute();

while ( my @HostArray = $hostStatement->fetchrow_array() ) {
  $racktablesConnection->do("UPDATE RackObject SET has_problems=1 WHERE name='@HostArray[1]';")
}

# Set all hosts with service problems to has_problems in racktables
$query = 'Select h.alias, h.display_name, s.current_state from nagios_servicestatus s inner join nagios_services se ON se.service_object_id = s.service_object_id inner join nagios_hosts h ON h.host_object_id = se.host_object_id WHERE s.current_state=1 OR s.current_state=2;';
my $serviceStatement = $ndoConnection->prepare($query);
$serviceStatement->execute();

while ( my @ServiceArray = $serviceStatement->fetchrow_array() ) {
  $racktablesConnection->do("UPDATE RackObject SET has_problems=1 WHERE name='@ServiceArray[1]';")
}

# Disconnect
$ndoConnection->disconnect();
$racktablesConnection->disconnect();

Download: updateProblems.pl_.tar.gz (1025 Downloads)

Just download and unpack. You may want to create a cronjob like this one (crontab -e):

*/5 * * * * /path/to/updateProblems.pl

This cronjob executes the script every 5 minutes.

More Racktables Projects on this site.

Kategorie: Allgemein Stichworte: NDOUtils, Racktables

Leser-Interaktionen

Kommentare

  1. Hosea meint

    23. April 2013 um 09:48

    Wow! This could be one of the most beneficial blogs we have ever come across on thesubject. Basically magnificent info! I am also a specialist in this topic so I can understand your hard work.

    Antworten

Schreibe einen Kommentar Antworten abbrechen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

Footer

Kategorien

  • Allgemein
  • Coldfusion
  • Development
  • Fun
  • General
  • Home automation
  • Homematic
  • Linux
  • Mobile
  • PHP
  • Privat
  • Systemadministration
  • Virtualization
  • Windows
  • Zaurus

© 2021 · Sebastian Mogilowski's Blog · Powered by Imagely