NDO to PNP( ndoutils to PNP4Nagios)

How to use this script

The aim of this script is to import your ndo database directly into PNP4nagios. To do so, we use an exporter (ndo2pnp.pl) that can connect throught MySQL database and export contents into the same format as perfdata expected from nagios. Then we plug this into pnp4nagios using bulk option.

  $ ./ndo2pnp.pl --help   Usage :     -h  --help            Display this message.         --version         Display version then exit.     -v  --verbose         Verbose run.     -u  --user <NDOUSER>  Log on to database with <NDOUSER> (default root).     -p  --pass <PASSWD>   Use <PASSWD> to logon (default gbu2kfe).     -t  --type <DBTYPE>   Change database type (default mysql).         --host <DBHOST>   Use <DBHOST> (default localhost).         --dbname <DB>     Use <DB> for ndo database name (default ndoutils).         --list-machine    Display machine definition in ndo database.         --list-service    Show services defined.         --export-as-pnp   Export ndo content as a bulk file used by process_perfdata.pl.

Main step to import ndo database into pnp4nagios

Here‘s the main step you can follow :

  • first, check your database connectivity by listing your services :
  $ ./ndo2pnp.pl --user <MYSQL_USER> -p <MYSQL_PASS> --list-service   Hostname                       | Service   -------------------------------+-------------------   gateway                        | PING   localhost                      | Current Load   localhost                      | Current Users   localhost                      | Disk Space   localhost                      | HTTP   localhost                      | SSH   localhost                      | Total Processes
  • then, export database contents into perfdata file :
  $ ./ndo2pnp.pl --user <MYSQL_USER> -p <MYSQL_PASS> --export-as-pnp > /tmp/perfdata.bulk

Beware children ! This extraction can take a huge slice of time !

Here‘s a small extraction of this export :

  $ more /tmp/perfdata.bulk    DATATYPE::SERVICEPERFDATA       TIMET::1277405698[...]SERVICESTATE::WARNING   SERVICESTATETYPE::HARD
  • Now, use process_perfdata.pl (as nagios user) in order to import your extraction :
  [email protected]:~$ /usr/share/pnp4nagios/libexec/process_perfdata.pl -b /tmp/perfdata.bulk --timeout 0

NB1: don‘t forget the --timeout 0. If you forget this option, you‘ll get timeout while importing big chunks of services.

NB2: use the LOG_LEVEL option in the config file process_perfdata.cfg to get a feedback in the perfdata.log file.

ndo2pnp.pl

