Curve the way to save the nation, using the temperature of the switch to determine whether the air-conditioning power.
1, expect interactive login switch reading temperature value
The code is as follows |
Copy Code |
[Root@nagios opt]# Cat 123.exp #!/usr/bin/expect-f Set User User Set passwd password Spawn Telnet 192.168.0.254 Expect "Username:" Send--"$userr" Expect "Password:" Send--"$PASSWDR" Expect "" Send--"Dis ENVR" Expect "" Send--"QUITR" Expect EOF |
2, add a nagios monitoring script
code is as follows |
copy code |
[Root@nagios opt]# Cat/usr/local/nagios/libexec/check_temp #!/bin/bash Expect/opt/123.exp >/opt/123.log temp= ' awk '/hotspot/{print $} '/opt/123.log ' State_ok=0 State_warning=1 state_critical=2 State_unknown=3 If ["$#" = "4"] Then #Set variables ARG=${4} W=$2 C=$4 If [$temp-ge $w-a $temp-lt $c] Then echo "Warning:room temperature $temp °c" exitstatus= $STATE _warning elif [$temp-ge $c] Then echo "Critical:room temperature $temp °c" exitstatus= $STATE _critical Else echo "Ok:room temperature $temp °c." exitstatus= $STATE _OK Fi Fi Exit $exitstatus |
3. Add command
The code is as follows |
Copy Code |
[Root@nagios opt]# tail-5/usr/local/nagios/etc/objects/commands.cfg # ' check_temp ' command definition Define Command{ Command_name check_temp Command_line $USER 1$/check_temp-w $ARG 1$-C $ARG 2$ } |
4. Modify Nrpe.cfg
The code is as follows |
Copy Code |
[Root@nagios opt]# grep "Temp"/usr/local/nagios/etc/nrpe.cfg Command[check_temp]=/usr/local/nagios/libexec/check_temp-w 30-c 33 |
5. Add Monitoring items
The code is as follows |
Copy Code |
[Root@nagios opt]# tail-6/usr/local/nagios/etc/objects/localhost.cfg Define Service{ Use Generic-service HOST_NAME localhost Service_description check_temp Check_command check_nrpe!check_temp } |
Nagios main functions
Network Service Monitoring (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)
Host resource monitoring (CPU load, disk usage, system logs) Also includes a Windows host (using nsclient++ plugin)
You can specify the plugin you write to monitor any situation (temperature, warning ...) by collecting data over the network.
can be configured by configuring Nagios remote Execute plug-in remote scripting
Remote monitoring supports SSH or SSL plus channel monitoring
Simple plugin design allows users to easily develop the inspection services they need, supporting many development languages (shell scripts, C + +, Perl, Ruby, Python, PHP, C #, etc.
contains a lot of graphical data plugins (Nagiosgraph, Nagiosgrapher, Pnp4nagios, etc.)
Parallel service checking The
is able to define the hierarchy of network hosts, allowing for a step-by-step check, starting with the parent host to check
when a service or host problem occurs, notify by email, pager, SMS, or any user-defined plugin
Ability to customize event handling to reactivate a problematic service or host
Automatic log loop
supports redundant monitoring
includes web interface to view current network status, notifications, problem histories, log files, etc.