Adding Hosts to Nagios

In my first nagios tutorial I talked you through the instillation process required for nagios, if you have not yet installed nagios please follow my tutorial, Installing Nagios on Ubuntu.

In this tutorial we are going to go through adding hosts to nagios, sounds simple rite, well there’s a bit more to it then you think, but its not too difficult and its great to see nagios in action after all this time setting it up.

So where to start, well that’s look at the structure of the nagios config files, this diagram outlines how all the config files link together.

Unless you changed it your config files should be in the /usr/local/nagios/etc:

Notes on Config Files

  1. Lines that start with # are ignored buy nagios so are used as human readable comments
  2. Variables are Case-Sensitive
  3. Variables must start at the beginning of a line, no white space before them.

Main Configuration File
This file is read first buy the Nagios Daemon, basically its job is to point to the rest of the configuration files, if we make a new config file we need to add its location to this file before nagios can read it.

Resource File
This is where user created macros are stored, however the main purpose of these files is to hide sensitive information, such as password, from the CGI’s

Object Definition Files
This is where we define hosts, services, host groups, contacts, contact groups, commands, etc.. Basically this is were you define anything you want nagios to monitor and choose how you want it to monitor them.

CGI Config File
This is where you outline the CGI’s configuration, this also has a reference to the main config file so the cig’s know how you configured nagios.

Ok, so now that’s actually add some settings, first make a new object definition file buy typing:

sudo nano /usr/local/nagios/etc/objects/newhost.cfg

and adding the following lines to it:

# Define a host for the local machine

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               google.com
        alias                   google.com
        address                 www.google.com
        }

###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################

# Define a service to "ping" the local machine

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       google.com
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

# 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                             generic-service         ; Name of service template to use
        host_name                       google.com
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }

now edit your main config file to tell it the location of the new config file:

sudo nano /usr/local/nagios/etc/nagios.cfg

add the folowwing line to the file

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

Now restart your nagios daemon:

sudo /etc/init.d/nagios restart 

and hay presto your nagios server is now monitoring google. Ok so how did all that work, well first lets go through the newhosts.cfg file:

define host
Here we define a new host:
use linux-server: We use Linux-Server because its the easiest template to use, more on this later

host_name google.com: This is the host name, this is how you reference your hosts settings, it doesn’t have to be its address just something meaningful related to the host

alias google.com: This is the long name for the host, this is only used for display purposes

address www.google.com: This is important, its the actual address for the host, either a DNS name or IP address will work here.

define service
This is were we define the services on each host, for google we are only going to check if its alive(ping) and check to see if its web server is running (http). We need to two services for this, however the settings are the same for each:

use This is the service template, use generic-serivce is the standard template.

host_name This is where we reference what host we want the service connected to, use the name of the host defined earlier.

service_description This is the name the user will see on the nagios web page

check_command This is the command we are going to run to test if the service is running, more on commands later.

So what about the nagios.cfg, why did we add that line to it, well as we created a new cfg file we need to tell nagios about it, you can either have one massive file for each host or make a new file for each one, however if you make a new file for each one you have to add it to the nagios.cfg.

Rite, hopefully that has explained the Hosts file to you, now would be a good idea to add your own hosts, start with something simple like another website, try “yahoo.com”, if you encounter problems check my config file for google and yahoo here. Remember to restart nagios after changing any config files with:

sudo /etc/init.d/nagios restart 

if you get any errors when restarting run the following command to check for problems with your config files

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Please leave any comments for feeback.

时间: 2024-08-07 01:23:16

Adding Hosts to Nagios的相关文章

一件自动化安装nagios服务

声明 作者:昨夜星辰 博客:http://yestreenstars.blog.51cto.com/ 本文由本人创作,如需转载,请注明出处,谢谢合作! 目的 一键自动化安装nagios服务. 环境 OS: CentOS 6.2 32 nagios: 4.0.7 nagios-plugins: 2.0.3 nrpe: 2.15 配置 #!/bin/bash # Script Name: One-key Automatic Install Nagios Service # Author: yestr

网站监控系统安装部署(zabbix,nagios)

zabbix分布式监控系统安装部署 官方网站链接 https://www.zabbix.com/documentation/2.0/manual/installation 安装环境说明 参考地址 http://mayulin.blog.51cto.com/1628315/514371 虚拟机两台 zabbix_server 192.168.50.141 zabbix_agentd 192.168.50.139 os:CentOS 6.3 x64 软件: zabbix-2.0.6 需求软件:htt

python-Django监控系统二次开发Nagios

1.Nagios安装 yum install -y nagios.i686 yum install -y nagios-plugins-all.i686 安装完后会在apache的配置文件目录下/etc/httpd/conf.d/产生一个外部的配置文件nagios.conf service httpd start service nagios start default user nagiosadmin password nagiosadmin 2.配置文件生成器 Django前期的收集主机信息

自动化运维工具之Zabbixzabbix发现_自动注册及web页面状态监控(四)

网络发现(Network Discovery) **网络发现是zabbix最具有特色的功能之一,它能根据用户实现定义好的规则自动添加监控主机和服务等 -->speed up Zabbix deployment -->simplify administration -->use Zabbix in rapidly changing environments without excessive administration **Zabbix的网络发现功能可基于如下信息进行: -->IP

Apache Ambari 2.4 发布,Hadoop 管理监控

Apache Ambari 2.4 发布了,Apache Ambari是一种基于Web的工具,支持Apache Hadoop集群的供应.管理和监控(腾云科技ty300.com).Ambari目前已支持大多数Hadoop组件,包括HDFS.MapReduce.Hive.Pig. Hbase.Zookeper.Sqoop和Hcatalog等(基础教程qkxue.net). Apache Ambari 支持HDFS.MapReduce.Hive.Pig.Hbase.Zookeper.Sqoop和Hca

基于OpenDaylight和Mininet的试验床平台搭建

##########################################平台架构######################################### 一.虚拟机安装和镜像加载 *本部分过程非常简单,所以不详细描述,基本流程稍微提一下. 1. 虚拟机软件:安装虚拟机软件主要有VMware Station, VirtualBox等,后者免费,下载网址为:https://www.virtualbox.org/wiki/Downloads,本文以VMware Station为例

mininet安装,使用

http://mininet.org/download/ -----------------------------------源码安装------------------------------------------------------------------- 1.从GITHUB上获取mininet源码 git clone git://github.com/mininet/mininet 2.安装 mininet/util/install.sh [options] 参数包括 -a: 全

用shell脚本自动化安装hadoop

一.概述 1.1 简介 本文主要介绍怎样用 shell 实现 hadoop 的自动化安装.关于手动安装 hadoop 的步骤,可以查看以下链接: http://www.cnblogs.com/13bear/articles/3700842.html 1.2 环境 OS: CentOS release 6.4 (Final) Hadoop:Apache hadoop V1.2.1 1.3 脚本下载 http://pan.baidu.com/s/1eQHyfZk 二.脚本综述 2.1 脚本目录列表

【转载】FslSge

Introduction This is a quick walk through to get Grid Engine going on Linux for those who would like to use it for something like FSL. This documentation is a little old, being written when the Grid Engine software was owned by Sun and often referred