check_mk之Parents和statusmap_image

2014年2月13日 发表评论 阅读评论

近日在改造老的nagios 监控方式,原有的nrpe和snmp方式的监控不变,新的主机以check_mk的方式进行监控。由于之前做过相关的搭建,在功能新增上基本上没遇到什么瓶颈。不过还是遇到了三个小问题,这里做下总结。

问题一、Parents 父节点绘图问题

现新建立的KVM虚拟主机的父节点都是物理服务器,但物理服务器之前是由nrpe的方式进行监控的。新增的虚拟以check_mk wato方式增加时,输入父节点时会报警告 

Warning: This host has an invalid configuration!
You defined the non-existing host 'xxx.37.194.xx' as a parent.

如下图所示:

check-mk-parent

通过scan for parents也找不到可用的父节点。如果增加时不选择父节点 。在nagios的map上查看时,发现其是一个根节点(this is a root host )。显然这在实际的网络结构中不对。通过查看官网资料

https://mathias-kettner.de/checkmk_parents.html

发现解决方法如下

方法1、不管警告信息,直接按wato的各项填写完成后save & Finish 。虽然告警,但在nagios map上查看到的结果是正常的。

方法2、修改/usr/local/nagios/etc/hosts/check_mk_objects.cfg 文件(具体根据自己nagios的编译位置查找),打开该文件后,发现其配置方式和nrpe配置里的配置方式相同。在define host里增加parents 项并重启nagios 即可。

注:该方法缺陷比较大,该文件头上有提示Created by Check_MK. Do not edit. 每次在check_mk的配置界面上更改配置并change active后,新加的配置又没了。所以该方法不推荐用。

方法3、参照官方文档,更改/etc/check_mk/conf.d/wato/hosts.mk文件,按check_mk官网格式添加配置,并cmk -O生效 。不过该方法同样会出现方法2中的问题。

方法4、在/etc/check_mk/conf.d/wato/中新建一个.mk文件,名字随意取。将配置写到该文件中,完成后cmk -O生效。无论在web界面上如何更改,也不会修改该配置中的内容。

问题二、statusmap_image图标问题

该问题也是nagios map上的小问题,按上面的方法增加好host并配置好parent后,默认显示的图标是个问号 。web界面上又找不到配置图标的地方。使用问题一 中的方法2和方法3肯定一样不行。同样,按照问题一中的方法4,新增一个配置文件,增加如下内容:

#cat statusmap.mk
extra_host_conf['statusmap_image'] = [
   ( 'linux40.gd2', ['prod', ], ALL_HOSTS ),
]

这里是以tag组的方式添加的,也可以以host的方式添加,具体看上面checkmk_parents文档里的语法就行了。该问题的解决方法,参考以下页面。

http://www.monitoring-portal.org/wbb/index.php?page=Thread&threadID=30166

问题三、网卡流量检测出图异常

该问题在之前版本中的check_mk中没遇到,目前使用Check_MK 1.2.4 (stable) 安装后,其他插件出图正常。报错内容为:

unknow function 'PERCENTNAN' in VDEF outper

问题原因:新的check_mk pnp4nagios模板文件写的有问题。使用以前旧的模板文件即可。

解决方法:在/usr/local/pnp4nagios/share/templates 模板中,将check_mk-lnx_if.php文件(即check_mk-if.php文件,ln软链的)的内容更改为以下内容。

