Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Nagios Centreon Seminar

Nagios Centreon Seminar: architectuur, configuratie en beheer
by

Roderick Derks

on 24 October 2011

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Nagios Centreon Seminar

Nagios Directories:

/usr/local/nagios
/usr/local/nagios/etc -> config
/usr/local/nagios/libexec -> plugins!
/usr/local/nagios/var -> logfile
/usr/local/nagios/bin -> applicatie
/etc/init.d/nagios -> opstartscript
/usr/share/snmp/mibs -> snmp mib files directories o.a.: /usr/local/centreon
/usr/local/centreon/www
/usr/local/centreon/bin
/usr/local/centreon/lib
/etc/centreon
/var/lib/mysql
en meer Nagios is de engine en bevat alle logica voor:
checks, statussen, alarmeringen en escalaties
start de checks/plugins op slimme en efficiente manier
ontvangt en verwerkt info, en stuurt deze door
toont info in webinterface
configuratie door bewerken van bestanden Centreon #!/usr/bin/perl
# Author : Roderick Derks (roderick@r71.nl)
# Written for the St. Elisabeth Hospital in Tilburg, The Netherlands
# Date : September 23, 2009
# check_snmp_nortel_trunkport
#
# This program 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#################################################################
$debug = 0;


# globale variabelen:
use vars qw($opt_h $opt_H $opt_C $opt_g);
use Getopt::Std;


&getopts("h:H:C:g")||die "ERROR: Onbekende optie. -help voor help\n";
if ($opt_h) {
&print_usage;
}

sub print_usage {
print "check_snmp_nortel_trunkport -H [ IP|HOSTNAME ] -C SNMPCOMMUNITY\n";
exit $STATE_UNKNOWN;
}

$PROGNAME = "check_snmp_nortel_trunkport";
$STATE_CRITICAL = 0;
$STATE_WARNING = 0;
$STATE_UNKNOWN = 0;

$IP=$opt_H;
$COMMUNITY=$opt_C;
#$warning=$opt_w;
#$critical=$opt_c;


##### Main routines #####

&GetSwitchTypeInfo;
#exit
&ping;
&find_fiberports;
&get_trunkport_indexnumbers;
&get_trunkport_fcserrors("first");
sleep 3;
&get_trunkport_fcserrors("second");
foreach $trunkport_indexnr (@trunkport_indexnrlist) {
&compare;
}
&generate_output;



##################################################################################

sub get_trunkport_indexnumbers {

@commandoutput =`snmpbulkwalk -v2c -c $COMMUNITY $IP RC-VLAN-MIB::rcVlanPortType|grep trunk`;
if (! @commandoutput) {
print "No Trunkports configured on stack\n";
exit 3;
}


foreach $line (@commandoutput) {
#output: RC-VLAN-MIB::rcVlanPortType.48 = INTEGER: trunk(2)
chomp @commandoutput;
chomp $line;
print "trunkportlist\n @commandoutput \n\n" if ($debug >= 3);
print "trunkport\n $line \n\n" if ($debug >= 3);

$trunkport_indexnr = ((split /=/, ${line})[0] );
$trunkport_indexnr =~s/RC-VLAN-MIB::rcVlanPortType[.]//g;
print "trunkport_indexnr ${trunkport_indexnr}\n" if ($debug >= 3);
chomp $trunkport_indexnr;
chop $trunkport_indexnr;

push(@trunkport_indexnrlist, "$trunkport_indexnr");
}

print "trunkport_indexnrlist: @trunkport_indexnrlist\n" if ($debug >= 2);
foreach $trunkport (@trunkport_indexnrlist) {
print "trunkport: $trunkport\n" if ($debug >= 2);
}

}

#################################################################################

