合nagios+cacti+微信、飞信实现网络监控报警

系统环境:rhel6.3

        selinux disabled  和 iptables
    整合cacti和nagios是利用了cacti的一个插件nagiosfor cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。

一、nagios监控本地主机

注释掉localhost.cfg,新增加hosts.cfg,services.cfg

[[email protected] etc]#vim  /usr/local/nagios/etc/nagios.cfg

# You can specify individual object config files as shown below:

cfg_file=/usr/local/nagios/etc/objects/commands.cfg

cfg_file=/usr/local/nagios/etc/objects/contacts.cfg

cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg

cfg_file=/usr/local/nagios/etc/objects/templates.cfg

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

# Definitions for monitoring the local (Linux) host

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

localhost.cfg中主机与服务是在一块的,这样不好管理,以下将主机与服务分开

更改主机:

[[email protected] objects]# cp localhost.cfg hosts.cfg

[[email protected] objects]# vim hosts.cfg

define host{

use                     linux-server

host_name              server34.example.com

alias                   Manager

address                 192.168.0.34

icon_image              server.gif

statusmap_image         server.gd2

2d_coords500,200

3d_coords500,200,100

}

###############################################################################

###############################################################################

#

# HOST GROUP DEFINITION

#

###############################################################################

###############################################################################

# Define an optional hostgroup for Linux machines

define hostgroup{

hostgroup_name  linux-servers ; The name of the hostgroup

alias           Linux Servers ; Long name of the group

members         *     ; Comma separated list of hosts that belong to this group

}

[[email protected] objects]# cp localhost.cfg services.cfg

[[email protected] objects]# cat hosts.cfg

define host{

use                     linux-server

host_name              server34.example.com

alias                   Manager

address                 192.168.0.34

icon_image              server.gif

statusmap_image         server.gd2

2d_coords500,200

3d_coords500,200,100

}

###############################################################################

###############################################################################

#

# HOST GROUP DEFINITION

#

###############################################################################

###############################################################################

# Define an optional hostgroup for Linux machines

define hostgroup{

hostgroup_name  linux-servers ; The name of the hostgroup

alias           Linux Servers ; Long name of the group

members         *     ; Comma separated list of hosts that belong to this group

}

[[email protected] objects]# cat services.cfg

define servicegroup{

servicegroup_name 系统负荷检查

alias 负荷检查

members server34.example.com,进程总数,server34.example.com,登录用户数,server34.example.com,根分区,server34.example.com,交换空间利用率

}

define servicegroup{

servicegroup_name 全部联通性检查

alias 联通性检查

members server34.example.com,PING

}

###############################################################################

###############################################################################

#

# SERVICE DEFINITIONS

#

###############################################################################

###############################################################################

# Define a service to "ping" the local machine

define service{

use                             local-service         ; Name of service template to use

host_name                       *

service_description             PING

check_commandcheck_ping!100.0,20%!500.0,60%

}

# Define a service to check the disk space of the root partition

# on the local machine.  Warning if < 20% free, critical if

# < 10% free space on partition.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             根分区

check_commandcheck_local_disk!20%!10%!/

}

# Define a service to check the number of currently logged in

# users on the local machine.  Warning if > 20 users, critical

# if > 50 users.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             登录用户数

check_commandcheck_local_users!20!50

}

# Define a service to check the number of currently running procs

# on the local machine.  Warning if > 250 processes, critical if

# > 400 users.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             进程总数

check_commandcheck_local_procs!250!400!RSZDT

}

# Define a service to check the load on the local machine.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             系统负荷

check_commandcheck_local_load!5.0,4.0,3.0!10.0,6.0,4.0

}

# Define a service to check the swap usage the local machine.

# Critical if less than 10% of swap is free, warning if less than 20% is free

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             交换空间利用率

check_commandcheck_local_swap!20!10

}

# Define a service to check SSH on the local machine.

# Disable notifications for this service by default, as not all users may have SSH enabled.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             SSH

check_commandcheck_tcp!22!1.0!10.0

notifications_enabled0

}

# Define a service to check HTTP on the local machine.

# Disable notifications for this service by default, as not all users may have HTTP enabled.

define service{

use                             local-service         ; Name of service template to use

host_name                       server34.example.com

service_description             HTTP

check_commandcheck_http

notifications_enabled0

}

检测nagios的配置文件

