Chinaunix首页 | 论坛 | 博客
  • 博客访问: 206716
  • 博文数量: 53
  • 博客积分: 2059
  • 博客等级: 大尉
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-30 03:03
文章分类
文章存档

2012年(4)

2011年(19)

2010年(30)

分类: LINUX

2011-05-17 13:49:51

最近由于一些原因,找了一个nagios的插件来实现基于地理位置的监控,实现起来有一个地方需要注意,在此做些记录,作为以后的总结.
插件的地址为:
官方有比较详细的安装文档:
  1. 1. copy/move *.php,*.csv,*.htm to nagios/share
  2. 2. copy/move *.png, *.gif to /nagios/share/images
  3. 3. get a google map API from google, Add this key to map.htm
  4. 4. edit hosgroups.csv, add your hostgroups and coord. (,) see example in hostgroups.csv
  5. 5. edit services.csv, add your services and coord (,,) see example in services.csv
  6. 6. edit nagios_hg.php, add nagios username/password and nagiosserver.
  7. start nagios/map.htm in a webbrowser....
按照官方文档安装,
1.创建目录hostgroupstatus
mkdir hostgroupstatus
cp naghostgroups.tar hostgroupstatus
tar xvf naghostgroups.tar 
cp *.php *.csv *.htm /usr/local/nagios/share/
cp *.png *.gif /usr/local/nagios/share/images/
2,获取google地图的API,地址为
此处需要google的账号,获取API以后,由于map.htm一处代码有些问题,所以复制
替换掉map.htm之中
  1. script src=" google maps API key>" type="text/javascript">
3,编辑hosgroups.csv,格式如下
  1. vm servers,23.130257185291032,113.2635498046875
  2. application servers,35.689488,139.691706
其中第一对应,nagios的hostgroup,后面的对应谷歌地图相应位置的地理坐标。
如何获取响应位置的坐标?
首先,在google地图中,搜索相应地理位置。
然后在IE,地址栏中输入如下代码:
  1. javascript:void(prompt('',gApplication.getMap().getCenter()));
会有对话框出现,显示该地理位置的经度和纬度。
4.编辑service.csv,格式如下
  1. urg-isa01,Ping,
  2. urg-sw-01,Ping,
其中第一个代表,相应hostgroup的主机,Ping代表ping服务,可以根据主机的检测机制,来确定该服务,一定要保证服务大小写和配置文件中的相同,否则获取不到该服务的状态,因为在service.php中有如下代码。
  1. $file = file_get_contents('http://' . $username . ':' . $password . '@' . $nagiosserver . '/nagios/cgi-bin/extinfo.cgi?type=2&host=' . $host . '&service=' . $service . '');
  2. $status = get_string_between($file, "
    ");
  3. if ($status == "OK") {$col1="green";}
  4. if ($status == "WARNING"){ $col1="yellow";}
  5. if ($status == "CRITICAL") {$col1="red";}
  6. if ($status == "UNKNOWN") {$col1="orange";}
后面的两个坐标,前面一个代表监控主机的地理位置坐标,后面一个代表远程服务器的地理坐标。
5,编辑nagios_hg.php,把nagios的账号,密码和主机地址,写入该文件,去掉<>号。
6,打开浏览器,输入如下地址
就能看到你的基于地理位置的监控了。



阅读(3360) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~