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 :
nagios@nagioshost:~$ /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
NDO to PNP( ndoutils to PNP4Nagios)的更多相关文章
- install nagios pnp4nagios on centos 6
安装配置Apache.PHP(忽略此次安装步骤) 安装nagiosrpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release ...
- Nagios+pnp4nagios+rrdtool 安装配置nagios(一)
基于的软件版本 Apache-2.0.63 php-5.3.2 nagios-3.2.3 nagios-plugins-1.4.15 rrdtool-1.4.5 nrpe-2.12 pnp4na ...
- Nagios图像绘制插件PNP4Nagios部署和测试
注:本篇博客Nagios版本Nagios-3.5.1 1. 概述2. 关于PNP4Nagios3. 部署PNP4Nagios3.1 下载PNP4Nagios3.2 编译安装3.3 目录文件说明4. 配 ...
- Nagios数据存储插件NDOUtils部署和测试
1. 概述 NDOUTILS,Nagios Data Output Utils,Nagios数据输出工具,允许用户从Nagios导出状态和事件信息到数据库中,便于以后的检索和加工 它包括几个部分: N ...
- nagios 插件ndoutils 安装配置
nagios 插件ndoutils 安装配置 原文地址:http://www.cnblogs.com/caoguo/p/5022645.html # Nagios install ndoutils # ...
- 相机位姿估计0:基本原理之如何解PNP问题
关键词:相机位姿估计 PNP问题求解 用途:各种位姿估计 文章类型:原理 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-18 @Lab: CvLa ...
- 使用centos引导内核错误:kernel: pnp 00:0b: can't evaluate _CRS: 8
CentOS系统在开机过程中,一直遇到黑屏提示:“kernel: pnp 00:0b: can't evaluate _CRS: 8”,不理会它仍能启动系统并正常工作,未知何故. 经查,这是内核引导的 ...
- 烂泥:nagios学习(四):pnp4nagios图形化绘制nagios数据
本文由秀依林枫提供友情赞助,首发于烂泥行天下 在nagios安装完毕后,我们也添加了一些监控对象,但是你会发现nagios只是简单的给我们列出那些监控对象是正常的,而没有把这些监控对象的数据进行整合. ...
- NPN&PNP
一.晶体管基础知识 晶体管分2种:NPN.PNP 晶体管通常封装为TO-92,下面是元件实物图 和 元件符合: NPN: 当电压和电流被加到基极上时,NPN晶体管: 其工作原理: 就像水龙头—给控制开 ...
随机推荐
- Hello World 程序
1.windows 在d:/python35_study目录下创建hello.py文件,内容如下: print ('Hello World') 在cmd下执行进入d:/python35_study目录 ...
- PHP 缩放图片
class CImage { /** * 生成保持原图纵横比的缩略图,支持.png .jpg .gif * 缩略图类型统一为.png格式 * $srcFile 原图像文件名称 * $toW 缩略图宽 ...
- 用Python向MySQL数据库插入数据
最近一直在学习MySQL数据库,很感兴趣.这次我做了一个简单的尝试,使用Python3.4与MySQL数据库进行交互,将一份从雪球网上下载的某股票数据上传至MySQL数据库.仅为初学者提供参考,高手请 ...
- 【原】redis插件安装
wget -c https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz -O phpredis-2.2.4.tar.gz tar xzf ...
- Oracle分区表!
Oracle 数据库分区表的创建和操作 摘要:在大量业务数据处理的项目中,可以考虑使用分区表来提高应用系统的性能并方便数据管理,本文详细介绍了分区表的使用. 在大型的企业应用或企业级的数据库应用中,要 ...
- OpenGL学习笔记0——安装库
最近需要做一个基于Zigbee室内无线定位的系统,受到TI公司ZigBee Sensor Monitor软件的启发,打算用OpenGL来做一个3D显示空间内物体位置的程序.学习阶段选择VS2010+O ...
- UEFI+GPT引导基础篇(一):什么是GPT,什么是UEFI?
其实关于UEFI的几篇文章很早就写下了,只是自己读了一遍感觉很不满意,就决定重写.目的是想用最简单直白的语言把内容写出来,让每个人都能轻松读懂.当然,如果你已经对这些内容有了很深的理解的话,这篇文章除 ...
- AES加密算法实现
AES算法是一种对称加密算法,是美国国家标准技术研究所NIST旨在取代DES的21世纪的加密标准. 下文实例中,密钥采用了直接写死的方式,实际使用中可以配合RSA加密算法加密密钥,从而达到更好的安全效 ...
- Bootstrap3-技巧之解决Bootstrap模态框切换时页面抖动 or页面滚动条
Bootstrap为了让所有的页面(这里指内容溢出和不溢出)显示效果一样,采取的方法如下: 当Modal显示时,设置body -- overflow:hidden;margin-right:15px; ...
- hadoop 运维
1:hdfs dfsadmin -report //查看集群运行状态