ndo2pnp.pl
#!/usr/bin/perl   use strict; use warnings; use Getopt::Long; use File::Basename;   my $version       = 0.1; my $verbose       = 0; my $show_help     = 0; my $show_machine  = 0; my $show_service  = 0; my $type          = "mysql"; my $db_name       = "ndoutils"; my $user          = "root"; my $password      = "root"; my $host          = "localhost"; my $export_as_pnp = 0;   my $service_table = "nagios_servicechecks"; my $object_table  = "nagios_objects"; my $start_time = 0; my $end_time = 0; my $filter_machine = 0; my $filter_service = 0;   sub usage {   print "Usage :   -h  --help            Display this message.       --version         Display version then exit.   -v  --verbose         Verbose run.   -u  --user <NDOUSER>  Log on to database with <NDOUSER> (default $user).   -p  --pass <PASSWD>   Use <PASSWD> to logon (default $password).   -t  --type <DBTYPE>   Change database type (default $type).       --host <DBHOST>   Use <DBHOST> (default $host).       --dbname <DB>     Use <DB> for ndo database name (default $db_name).       --list-machine    Display machine definition in ndo database.       --list-service    Show services defined.       --export-as-pnp   Export ndo content as a bulk file used by process_perfdata.pl.   "; }   GetOptions(     "version"       => \$version,     "v"             => \$verbose,     "verbose"       => \$verbose,     "h"             => \$show_help,     "help"          => \$show_help,     "u=s"           => \$user,     "user=s"        => \$user,     "username=s"    => \$user,     "p=s"           => \$password,     "pass=s"        => \$password,     "password=s"    => \$password,     "type=s"        => \$type,     "dbname=s"      => \$db_name,     "host=s"        => \$host,     "list-machine"  => \$show_machine,     "list-service"  => \$show_service,     "export-as-pnp" => \$export_as_pnp,     "machines=s"    => \$filter_machine,     "services=s"    => \$filter_service, );   if($show_help) {   usage ; exit(); }   use DBI; my $dbh = 0;   sub connect_db {   $dbh = DBI->connect("DBI:$type:$db_name;host=$host", $user, $password) || die "Could not connect to database: $DBI::errstr"; }   my $request = 0;   sub show_machine {   $request = "SELECT name1 FROM $object_table WHERE objecttype_id = 1";   my $sth = $dbh->prepare($request);   $sth->execute();   while(my @result = $sth->fetchrow_array()) {     print $result[0]."\n";   } }   sub show_service {   $request = "SELECT name1, name2 FROM $object_table WHERE objecttype_id = 2";   print STDERR "Hostname                       | Service\n";   print STDERR "-------------------------------+-------------------\n";   my $sth = $dbh->prepare($request);   $sth->execute();   while(my @result = $sth->fetchrow_array()) {     printf("%-30s | %s\n", $result[0], $result[1]);   } }   sub export_as_pnp {   my %status = (0, "OK", "1", "WARNING", 2, "CRITICAL", 3, "UNKNOWN");   my %state_type = (0, "SOFT", 1 , "HARD");   my $request_filter = "1";   if($start_time) {     $request_filter .= " AND $service_table.start_time > ‘$start_time‘ ";   }   if($end_time) {     $request_filter .= " AND $service_table.start_time <= ‘$end_time‘ ";   }   if($filter_machine) {     my @machines = split(/\s*,\s*/, $filter_machine);     $request_filter .= " AND $object_table.name1 IN (‘".join("‘,‘", @machines)."‘) ";   }   if($filter_service) {     my @services = split(/\s*,\s*/, $filter_service);     $request_filter .= " AND $object_table.name2 IN (‘".join("‘,‘", @services)."‘) ";   }   $request = "SELECT   UNIX_TIMESTAMP(start_time), name1, name2, perfdata, command_line, command_args, output, state, state_type FROM   $service_table, $object_table WHERE   $service_table.service_object_id = $object_table.object_id AND length(perfdata) > 0 AND $request_filter ORDER BY   $service_table.start_time ";   print "$request\n" if($verbose);   my $sth = $dbh->prepare($request);   $sth->execute();   while(my @r = $sth->fetchrow_array()) {     basename($r[4]) =~ /^(\w+).*/;     my $cmd = "$1";     $cmd .= ($r[5] ? "!".$r[5] : "");     print "DATATYPE::SERVICEPERFDATA\tTIMET::".$r[0]."\tHOSTNAME::".$r[1]."\tSERVICEDESC::".$r[2]."\tSERVICEPERFDATA::".$r[3].           "\tSERVICECHECKCOMMAND::$cmd\tHOSTSTATE::OK\tHOSTSTATETYPE::HARD\tSERVICESTATE::".$status{$r[7]}."\tSERVICESTATETYPE::".$state_type{$r[8]}."\n";   } }   my $format = "%s"; if($show_machine) {   connect_db();   show_machine(); } elsif($show_service) {   connect_db();   show_service(); } elsif($export_as_pnp) {   connect_db();   export_as_pnp(); } else {   print "Nothing to do\n";   exit; }

https://docs.pnp4nagios.org/pnp-0.6/ndo2pnp

时间: 2024-08-07 12:28:08

NDO to PNP( ndoutils to PNP4Nagios)的相关文章

Centos5.6下安装Nagios PNP

去官方下载最新的版本nagios-4.0.8  http://www.nagios.org/download/core [[email protected] nagios]#  tar zxvf nagios-4.0.8.tar.gz [[email protected] nagios-4.0.8]# make all [[email protected] nagios-4.0.8]#   make install [[email protected] nagios-4.0.8]#  make

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(一)介绍

