如何使用Nagios监控Cisco交换机硬件及运行状态

如何使用Nagios监控Cisco交换机硬件及运行状态,第1张

系统环境:Nagios3.x+CentOS5.6+Cisco4500前提条件:1.Cisco交换机都支持SNMP协议,只需要简单的设置即可开启,例如:snmp-servercommunitysnmppwRO。更加详细的设置请使用Google搜索“Cisco开启SNMP”,参考网上相关文章。2.在安装Nagios之前,必须已经安装Net-Utils及其开发组件。成功安装Nagios之后,再次检查libexec目录下有check_snmp命令。系统测试:check_snmp命令提供了详细的使用说明,只需要在Linux命令行输入check_snmp–help即可查看帮助信息,这其中包括每一项参数的使用等。这里以检测Cisco交换机的系统为例,示范如何使用check_snmp。交换机为Cisco4500系列,系统描述的OID为.1.3.6.1.2.1.1.1.0[root@wardkinglibexec]#./check_snmp-H10.241.10.1-o.1.3.6.1.2.1.1.1.0-CsnmppwSNMPOK–“CiscoIOSSoftware,Catalyst4500L3SwitchSoftware(cat4500-ENTSERV|K9-M),Version12.2(53)SG2,RELEASESOFTWARE(fc1)建议用于Nagios监控的OID:系统内存使用(5分钟内)1.3.6.1.4.1.9.9.48.1.1.1.5.1系统可用内存(5分钟内)1.3.6.1.4.1.9.9.48.1.1.1.6.1CPU使用率(5分钟内)1.3.6.1.4.1.9.2.1.58.0硬件状态1.3.6.1.4.1.9.9.13系统配置:由于使用check_snmp检测的结果不够人性化,大部分的结果都需要重新调整。使用Perl脚本调用NET::SNMP模块,实现收集监控结果,并重新输出,更易阅读和使用。这里引用4个从国外网站收集的脚本,check_snmp_env,check_snmp_cisco_memutil,check_snmp_cisco_loadavg,check_snmp_cisco_ifstatus请下载至nagios安装目录下的libexec子目录中,例如/usr/local/nagios/libexec,重命名去掉txt扩展名,赋予可执行权限:[root@nagioslibexec]#pwd/usr/local/nagios/libexec[root@nagioslibexec]#chmoda+xcheck_snmp_cisco_*check_snmp_env-vmodeof`check_snmp_cisco_ifstatus’retainedas0755(rwxr-xr-x)modeof`check_snmp_cisco_loadavg’retainedas0755(rwxr-xr-x)modeof`check_snmp_cisco_memutil’retainedas0755(rwxr-xr-x)modeof`check_snmp_env’retainedas0755(rwxr-xr-x)剩下的工作就是follow标准流程设置监控命令,添加被监控的交换机和服务了。编辑etc/objects/command.cfg,添加如下定义:#CheckCisco,ExtremeandJuniperhardwaredefinecommand{command_namecheck_snmp_envcommand_line$USER1$/check_snmp_env-H$HOSTADDRESS$-C$ARG1$$ARG2$}#CiscoSNMPdevicemonitoringdefinecommand{command_namecheck_snmp_cisco_memcommand_line$USER1$/check_snmp_cisco_memutil-H$HOSTADDRESS$-C$ARG1$-w$ARG2$-c$ARG3$}definecommand{command_namecheck_snmp_cisco_cpucommand_line$USER1$/check_snmp_cisco_loadavg-H$HOSTADDRESS$-C$ARG1$-w$ARG2$-c$ARG3$}definecommand{command_namecheck_snmp_cisco_ifcommand_line$USER1$/check_snmp_cisco_ifstatus-H$HOSTADDRESS$-C$ARG1$-i$ARG2$-w$ARG3$-c$ARG4$}编辑switch.cfg加入监控的交换机配置,新增相关系统服务,例如:defineservice{usegeneric-serviceInheritvaluesfromatemplatehost_nameCAT4506E_B1_LG3_1,CAT4506E_B3_A09L_1,CAT4507R_B5_A09R_1,CAT4507R_B1_LG3_1,CAT4507R_B5_D12_1,RackSW_PDC_1,RackSW_PDC_2,RackSW_PDC_3,RackSW_PDC_4,RackSW_SDC_2,RackSW_SDC_3service_descriptionEnvironmentcheck_commandcheck_snmp_env!snmppw}defineservice{usegeneric-serviceInheritvaluesfromatemplatehost_nameCAT4507R_B5_D12_1,CAT4507R_B1_LG3_1,CAT4506E_B1_LG3_1,CAT4506E_B3_A09L_1,CAT4507R_B5_A09R_1service_descriptionLoadAVGcheck_commandcheck_snmp_cisco_cpu!snmppw!60!80}defineservice{usegeneric-serviceInheritvaluesfromatemplatehost_nameCAT4507R_B5_D12_1,CAT4507R_B1_LG3_1,CAT4506E_B1_LG3_1,CAT4506E_B3_A09L_1,CAT4507R_B5_A09R_1service_descriptionMemutilcheck_commandcheck_snmp_cisco_mem!snmppw!70!90}