sub get_trunkport_fcserrors {

# input is 'first' or 'second', depending on the first or second time you are calling this sub
$request = "@_";

foreach $trunkport_indexnr (@trunkport_indexnrlist) {

$Table="Table_${trunkport_indexnr}"; # create tablename (per port)
#$Table="Table";

print "checking fcserrors for port $trunkport_indexnr\n" if ($debug >= 3);
$trunkport_fcserrors =`snmpbulkwalk -v2c -c $COMMUNITY $IP EtherLike-MIB::dot3StatsFCSErrors.${trunkport_indexnr}`;
chomp $trunkport_fcserrors;

# EtherLike-MIB::dot3StatsFCSErrors.48 = Counter32: 2020594
$trunkport_fcserrors = ((split /Counter32:\s+/, ${trunkport_fcserrors})[1] );
print "trunkport_fcserrors port $trunkport_indexnr $trunkport_fcserrors\n" if ($debug >= 2);

if ( $request eq "first" ) {

%${Table}=(); # create the table (per port)
%$Table = ('first' => $trunkport_fcserrors ); # add key and value to the table
}
if ( $request eq "second" ) {
$${Table}{'second'} = "${trunkport_fcserrors}"; # add key and value to the table
}
}

}

################################################################

sub compare {


# check if the trunkport_indexnr is a fiberport
if ( grep { $_ eq $trunkport_indexnr} @fiberport_array ) {

&get_switchportnumber($trunkport_indexnr);

# look into the tables and collect the info
$Table="Table_${trunkport_indexnr}";

print "$Table \n" if ($debug >= 3);
for $key ( keys %${Table} ) { $value = $$Table{$key}; print "$key => $value\n" if ($debug >= 2); }

print "first result for port $trunkport_indexnr $$Table{first}\n" if ($debug >= 2);
print "second result for port $trunkport_indexnr $$Table{second}\n" if ($debug >= 2);

$result=$$Table{first}-$$Table{second};
$PERFDATA="fcserrors_absolute_${hr_switch}-${hr_port}:=$$Table{second} ${PERFDATA}";

if ( $$Table{first} < $$Table{second} ) {
$OUTPUT = "SwitchPort $hr_switch/$hr_port: $result FCSerrors $OUTPUT";
print "OUTPUT WARNING: $result FCSerrors found for trunkport ${trunkport_indexnr} SwitchPort $hr_switch/$hr_port\n" if ($debug >= 1);
$STATE_WARNING = 1;
}
if ( $$Table{first} == $$Table{second} ) {
$OUTPUT = "SwitchPort $hr_switch/$hr_port: $result FCSerrors $OUTPUT";
print "OUTPUT ${trunkport_indexnr} ($result errors)\n" if ($debug >= 1);
$STATE = $STATE_OK;
}
}

}

########################################################################