<?php
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  /  | |/ /           |
# |           | |   | '_  / _ / __| |/ /   | |/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | .             |
# |            ____|_| |_|___|___|_|____|_|  |_|_|_           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk 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 in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
setlocale(LC_ALL, 'C');
# Performance data from check:
# in=6864.39071505;0.01;0.1;0;125000000.0
# inucast=48.496962273;0.01;0.1;;
# innucast=4.60122981717;0.01;0.1;;
# indisc=0.0;0.01;0.1;;
# inerr=0.0;0.01;0.1;;
# out=12448.259172;0.01;0.1;0;125000000.0
# outucast=54.9846963152;0.01;0.1;;
# outnucast=10.5828285795;0.01;0.1;;
# outdisc=0.0;0.01;0.1;;
# outerr=0.0;0.01;0.1;;
# outqlen=0;;;;10000000
# Graph 1: used bandwidth
# Determine if Bit or Byte.
# Change multiplier and labels
$unit = "B";
$unit_multiplier = 1;
$vertical_label_name = "MByte/sec";
if (strcmp($MIN[11], "0.0") == 0) {
    $unit = "Bit";
    $unit_multiplier = 8;
    $vertical_label_name = "MBit/sec";
}
$bandwidth = $MAX[1]  * $unit_multiplier;
$warn      = $WARN[1] * $unit_multiplier;
$crit      = $CRIT[1] * $unit_multiplier;
# Horizontal lines
$mega        = 1024.0 * 1024.0;
$mBandwidthH = $bandwidth / $mega;
$mWarnH      = $warn      / $mega;
$mCritH      = $crit      / $mega;
# Break down bandwidth, warn and crit
$bwuom = ' ';
$base = 1000;
if($bandwidth > $base * $base * $base) {
	$warn /= $base * $base * $base;
	$crit /= $base * $base * $base;
	$bandwidth /= $base * $base * $base;
	$bwuom = 'G';
} elseif ($bandwidth > $base * $base) {
	$warn /= $base * $base;
	$crit /= $base * $base;
	$bandwidth /= $base * $base;
	$bwuom = 'M';
} elseif ($bandwidth > $base) {
	$warn /= $base;
	$crit /= $base;
	$bandwidth /= $base;
	$bwuom = 'k';
}
if ($mBandwidthH < 10)
   $range = $mBandwidthH;
else
   $range = 10.0;
$bandwidthInfo = "";
if ($bandwidth > 0){
    $bandwidthInfo = " at bandwidth ${bwuom}${unit}/s";
}
$ds_name[1] = 'Used bandwidth';
$opt[1] = "--vertical-label "$vertical_label_name" -l -$range -u $range -X0 -b 1024 --title "Used bandwidth $hostname / $servicedesc $bandwidthInfo" ";
$def[1] =
  "HRULE:0#c0c0c0 ";
  if ($mBandwidthH)
      $def[1] .= "HRULE:$mBandwidthH#808080:"Port speed:  " . sprintf("%.1f", $bandwidth) . " ".$bwuom."$unit/s\n" ".
                 "HRULE:-$mBandwidthH#808080: ";
   if ($warn)
      $def[1] .= "HRULE:$mWarnH#ffff00:"Warning:                " . sprintf("%6.1f", $warn) . " ".$bwuom."$unit/s\n" ".
                 "HRULE:-$mWarnH#ffff00: ";
   if ($crit)
      $def[1] .= "HRULE:$mCritH#ff0000:"Critical:               " . sprintf("%6.1f", $crit) . " ".$bwuom."$unit/s\n" ".
                 "HRULE:-$mCritH#ff0000: ";
  $def[1] .= "DEF:inbytes=$RRDFILE[1]:$DS[1]:MAX ".
  "DEF:outbytes=$RRDFILE[6]:$DS[6]:MAX ".
  "CDEF:intraffic=inbytes,$unit_multiplier,* ".
  "CDEF:outtraffic=outbytes,$unit_multiplier,* ".
  "CDEF:inmb=intraffic,1048576,/ ".
  "CDEF:outmb=outtraffic,1048576,/ ".
  "CDEF:minusoutmb=0,outmb,- ".
  "AREA:inmb#00e060:"in                    " ".
  "GPRINT:intraffic:LAST:"%6.1lf %s$unit/s last" ".
  "GPRINT:intraffic:AVERAGE:"%6.1lf %s$unit/s avg" ".
  "GPRINT:intraffic:MAX:"%6.1lf %s$unit/s max\n" ".
  "AREA:minusoutmb#0080e0:"out                   " ".
  "GPRINT:outtraffic:LAST:"%6.1lf %s$unit/s last" ".
  "GPRINT:outtraffic:AVERAGE:"%6.1lf %s$unit/s avg" ".
  "GPRINT:outtraffic:MAX:"%6.1lf %s$unit/s max\n" ";