以nagios为核心.伴以多款开源软件来进行的整合部署,从而实现监控信息图形化.web页面定义监控配置.监控信息存储.图形化监控主机和服务等一系列功能的解决方案. pnp4nagios是基于RRD轮循(环状)数据库中所提供的综合信息,以可视化图形的方式呈现给用户的一款nagios插件:nconf是基于PHP使用户通过web页面实现对nagios各项属性进行配置,诸如模板定义.添加修改监控的主机/服务等操作:ndoutils可以导出nagios通过SNMP捕获到的当前和历史数据并存储到MySQL数

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(三)pnp4nagios安装

官网地址:https://docs.pnp4nagios.org/ 前面的文章已经说过,pnp4nagios的Broker模式不支持nagios4x,这里采用Bulk Mode模式 1.RRDtool的安装,这里使用的是yum安装#yum install -y rrdtool* 2.pnp4nagios安装#tar -zxvf pnp4nagios-0.6.25.tar.gz#cd pnp4nagios-0.6.25#./configure --with-rrdtool=/usr/bin/rrd

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(七)nagios+cacti整合

nagios和cacti的安装请参考之前的文章安装,这里介绍二者如何整合在一起. ndoutils将nagios的监控数据写入数据库 cacti则将ndoutil插件写入数据库的数据展示在页面上,因为数据写入数据库会因为各种因素延时,所以有时候nagios自身的页面有的监控项已经告警,但是cacti页面可能还是正常状态. 所以这套方案的核心还是nagios,所有监控和故障通知都由nagios完成,cacti只是担任web管理页面. 1.修改数据库结构 mysql> use nagios; mys

Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(一)nagios安装

1.nagios安装 groupadd nagios useradd -g nagios nagios mkdir -p /usr/local/nagios/ passwd nagios tar -xvf nagios-4.0.8.tar.gz cd nagios-4.0.8 ./configure --prefix=/usr/local/nagios/ --with-command-group=nagios --with-nagios-user=nagios --with-nagios-gro

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(五)cacti安装

1.安装LAMP环境这里就不做介绍,网上一堆的相关文档,还有很多牛人写的自动化安装脚本 2.安装rrdtoolyum install cairo-devel libxml2-devel pango pango-devel rrdtool –y 3.安装SNMP操作系统一般自带SNMP,如果没有即安装 yum -y install net-snmp net-snmp-libs net-snmp-utils 4.安装Cacti (1)下载Cacti#wget http://www.cacti.net

开源监控解决方案Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(八)nconf安装

nconf提供WEB界面,管理nagios配置,其将nagios配置文件放入数据库,用户做相应修改后点击生成配置文件,Nconf会从数据库中将配置写入配置文件.所以最后nagios的配置还是以文件的形式存在,这是相对与nagioSQL本人比较喜欢Nconf的原因,其次Nconf还提供了静态文件的修改页面. 一.初始化数据库mysql> create database nconf default character set utf8;mysql> grant all privileges on

nagios结合pnp4nagios图表

安装rrdtool 网址:https://www.oetiker.ch/en/oss/projects/ cd /usr/local/src wgethttp://oss.oetiker.ch/rrdtool/pub/rrdtool.tar.gz tar -zxvf rrdtool.tar.gz cd rrdtool-1.4.9/ yum install -y pango*                #./configure依赖的包 yum install –y perl-ExtUtils-

Linux学习笔记:为Nagios 4.1.1安装出图插件pnp 0.6.25

Nagios 4.1.1的部署安装可参考http://coosh.blog.51cto.com/6334375/1741257 前言: Nagios客户端默认是没有自带出图的插件的,需要另外安装,这里介绍最常见的插件pnp.在老男孩老师的视频中,他所推荐的是0.4版本,并且建议不必选用更新的版本.虽说我同意他的观点,但本着研究学习的精神,我还是安装了最新的0.6.25,安装过程中碰到了很多问题,并一一解决了,这里做一下记录. 前期准备: 安装Nagios和部署这里不再赘述,找到http://do