1,安装NSClient++

访问http://nsclient.org/nscp/下载NSClient++,这里我使用的是NSClient++-0.3.9-x64的msi安装包。下载之后直接安装,过程中会提示输入Nagios监控服务器地址和密码。地址填写正确,密码不用设置。Nagios监控服务器事先在监控Linux服务器时候已经搭建好,以后再和大家分享。

安装如下图所示:

2.配置NSClient++

编辑安装目录下的NES.ini文件,打开NSClient++的端口。方法为找到:[NSClient]port=12489去掉port前的“”就可以启用12489端口。

3,Nagios监控服务器设置vi /usr/local/nagios/etc/nagios.cfg

4,搜索找到:# Definitions for monitoring a Windows machine

# cfg_file=/usr/local/nagios/etc/objects/windows.cfg

5,将第二行的#去掉打开Nagios监控的Windows模块,然后保存。

接着编辑# vi /usr/local/nagios/etc/objects/windows.cfg

6,找到并设置监控的服务器:

7,接下来搜索各种监控的服务并设置:

8,部署好之后在Nagios中显示如下:

监控主机配置:redhat linux as4,nagios3

被监控主机:Windows Server 2008 R2 Enterprise,nsclient++0.4.4.172

Nagios是一款开源的免费网络监视工具,其功能强大,灵活性强。能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。nagios监控windows系统有三种实现方式:SNMP、NSClient++、NRPE。

下面介绍使用NSClient++方式来监控Windows:

首先在windows下安装nsclient++,运行NSCP-0.4.0.172-x64.msi安装文件,一步一步往下走,其中需要设置nagios监控主机IP和NSClient密码(值当使用check_nt时使用),如图1所示:

Allowed hosts:填写nagios监控主机IP

NSClient Password:当使用命令check_nt时需要设置密码,根据自己情况设置

Module to load:根据自己的需要选择相应的模块

安装完毕以后,打开windows服务管理器,查看nsclient服务是否启动,如图2所示:

然后在nagios监控主机上面进行相关的配置,主要涉及两个配置文件nagios.cfg和windows.cfg

(1)因为nagios是模块化调用,先到配置文件打开windows相关模块,编辑nagios.cfg文件

[root@localhost etc]# ls

cgi.cfg htpasswd nagios.cfg nrpe.cfg objects objects.bak objects.tar resource.cfg

[root@localhost etc]# pwd

/usr/local/nagios/etc

[root@localhost etc]# vi nagios.cfg

将#cfg_file=/usr/local/nagios/etc/objects/windows.cfg该行前面的#注释去掉即可.

(1)修改windows.cfg配置文件,需要修改define host和define service两部分

# Define a host for the Windows machine we'll be monitoring

# Change the host_name, alias, and address to fit your situation

define host{

use windows-server Inherit default values from a template

host_name video4-beijing The name we're giving to this host 被监控主机的主机名

alias video4-beijing A longer name associated with the host

contact_groupssa

address 10.12.4.169 IP address of the host 被监控主机的IP

}

# Create a service for monitoring CPU load

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description CPU Load

check_command check_nt!CPULOAD!-l 5,80,90

contact_groups sa

}

# Create a service for monitoring

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description Memory Usage

check_command check_nt!MEMUSE!-w 80 -c 90

contact_groups sa

}

# Create a service for monitoring C:\ disk usage

# Change the host_name to match the name of the host you defined above

define service{

use generic-service

host_name video4-beijing

service_description C:\ Drive Space

check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90

contact_groups sa

}

修改完相关的配置文件以后,执行如下命令检查配置文件是否正确:

[root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

遇到的问题,在检查配置文件时错误信息如下:

Checking services...

Error: Contact group 'admins' specified in service 'C:\ Drive Space' for host 'video4-beijing' is not defined anywhere!

Error: Contact group 'admins' specified in service 'Explorer' for host 'video4-beijing' is not defined anywhere!

Error: Contact group 'admins' specified in service 'Memory Usage' for host 'video4-beijing' is not defined anywhere!

Checked 14 services.

Checking hosts...

Error: Contact group 'admins' specified in host 'video4-beijing' is not defined anywhere!

Checked 7 hosts.

Checking host groups...

Checked 2 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 25 commands.

Checking time periods...

Checked 5 time periods.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

Total Warnings: 0

Total Errors: 4

***>One or more problems was encountered while running the pre-flight check...

Check your configuration file(s) to ensure that they contain valid

directives and data defintions. If you are upgrading from a previous

version of Nagios, you should be aware that some variables/definitions

may have been removed or modified in this version. Make sure to read

the HTML documentation regarding the config files, as well as the

'Whats New' section to find out what has changed.

以上问题的原因是因为一开始在windows.cfg文件中定义host和service时没有增加contact_groups sa这个字段,host和service默认所在的contact_group为admins,而我的nagios监控主机contacts.cfg文件中配置的contactgroup为sa。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11458792.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存