if (isset($DS[12])) {
  $def[1] .=
  "DEF:inbytesa=$RRDFILE[12]:$DS[12]:MAX ".
  "DEF:outbytesa=$RRDFILE[13]:$DS[13]:MAX ".
  "CDEF:intraffica=inbytesa,$unit_multiplier,* ".
  "CDEF:outtraffica=outbytesa,$unit_multiplier,* ".
  "CDEF:inmba=intraffica,1048576,/ ".
  "CDEF:outmba=outtraffica,1048576,/ ".
  "CDEF:minusoutmba=0,outmba,- ".
  "LINE:inmba#00a060:"in (avg)              " ".
  "GPRINT:intraffica:LAST:"%6.1lf %s$unit/s last" ".
  "GPRINT:intraffica:AVERAGE:"%6.1lf %s$unit/s avg" ".
  "GPRINT:intraffica:MAX:"%6.1lf %s$unit/s max\n" ".
  "LINE:minusoutmba#0060c0:"out (avg)             " ".
  "GPRINT:outtraffica:LAST:"%6.1lf %s$unit/s last" ".
  "GPRINT:outtraffica:AVERAGE:"%6.1lf %s$unit/s avg" ".
  "GPRINT:outtraffica:MAX:"%6.1lf %s$unit/s max\n" ";
}
# Graph 2: packets
$ds_name[2] = 'Packets';
$opt[2] = "--vertical-label "packets/sec" --title "Packets $hostname / $servicedesc" ";
$def[2] =
  "HRULE:0#c0c0c0 ".
  "DEF:inu=$RRDFILE[2]:$DS[2]:MAX ".
  "DEF:innu=$RRDFILE[3]:$DS[3]:MAX ".
  "AREA:inu#00ffc0:"in unicast              " ".
  "GPRINT:inu:LAST:"%7.2lf/s last  " ".
  "GPRINT:inu:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:inu:MAX:"%7.2lf/s max\n" ".
  "AREA:innu#00c080:"in broadcast/multicast  ":STACK ".
  "GPRINT:innu:LAST:"%7.2lf/s last  " ".
  "GPRINT:innu:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:innu:MAX:"%7.2lf/s max\n" ".
  "DEF:outu=$RRDFILE[7]:$DS[7]:MAX ".
  "DEF:outnu=$RRDFILE[8]:$DS[8]:MAX ".
  "CDEF:minusoutu=0,outu,- ".
  "CDEF:minusoutnu=0,outnu,- ".
  "AREA:minusoutu#00c0ff:"out unicast             " ".
  "GPRINT:outu:LAST:"%7.2lf/s last  " ".
  "GPRINT:outu:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:outu:MAX:"%7.2lf/s max\n" ".
  "AREA:minusoutnu#0080c0:"out broadcast/multicast ":STACK ".
  "GPRINT:outnu:LAST:"%7.2lf/s last  " ".
  "GPRINT:outnu:AVERAGE:"%7.2lf/s avg  "  ".
  "GPRINT:outnu:MAX:"%7.2lf/s max\n" ";
# Graph 3: errors and discards
$ds_name[3] = 'Errors and discards';
$opt[3] = "--vertical-label "packets/sec" -X0 --title "Problems $hostname / $servicedesc" ";
$def[3] =
  "HRULE:0#c0c0c0 ".
  "DEF:inerr=$RRDFILE[5]:$DS[5]:MAX ".
  "DEF:indisc=$RRDFILE[4]:$DS[4]:MAX ".
  "AREA:inerr#ff0000:"in errors               " ".
  "GPRINT:inerr:LAST:"%7.2lf/s last  " ".
  "GPRINT:inerr:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:inerr:MAX:"%7.2lf/s max\n" ".
  "AREA:indisc#ff8000:"in discards             ":STACK ".
  "GPRINT:indisc:LAST:"%7.2lf/s last  " ".
  "GPRINT:indisc:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:indisc:MAX:"%7.2lf/s max\n" ".
  "DEF:outerr=$RRDFILE[10]:$DS[10]:MAX ".
  "DEF:outdisc=$RRDFILE[9]:$DS[9]:MAX ".
  "CDEF:minusouterr=0,outerr,- ".
  "CDEF:minusoutdisc=0,outdisc,- ".
  "AREA:minusouterr#ff0080:"out errors              " ".
  "GPRINT:outerr:LAST:"%7.2lf/s last  " ".
  "GPRINT:outerr:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:outerr:MAX:"%7.2lf/s max\n" ".
  "AREA:minusoutdisc#ff8080:"out discards            ":STACK ".
  "GPRINT:outdisc:LAST:"%7.2lf/s last  " ".
  "GPRINT:outdisc:AVERAGE:"%7.2lf/s avg  " ".
  "GPRINT:outdisc:MAX:"%7.2lf/s max\n" ";
?>




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

分类: 开源软件 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.