icinga2集成pnp4nagios

alt

PNP4nagios

cp -r modules/* /usr/share/icingaweb2/modules/
ln -s /usr/local/pnp4nagios/etc/* /etc/pnp4nagios/
#vim /etc/pnp4nagios/npcd.cfg

user = icinga
group = icinga
log_type = file
log_file = /usr/local/pnp4nagios/var/npcd.log
max_logfile_size = 10485760
log_level = 0 #debug时打开
perfdata_file_run_cmd = /usr/local/pnp4nagios/libexec/process_perfdata.pl
perfdata_file_run_cmd_args = --bulk
identify_npcd = 1
npcd_max_threads = 5
sleep_time = 15
load_threshold = 0.0
pid_file=/var/run/npcd.pid
perfdata_file = /usr/local/pnp4nagios/var/perfdata.dump
perfdata_spool_dir = /var/spool/icinga2/perfdata
perfdata_spool_filename = perfdata
perfdata_file_processing_interval = 15

#vim /etc/pnp4nagios/process_perfdata.cfg

TIMEOUT = 15
USE_RRDs = 1
RRDPATH = /usr/local/pnp4nagios/var/perfdata
RRDTOOL = /usr/bin/rrdtool
CFG_DIR = /usr/local/pnp4nagios/etc
RRD_STORAGE_TYPE = SINGLE
RRD_HEARTBEAT = 8460
RRA_CFG = /usr/local/pnp4nagios/etc/rra.cfg
RRA_STEP = 60
LOG_FILE = /usr/local/pnp4nagios/var/perfdata.log
LOG_LEVEL = 0 #debug时打开
XML_ENC = UTF-8
XML_UPDATE_DELAY = 0
RRD_DAEMON_OPTS =
STATS_DIR = /usr/local/pnp4nagios/var/stats
PREFORK = 1
GEARMAN_HOST = localhost:4730
REQUESTS_PER_CHILD = 10000
ENCRYPTION = 1
KEY = should_be_changed
```
`#vim /etc/icinga2/features-enabled/perfdata.conf`

library “perfdata”
object PerfdataWriter “perfdata” {
service_format_template = “DATATYPE::SERVICEPERFDATA\tTIMET::$icinga.timet$\tHOSTNAME::$host.name$\tSERVICEDESC::$service.name$\tSERVICEPERFDATA::$service.
perfdata$\tSERVICECHECKCOMMAND::$service.check_command$$pnp_check_arg1$\tHOSTSTATE::$host.state$\tHOSTSTATETYPE::$host.state_type$\tSERVICESTATE::$service.
state$\tSERVICESTATETYPE::$service.state_type$”
}

`# vim /etc/icinga2/conf.d/templates.conf`

template Service “pnp-svc” {
action_url = “/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$”
vars.pnp_check_arg1 = “”
}

`#vim /etc/icinga2/conf.d/services.conf`

apply Service “nrpe_traffic” {
import “generic-service”
import “pnp-svc”
check_command = “nrpe”
assign where host.name == “kddi-pxe”
assign where host.name == “kddi-deploy”
vars.nrpe_timeout = 240
vars.nrpe_command = “check_traffic”
vars.pnp_check_arg1 = “!$nrpe_command$”
}

`#vim /usr/local/pnp4nagios/etc/check_commands/nrpe.cfg`

CUSTOM_TEMPLATE = 0,1
DATATYPE = GAUGE
USE_MAX_ON_CREATE = 0

`#vim /usr/local/pnp4nagios/var/perfdata/kddi-deploy/nrpe_traffic.xml`
看这个值
`<TEMPLATE>nrpe_check_traffic</TEMPLATE>`
然后根据xml中的名字创建模板
`#vim /usr/local/pnp4nagios/share/templates/nrpe_check_traffic.php`

<?php
#

Copyright (c) 2006-2010 Joerg Linge (http://www.pnp4nagios.org)

Plugin: check_bmon

Output: TRAFFIC OK|in=131.9Bps; out=185Bps;

$opt[1] = “–vertical-label \”Bytes/s\” –title \”$servicedesc\” “;

$def[1] = “DEF:var1=$RRDFILE[1]:$DS[1]:AVERAGE “ ;
$def[1] .= “DEF:var2=$RRDFILE[2]:$DS[2]:AVERAGE “ ;
$def[1] .= “CDEF:var3=var2,-1,* “ ;
$def[1] .= “AREA:var1#00ff00:\”in\” “ ;
$def[1] .= “GPRINT:var1:LAST:\”%.1lf %SBytes last\” “ ;
$def[1] .= “GPRINT:var1:AVERAGE:\”%.1lf %SBytes avg\” “ ;
$def[1] .= “GPRINT:var1:MAX:\”%.1lf %SBytes max\n\” “ ;

$def[1] .= “AREA:var2#0066FF:\”out\” “ ;

$def[1] .= “AREA:var3#0066FF:\”out\” “ ;
$def[1] .= “GPRINT:var2:LAST:\”%.1lf %SBytes last\” “ ;
$def[1] .= “GPRINT:var2:AVERAGE:\”%.1lf %SBytes avg\” “ ;
$def[1] .= “GPRINT:var2:MAX:\”%.1lf %SBytes max\” “;
?>
```
pnp template 文档
https://docs.pnp4nagios.org/pnp-0.6/tpl_custom
icinga2官方集成pnp4nagios模板攻略
http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/addons-plugins?highlight-search=pnp4nagios#addons-graphing-pnp-custom-templates