[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

[[email protected] objects]# /etc/init.d/nagios reload

http://192.168.0.34/nagios

点击服务:

看到以下信息

二、nagios监控远程主机

1、监控远程主机的网络服务

监控主机:192.168.0.34

远程主机(被监控主机):192.168.0.17

rhel6.4 selinux disabled and iptables

一、监控远程主机的网络服务(如监控mysql服务等):

在此以监控远程主机的mysql为例来说明nagios是怎样监控远程主机的网络服务的。

安装mysql

[[email protected] ~]# yum install mysql -y

启动mysql

创建nagios数据库,并给nagios用户授予在监控主机上登录nagios库的权限。

mysql> create database nagios;

mysql> grant select on nagios.* to [email protected]‘192.168.0.34‘ identified by ‘westos‘;

检测是否能采集到信息:

[[email protected] libexec]# ./check_mysql -H 192.168.0.17 -u nagios -p westos -d nagios

Uptime: 1648  Threads: 1  Questions: 15  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.9|Connections=8c;;; Open_files=16;;; Open_tables=8;;; Qcache_free_memory=0;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=0c;;; Qcache_queries_in_cache=0;;; Queries=15c;;; Questions=15c;;; Table_locks_waited=0c;;; Threads_connected=1;;; Threads_running=1;;; Uptime=1648c;;;

[[email protected] libexec]# pwd

/usr/local/nagios/libexec

添加检测命令:

[[email protected] objects]# vim commands.cfg

# ‘check_mysql‘ command definition

define command{

command_name    check_mysql

command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$  -d $ARG3$

}

添加主机:

[[email protected] objects]# vim hosts.cfg

define host{

use                     linux-server

host_name               server17.example.com

alias                   mysql

address                 192.168.0.17

icon_image              server.gif

statusmap_image         server.gd2

2d_coords               600,300

3d_coords               600,300,100

}

添加服务:

[[email protected] objects]# vim services.cfg   ###添加服务组

define servicegroup{

servicegroup_name 全部联通性检查

alias 联通性检查

members server34.example.com,PING,server17.example.com,PING

}

################################check_mysql#################################

define service{                             ###添加服务

use                             local-service         ; Name of service template to use

host_name                       server17.example.com

service_description             check_mysql

check_command                   check_mysql!nagios!westos!nagios

}

验证配置文件更改是否正确:

[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

重新加载nagios:

[[email protected] objects]# /etc/init.d/nagios reload

检测:http://192.168.0.34/nagios

点击主机->出现server17.example.com

点击服务->出现check_mysql服务

2、通过nrpe监控远程主机的基本信息(如此盘的使用情况等)。

在被监控主机上操作:

下载nagios插件包、nrpe包

nagios-plugins-1.5.tar.gz, nrpe-2.15.tar.gz

[[email protected] ~]# tar zxf nagios-plugins-1.5.tar.gz

创建nagios用户

[[email protected] ~]# useradd nagios

编译安装nagios-plugin

[[email protected] ~]# cd nagios-plugins-1.5

[[email protected] nagios-plugins-1.5]# ./configure --with-nagios-user=nagios --with-nagios-user=nagios

[[email protected] nagios-plugins-1.5]# make && make install

编译安装nrpe,nrpe是守护进程,需安装更改xinetd

[[email protected] nrpe-2.15]# yum install xinetd -y

[[email protected] nrpe-2.15]# vim /etc/xinetd.d/nrpe

only_from       = 192.168.0.34

[[email protected] nrpe-2.15]# vim /etc/services

nrpe            5666/tcp

[[email protected] nrpe-2.15]# ./configure

[[email protected] nrpe-2.15]# make all

[[email protected] nrpe-2.15]# make install-plugin

[[email protected] nrpe-2.15]# make install-daemon

[[email protected] nrpe-2.15]# make install-daemon-config

[[email protected] nrpe-2.15]# make install-xinetd

[[email protected] nrpe-2.15]# /etc/init.d/xinetd start

配置nrpe

[[email protected] etc]# vim nrpe.cfg

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

用守护进程xibnetd启动nrpe

[[email protected] ~]# /etc/init.d/xinetd start

##########################################

在监控主机上

下载nrpe包:

nrpe-2.15.tar.gz

在监控主机上操作:

[[email protected] nrpe-2.15]# ./configure

[[email protected] nrpe-2.15]# make all

[[email protected] nrpe-2.15]# make install-plugin

[[email protected] nrpe-2.15]# make install-daemon

[[email protected] nrpe-2.15]# make install-daemon-config

检测:

[[email protected] libexec]# ./check_nrpe -H 192.168.0.17

NRPE v2.15

检测磁盘使用情况:

[[email protected] libexec]# ./check_nrpe -H 192.168.0.17 -c check_disk

DISK OK - free space: / 14459 MB (85% inode=91%);| /=2540MB;14327;16118;0;17909

添加check_nrpe检测命令

[[email protected] objects]# vim commands.cfg

# ‘check_nrpe‘ command definition

define command{

command_name    check_nrpe

command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

[[email protected] objects]# vim services.cfg

define servicegroup{

servicegroup_name 系统负荷检查

alias 负荷检查

members server34.example.com,进程总数,server34.example.com,登录用户数,server34.example.com,根分区,server34.example.com,交换空间利用率

}

define servicegroup{

servicegroup_name 全部联通性检查

alias 联通性检查

members server34.example.com,PING,server17.example.com,PING

}

配置检测:

[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

检测:

http ://192.168.0.34/nagios

点击服务,查看结果。


整合nagios与微信、飞信

整合nagios与微信、飞信,使得nagios的监控报警具有了锦上添花的效果。这样,管理员不用经常性的查看系统运行是否正常,磁盘使用情况等等,有什么异常情况,微信、飞信会第一时间的通知你,你要做的就是手机保持畅通就ok了。既然这么好,那大家就跟随我一块愉快的感受下吧!

配置微信,飞信:

首先打开相关服务:

[[email protected] objects]# /etc/init.d/nagios start

[[email protected] objects]# /etc/init.d/httpd start

[[email protected] objects]# /etc/init.d/mysqld start

检测[email protected]是否能收发邮件

[[email protected] objects]# mail [email protected]

切换到nagios用户,查看到以下邮件时则成功

[[email protected] objects]# su - nagios

-bash-4.1$ mail

Heirloom Mail version 12.4 7/29/08.  Type ? for help.

"/var/spool/mail/nagios": 1 message

>   1 root                  Sun Apr 27 09:54  20/642   "dsdssds"

&

一般自定义域名会被QQ邮箱当作垃圾邮件处理,在QQ邮箱中设置白名单

-bash-4.1$ ping mail.qq.com  //检测是否可以上网

PING mail.qq.com (14.17.32.178) 56(84) bytes of data.

64 bytes from 14.17.32.178: icmp_seq=1 ttl=53 time=54.4 ms

64 bytes from 14.17.32.178: icmp_seq=2 ttl=53 time=1088 ms

添加邮箱:

[[email protected] objects]# vim contacts.cfg

email                           [email protected]

[[email protected] objects]# /etc/init.d/nagios reload

下载fetion,和飞信的库文件linuxso_20101113.tar.gz

[[email protected] ~]# tar zxf linuxso_20101113.tar.gz -C /lib^C

[[email protected] ~]# cp fetion /usr/local/nagios/libexec/

给以下文件加可执行权限

[[email protected] libexec]# chmod +x libACE*^C

[[email protected] libexec]# chmod +x libcrypto.so.4 libssl.so.4

[[email protected] libexec]# chmod nagios.nagios fetion

[[email protected] libexec]# su - nagios

根据提示的错误依次安装以下软件包:

-bash-4.1$ /usr/local/nagios/libexec/fetion

-bash: /usr/local/nagios/libexec/fetion: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

[[email protected] ~]# yum install /lib/ld-linux.so.2  libstdc++.so.6  libgssapi_krb5.so.2  libz.so.1  -y

第一次发送是会要求输入校验码,以后发送时则不需要

-bash-4.1$ /usr/local/nagios/libexec/fetion --mobile=18709242146 --pwd=316103ok --to=18740419949,18709242146 --msg-utf8="hahahahhhhhhhhhhhaaaa"

为了查看校验码的内容,将校验码拷贝到物理主机的桌面上

[[email protected] libexec]# scp 18709242146.jpg 192.168.0.39:/root/Desktop

整合飞信与nagios

因为发送的对象和内容一直在变,所以用脚本实现:

-bash-4.1$ vim fetion.sh

/usr/local/nagios/libexec/fetion --mobile=18709242146 --pwd=316103ok --to="$1" --msg-utf8="$2" &>/dev/null

给fetion.sh加可执行权限:

-bash-4.1$ chmod +x fetion.sh

测试:

-bash-4.1$ /usr/local/nagios/libexec/fetion.sh 18709242146 "westos linux"

-bash-4.1$ vim contacts.cfg

define contact{

contact_name                    nagiosadmin             ; Short name of user

use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

alias                           Nagios Admin            ; Full name of user

email                           [email protected]        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

pager                           18709242146

}

-bash-4.1$ vim commands.cfg

# ‘notify-host-by-fetion‘ command definition

define command{

command_name    notify-host-by-fetion

command_line    $USER1$/fetion.sh $CONTACTPAGER$ " $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$"

}

# ‘notify-service-by-FETION‘ command definition

define command{

command_name    notify-service-by-fetion

command_line     $USER1$/fetion.sh $CONTACTPAGER$ " $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"

}

-bash-4.1$ vim templates.cfg

service_notification_commands   notify-service-by-email,notify-service-by-fetion        ; send service notifications via email

host_notification_commands      notify-host-by-email,notify-host-by-fetion      ; send host notifications via email

加测配置文件

[[email protected] objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

测试:

[[email protected] ~]# /etc/init.d/mysqld stop

Stopping mysqld:                                           [  OK  ]

会收到邮件提示

合nagios+cacti+微信、飞信实现网络监控报警,布布扣,bubuko.com

时间: 2024-12-25 07:15:59

合nagios+cacti+微信、飞信实现网络监控报警的相关文章

实战Nagios网络监控(3)——Nagios 微信报警

1. 下载微信公众平台私有接口 # yum install -y git # git clone https://github.com/lealife/WeiXin-Private-API 2. 修改微信公众平台私有接口代码,以配合 nagios 报警 # cp -r WeiXin-Private-API /usr/local/nagios/libexec/weixin # chown -R nagios.nagios /usr/local/nagios/libexec/weixin # cd

实战1 网络监控cacti的安装配置

一.cacti概述二.cacti工作流程三.cacti安装四.配置cacti监控本机 环境: 操作系统:CentOS 6.4 x86_64软件:Cacti-0.8.7e 官方网站:http://www.cacti.net 一.cacti概述Cacti 在英文中的意思是仙人掌的意思,Cacti是一套基于PHP.MySQL.SNMP及RRDTool开发的网络流量监测图形分析工具.它通过snmpget来获取数据,使用 RRDtool绘画图形,它的界面非常漂亮,能让你根本无需明白rrdtool的参数能轻

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

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

CentOS6.7上安装Cacti网络监控系统

Cacti工具是一套开源的基于Web的网络监控和系统监控的图形解决方案.Cacti通过SNMP服务获取数据,并使用RRDtool绘制图形,提供非常直观的数据和用户管理功能.Cacti需要Web.MySQL和PHP的支持.Cacti一般用于监控网络流量.使用率CPU负载.磁盘空间等. Cacti官网:http://www.cacti.net/ 安装Cacti需要安装的软件包:Apache.MySQL.PHP.RRTool.PHP-SNMP.NET-SNMP 一.安装Cacti需要安装的软件包 1.

Nagios&Cacti篇六:使用Cacti监控Windows

通过前几篇的介绍,大家对CACTI软件已经有了初步的了解,并能够实现对网络设备(eg cisco).Linux Server进行监控.那么如何监控现网Windows系列服务器或客户端呢?本文将为大家解答这个问题,并提供简单的配置案例.[实验环境]Cacti Server:centos6.4_x86_64Windows Client:XP 32位 (192.168.8.154)[第一部分 cacti模板介绍]       在实验之前,咱们需要先了解"模板"这个概念.Cacti定义了三种类

实战Nagios网络监控(2)—— Nagios+Nrpe监控其他主机

本次实验在上次实验的环境下进行:实战Nagios网络监控(1)--监控本机运行状态和Mysq主机 需要的包:nagios-plugins-2.1.1.tar.gz nrpe-2.15.tar.gz 服务器端:server1.example.com        172.25.254.1 新监控端:server2.example.com        172.25.254.2 实验前提: /etc/init.d/httpd start /etc/init.d/nagios start /etc/i

nagios网络监控

nagios网络监控

实战Cacti网络监控(2)——搭建Spine轻量级框架

本次实验接着上次实验的环境.实战Cacti网络监控(1)--基础安装配置     (1)在物理主机上:        <1>yum install net-snmp.x86_64  -y    ##安装snmp服务             yum install net-snmp-utils.x86_64 -y        <2>vim /etc/snmp/snmpd.conf 41 #com2sec notConfigUser  default       public 42

开源监控解决方案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