sub get_switchportnumber {

#input needed is hte indexnumber of the port
${trunkport_indexnr2} = "@_";

print "zoeken naar switch en poortnummer\n" if ($debug >= 3);
print "found $trunkport_indexnr in array fiberport_array\n" if ($debug >= 3);

#get human readable switch/portnumber
#RFC1213-MIB::ifDescr.
#RFC1213-MIB::ifDescr.240 = STRING: "Nortel Ethernet Routing Switch 5520-48T-PWR Module - Unit 4 Port 48 "


$hr_switchport_nr =`snmpbulkwalk -v2c -c $COMMUNITY $IP RFC1213-MIB::ifDescr.${trunkport_indexnr2}`;
chomp $hr_switchport_nr;
print "\noutput snmpbulk commando $hr_switchport_nr\n" if ($debug >= 3);

#Different switchtypes have different output
#type 450/470: RFC1213-MIB::ifDescr.121 = STRING: "BayStack - module 4, port 25"
#type 5510/5520: "Nortel Ethernet Routing Switch 5510-48T Module - Unit 1 Port 48 "
if ( ${StackTypeNumber} =~ "450" || ${StackTypeNumber} =~ "470" ) {
print "found BayStack\n" if ($debug >= 3);
$hr_switch = ((split /module /, ${hr_switchport_nr})[1] );
$hr_switch = ((split /,/, ${hr_switch})[0]);
$hr_port = ((split /port /, ${hr_switchport_nr})[1] );
$hr_port =~s/"//g;
}
else {
$hr_switch = ((split /Unit /, ${hr_switchport_nr})[1] );
$hr_switch = ((split / Port/, ${hr_switch})[0]);
$hr_port = ((split /Port /, ${hr_switchport_nr})[1] );
$hr_port =~s/\s+"$//g;
}
if ( $hr_port =~ "GBIC" ) { # old 450 stacks give extra output, delete it: (GBIC)
$hr_port = ((split / \(GBIC/, ${hr_port})[0] );
}
if (! $hr_switch) {
print "\nstack contains just one switch, need to repair output for variable \$hr_switch\n" if ($debug >= 3);
$hr_switch = 1;
print "\hr_switch is now: $hr_switch\n" if ($debug >= 3);
}
print "resultaat: switch $hr_switch port ${hr_port}\n\n" if ($debug >= 1);


}

####################################################################################

sub generate_output {

if ( $STATE_WARNING ) {
print "WARNING: $OUTPUT|$PERFDATA\n";
exit 1;
}
else {
print "OK: $OUTPUT|$PERFDATA\n";
exit 0;
}

exit $STATE;
}

##################################################################################

sub ping {

$command = "ping -c 1 $IP 2>&1 1>/dev/null ";

$ping = system($command);
if ($ping) {
exit 2;
}

}

####################################################################################

sub find_fiberports {

@fiberport_array=();

#RC-PORT-MIB::rcPortType
@porttypelist =`snmpbulkwalk -v2c -c $COMMUNITY $IP RC-PORT-MIB::rcPortType`;
#print "array containing porttypelist @porttypelist\n" if ($debug >= 3);

foreach $fiberport_indexnr ( @porttypelist ) {
chomp $fiberport_indexnr;

# zoeken op output: RC-PORT-MIB::rcPortType.25 = INTEGER: rc1000BaseF(4) (F van Fiber, anders TX(1))
# RC-PORT-MIB::rcPortType.24 = INTEGER: rcGbicSx(11)
if ( $fiberport_indexnr =~ "Gbic" || $fiberport_indexnr =~ "rc1000BaseF") {
$fiberport_indexnr = ((split / =/, ${fiberport_indexnr})[0] );
$fiberport_indexnr = ((split /RC-PORT-MIB::rcPortType./, ${fiberport_indexnr})[1] );
print "found indexnr for port with fibercable: $fiberport_indexnr\n" if ($debug >= 3);
push(@{fiberport_array}, "$fiberport_indexnr");
}

}
print "fiberport_array @fiberport_array\n" if ($debug >= 2);
}

###########################################################################################################################

sub GetSwitchTypeInfo {

$fakemibfile="/usr/share/snmp/mibs/SNMPv2-SMI.mib"; # to prevent snmp commands using the MIBS ALL setting which preolads MIB files

open(OUTPUT, "snmpbulkwalk -m ${fakemibfile} -v2c -c ${COMMUNITY} ${IP} SNMPv2-MIB::sysDescr.0|");
@OUTPUT = <OUTPUT>;
close(OUTPUT);

print "command: snmpbulkwalk -m ${fakemibfile} -v2c -c ${COMMUNITY} ${IP} SNMPv2-MIB::sysDescr.0\n" if ($debug >= 3);
$Stacktype="@OUTPUT";
chomp $Stacktype;
print "searching for Stacktype and number\n" if ($debug >= 3);
print "command: snmpbulkwalk -v2c -c ${COMMUNITY} ${IP} SNMPv2-MIB::sysDescr.0\n" if ($debug >= 3);
print "Stacktype $Stacktype\n" if ($debug >= 3);
$Stacktype = ((split /STRING: /, ${Stacktype})[1]);
print "Stacktype $Stacktype\n" if ($debug >= 3);

if ( $Stacktype =~ /BayStack/ ) {
$Stacktype = ((split /BayStack /, ${Stacktype})[1]);
print "BayStack Stacktype $Stacktype\n" if ($debug >= 3);
}
else {
$Stacktype = ((split /Switch /, ${Stacktype})[1]);
print "Stacktype $Stacktype\n" if ($debug >= 3);
}
$Stacktype = ((split / /, ${Stacktype})[0]);
print "Stacktype $Stacktype\n" if ($debug >= 3);

my @Stacktype_char = split /-/, $Stacktype;

$StackTypeNumber = "${Stacktype_char[0]}";
$NrPortsOnSwitch = ((split /T/, ${Stacktype_char[1]})[0]);

chomp $NrPortsOnSwitch; chomp $StackTypeNumber;

print "Stacktypenumber: ${StackTypeNumber}\n" if ($debug >= 2);
print "nr of ports: ${NrPortsOnSwitch}\n" if ($debug >= 2);

} Waarom Centreon?
professionele en intuitieve webinterface, Ajax powered
webbased Nagios configuratie aanmaken
database
genereren van grafieken om trends te ontdekken
beschikbaarheidsrapportages
user access control en rollen (view, user, admin, etc) Centreon grafieken:
rrdtools -> rrd files
info grafieken uit database
regeneren grafieken mogelijk! NDO utils Verzenden nagios data naar database
Via TCP-IP op local port
Draait als daemon NDO2DB
Resultaat samenwerking OS community
http://en.doc.centreon.com/Setup:ndoutils2 Architectuur Drie databases:
ndo
centstorage (data)
centreon (config) NAGIOS CENTREON Seminar 01. Nagios
02. Centreon
03. NDO utils
04. Architectuur
05. CCT's Roderick Derks, april 2010 Scripts / plugins Voorbeeld op Linux commandline van verzamelen info uit een apparaat via SNMP

-bash-3.2# snmpbulkwalk -v2c -c ********** ser-f2.elisabeth.nl RC-VLAN-MIB::rcVlanPortType|grep trunk
RC-VLAN-MIB::rcVlanPortType.48 = INTEGER: trunk(2)
RC-VLAN-MIB::rcVlanPortType.176 = INTEGER: trunk(2) Toepassen in script:

@commandoutput =`snmpbulkwalk -v2c -c $COMMUNITY $IP RC-VLAN-MIB::rcVlanPortType|grep trunk`;
if (! @commandoutput) {
print "No Trunkports configured on stack\n";
exit 3;
} Output scripts gestandaardiseerd en ziet er zo uit:

-bash-3.2# ./check_snmp_nortel_trunkport -H ser-f2.elisabeth.nl -C ********
OK: SwitchPort 1/48: 0 FCSerrors |fcserrors_absolute_1-48:=100186

returnvalue script:
-bash-3.2# echo $?
0 CCT's
Centreon Configuratie Tips MySQL Database Tips 1. In Administration > Options > Centstorage
Verander Retention Duration voor Data in MySQL naar 182 dagen in Centreon.

2. In Administration > Options > Centstorage
Uncheck box zodat je ongelimiteerde groei voorkomt van de /usr/local/nagios/var/service-perfdata.tmp file.

3. Leeg de NDO database (behalve tables nagios_acknowledgements, nagios_commenthistory, nagios_comments, nagios_downtimehistory, nagios_instances) There are two ways to delete all the data in a MySQL database table.

TRUNCATE TABLE tablename; This will delete all data in the table very quickly. In MySQL the table is actually dropped and recreated, hence the speed of the query. The number of deleted rows for MyISAM tables returned is zero; for INNODB it returns the actual number deleted.
DELETE FROM tablename; This also deletes all the data in the table, but is not as quick as using the "TRUNCATE TABLE" method. In MySQL >= 4.0 the number of rows deleted is returned; in MySQL 3.23 the number returned is always zero. Gebruik tuning-primer.sh script voor controleren mysqld performance en volg adviezen
http://day32.com/MySQL/tuning-primer.sh

-bash-3.2# vi /etc/my.cnf
key_buffer_size=500M
table_cache=1024
query_cache_size=32M

-bash-3.2# service mysqld restart Database Growth Control Empty Rows in A Table Database performance Backup 1. VMware/Veritas
2. Appl & Data dmv script
- MySQL
- Files Restore - VM: Veritas
- Applicatie: files terugzetten
- Data: MySQL commando's -bash-3.2# /root/centreon/backup_centreon_db.sh
BACKUP_DIR /root/centreon/backup
Backing up the ndo database..
Backing up the centreon database..
Backing up the centstorage database..

-bash-3.2# ls -al /root/centreon/backup
total 559188
drwxr-xr-x 2 root root 4096 2010-03-26 12:31 .
drwxr-xr-x 3 root root 4096 2010-03-26 12:30 ..
-rw-r--r-- 1 root root 82061 2010-03-26 12:31 20100326123026.centreon.sql.gz
-rw-r--r-- 1 root root 501073196 2010-03-26 12:38 20100326123026.centstorage.sql.gz
-rw-r--r-- 1 root root 70864051 2010-03-26 12:31 20100326123026.ndo.sql.gz

-bash-3.2# /root/nagios/backup_nagios_config.sh full
Backing up the Nagios configuration files and plugins
tar: Removing leading `/' from member names
problem detected creating the tar file /root/nagios/backup/20100326133246_fullbackup_nagios_ezh_site.tar.gz

Hurray, we created a perfect fullbackup!
File:
-rw-r--r-- 1 root root 45022457 2010-03-26 13:33 /root/nagios/backup/20100326133246_fullbackup_nagios_ezh_site.tar.gz -bash-3.2# gunzip -v /root/centreon/backup/20100326123026.centreon.sql.gz
/root/centreon/backup/20100326123026.centreon.sql.gz: 84.3% -- replaced with /root/centreon/backup/20100326123026.centreon.sql

-bash-3.2# mysql -u root -p centreon < /root/centreon/backup/20100326123026.centreon.sql -bash-3.2# cat /usr/local/nagios/etc/ezhappl01.cfg

define host{
use 5x10-host ; Inherit default values from a template
host_name ezhappl01 ; The name we're giving to this host
alias ezhappl01 ; A longer name associated with the host
address ezhappl01.elisabeth.nl ; IP address of the host
hostgroups w2003,w_d_drive,allhosts,5x10-hosts ; Host groups this server is associated with
}

define hostextinfo{
host_name ezhappl01
icon_image windows.gif
icon_image_alt microsoft
}
-------------------
-bash-3.2# cat /usr/local/nagios/services.cfg

define service {
host_name ezhcom01
service_description adt-astraia_adt
_SERVICE_ID 141
use passive-service
check_command check_dummy
check_period 7x24
contact_groups admins
} Drie methodes om Nagios te voeden met informatie:
1= lokaal op Nagios host script starten
bv via SNMP
Voordeel: SNMP daemon inschakelen op Host is simpel; verder niets nodig
Nadeel: minder snel; SNMP is niet simpel

2= "listener" op Nagios -> NSCA executable/binary op host:
Initiatief komt vanaf de te monitoren host
Cloverleaf alert scripts zenden gegevens naar Nagios
Windows scheduler start VB script

3= extern script starten middels NRPE plugin of NS+client
Initiatief ligt bij Nagios
NRPE binary installeren op Nagios server, NRPE daemon op Linux host
Tegenhanger NRPE = check_by_ssh plugin
NS+Client installeren op Windows hosts (service) Mo = Mega octet = Mb ................................... ................... ............................ ..................... ................................. 1 2 3 4 6 5 3. Howto Add A Service 2. Howto edit a command 1. How to add a host 4. ACL - rechten in Centreon 06. MySQL tips
07. Backup/Restore
08. Update/Upgrade
09. Video's en Doc's
10. Vragen? Video's en Doc's .......................................... Thank You! Performanceproblemen Centreon server?
VMotion! Doc's Video's Uitgebreide installatiehandleiding Nagios en Centreon, inclusief alle benodigde RPM packages
Configuratiehandleiding
http://sharepoint.elisabeth.nl/ICTBeheer/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2fICTBeheer%2fShared%20Documents%2fSystemen%2fNagios%20%2d%20Centreon&View=%7b2C9CF29C%2d0CE9%2d45E6%2d850B%2dD1CB34F37262%7d 9 Update en Upgrade Testomgeving: http://10.20.2.27/centreon/ -bash-3.2# tar xvzf centreon-2.1.5.tar.gz
-bash-3.2# cd centreon-2.1.5
-bash-3.2# ./install.sh -u /etc/centreon/

Do you want to use the last Centreon install parameters ?
[y/n], default to [y]:
> y

Using: /etc/centreon/instCentCore.conf
/etc/centreon/instCentPlugins.conf
/etc/centreon/instCentStorage.conf
/etc/centreon/instCentWeb.conf

Do you want to install : Centreon Web Front
[y/n], default to [n]:
> y

Do you want to install : Centreon CentCore
[y/n], default to [n]:
> y

Do you want to install : Centreon Nagios Plugins
[y/n], default to [n]:
> n

Do you want to install : Centreon Snmp Traps process
[y/n], default to [n]:
> n

----------
SUDO
----------
Do you want me to reconfigure your sudo ? (WARNING)
[y/n], default to [n]:
> n
-----------------------------------------------------
Configure Apache server
-----------------------------------------------------
Create '/etc/httpd/conf.d/centreon.conf' OK
Configuring Apache OK

Do you want to reload your Apache ?
[y/n], default to [n]:
> n

--------------
Centreon
--------------
Do you want me to install CentStorage init script ?
[y/n], default to [n]:
> n -bash-3.2# cd /tmp
-bash-3.2# rm -Rf centreon-2.1.5* 1. huidige versie 2.1.4 2. Download nieuwe versie van www.centreon.com Centreon upgrade 3. Upload tar file naar server 4. tar file uitpakken en install script starten 5. Update database schema via webui 6. EZH logo terugzetten -bash-3.2# cd /usr/local/centreon/www/img/
-bash-3.2# cp centreon.gif.ezh centreon.gif 7. Tar file en uitgepakte bestanden opruimen 8 7 Nagios upgrade 1. Download nieuwe versie Nagios Core van www.nagios.org -bash-3.2# tar xvzf nagios-3.2.0.tar.gz
-bash-3.2# cd nagios-3.2.1
-bash-3.2# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
-bash-3.2# make all
-bash-3.2# make install
-bash-3.2# make install-init
-bash-3.2# chkconfig --add nagios
-bash-3.2# service nagios status
-bash-3.2# cd /usr/local/nagios/
-bash-3.2# chown -R nagios:nagios etc/
-bash-3.2# ln -s /usr/local/nagios/etc/apache/nagios.conf /etc/httpd/conf.d/nagios.conf
-bash-3.2# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 2. Compileer en installeer Do Not! Nagios en Centreon leveren allebei standaard plugins om systemen mee te monitoren. Voor Nagios is dit een aparte download, Centreon vraagt of je wilt installeren tijdens het install script.

Bij de inititiele installatie is dat handig. Veel van deze standaard plugins zijn inmiddels aangepast vanwege gewenste functionaliteitsuitbreidingen, output aanpassingen en kleine bugs.

Daarom geldt voor de upgrades van Nagios en Centreon: installeer niet de standaard plugins opnieuw want daarmee overschrijf je de aangepaste plugins. Als gevolg zullen checks niet meer werken en/of grafieken niet meer worden bijgewerkt. Geen Standaardplugins mee installeren ........... ........ Centreon eventlog:
bekijken geschiedenis op detailniveau Centreon Reporting
Beschikbaarheidsrapportages
Events te zien op de tijdbalk Regenereren grafieken na aanpassing instellingen (tijdsinterval van een service)
Verwijderen data grafieken (na verwijderen host) Voorbeeld configuratiefiles Plugin architectuur Delete of Disable de Host en NIET de Service
Aanmaken nieuwe Host: maak kopie of gebruik anders Host of Service templates
Users aanmaken: ook in Nagios rechten geven!
Nieuwe host? Denk aan relations!
Nieuwe plugin? Maak commando, dan service, dan koppelen aan host (zie video's en http://ezhappl21.elisabeth.nl/centreon/main.php?p=608)
Grote storing: zet sms uit
Grafieken opnieuw genereren
Performance probleem? Uitzetten notifications Home > Nagios Statistics > Process Info ezhappl21 ezhappl.... ::
:: Roderick Derks r.derks@elisabeth.nl roderick@r71.nl
::
:: Datum 1e oplevering 23-07-2009
::
:: Controleren of in Veritas Netbackup een DSSU policy langer dan 86400sec (1 dag) draait.
:: Resultaat wordt via nsca.exe naar Nagios gestuurd.
::
:: v1.0 20090722
:: v1.1 20090724
:: v1.2 20090727 juiste output bij meerdere draaiende DSSU policies (resultaat was OK als de "probleem policy" zich niet als laatste in de lijst bevindt)
:: v1.3 20090728 jobnummer van te lang draaiende DSSU wordt in output meegenomen. Bij meerdere te lang draaiende alleen het eerste jobnr.
:: v1.4 20090728 Goed nieuws werd niet verzonden, aangepast.
:: v1.5 20090729 Aantal uren dat de ploicy draait verwerkt in de output naar Nagios
::

echo off
cls


REM EXAMPLE COMMANDLINE INPUT FOR THIS SCRIPT
REM C:\Documents and Settings\adminrrderks>bpdbjobs -gdm|find "DSSU"|find "000000,,"
REM 257920,0,1,,__DSSU_POLICY_BACKUP02_H2200,-,ezhbackup02,ezhbackup01,1248291849,0000001059,0000000000,,1,34,0,ezhbackup01,,,0257476,0,1,,__DSSU_POLICY_BACKUP01_F2100,-,ezhbackup01,ezhbackup01,1248249218,0000043690,0000000000,,0,34,0,ezhbackup01,,,0
rem For /f "tokens=10 delims=, " %%i in ('Find "field" %logfile%') Do (if %%i gtr 10 set errors=1)

set tempfile="D:\tempfile_command_output.txt"
set errors=0
set errorvalue=0
set sent=0

:: opvragen status jobs vanuit veritas netbackup, filteren
bpdbjobs -gdm|find "DSSU"|find "000000,," > %tempfile%

::checken of tempfile data bevat
REM for %%a in (%tempfile%) do if %%~za EQU 0 @echo Empty file
for %%a in (%tempfile%) do if %%~za GTR 0 @goto DSSU_FOUND


:NO_DSSU
set seconds=0
GOTO DSSU_FOUND

:DSSU_FOUND
REM file uitlezen en regel voor regel verwerken. Jobnr filteren en daarna tijdsduur lopende job controleren
For /f "tokens=1 delims=," %%i in ('Find "DSSU" %tempfile%') Do (set jobnr=%%i)
For /f "tokens=9 delims=," %%i in ('Find "DSSU" %tempfile%') Do call :check_output "%%i"

:check_output
set "seconds=%~1"


:: laatste regel command output is leeg, toch iets met deze variabele doen
if (%seconds%)==() set seconds=0



:: als %second% iets bevat als 0000086400 dan voorloopnullen weghalen
if %seconds% NEQ 0 (
for /f "tokens=* delims=0" %%a in ('echo %seconds%') do set seconds_after=%%a
set /a minuten=%seconds_after%/60
set /a uren=%minuten%/60
)

if %errorvalue% NEQ 1 (

if %seconds% LSS 86400 set message=geen DSSU policy job die langer dan 24u draait
if %seconds% LSS 86400 set errorvalue=0
if %seconds% GEQ 86400 set message=DSSU policy draait langer dan 24 uur namelijk %uren% uur, actie nodig. Jobnr %jobnr%
if %seconds% GEQ 86400 set errorvalue=1

)

REM echo seconds: %seconds%
REM echo errorvalue %errorvalue%
REM echo %message%


:FINISH
REM del %tempfile%

REM als niet verzonden dan altijd verzenden (goed nieuws moet ook aankomen)
if %sent%==0 (
echo ezhbackup01 netbackup-dssu %errorvalue% %message% | D:\ezh_scripts\nsca\send_nsca.exe -H nagios -d " " -c D:\ezh_scripts\nsca\send_nsca.cfg
set sent=1
)

REM als verzonden dan alleen nog verzenden in geval van foutmelding
if %sent%==1 (
if %errorvalue%==1 (
echo ezhbackup01 netbackup-dssu %errorvalue% %message% | D:\ezh_scripts\nsca\send_nsca.exe -H nagios -d " " -c D:\ezh_scripts\nsca\send_nsca.cfg
REM niet meer verzenden:
set sent=2
)
) system "echo $HOSTNAME_WITHOUT_DOMAINNAME ${SITE}-${TNAME} $errorvalue \"$CLV_MSG\" |
${EZH_SCRIPTS_BIN}/send_nsca -H ${NAGIOSSERVER_01} -d \" \" -c ${EZH_SCRIPTS_ETC}/send_nsca.cfg"; Cloverleaf alert script extract MSDOS Veritas Scratchpool
Full transcript