1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
5 | <meta http-equiv="Content-Style-Type" content="text/css" /> |
---|
6 | <meta name="generator" content="pandoc" /> |
---|
7 | <title>Nagios Installation and Configuration</title> |
---|
8 | <style type="text/css">code{white-space: pre;}</style> |
---|
9 | <link rel="stylesheet" href="../../style.css" type="text/css" /> |
---|
10 | </head> |
---|
11 | <body> |
---|
12 | <div id="header"> |
---|
13 | <h1 class="title">Nagios Installation and Configuration</h1> |
---|
14 | </div> |
---|
15 | <div id="TOC"> |
---|
16 | <ul> |
---|
17 | <li><a href="#introduction"><span class="toc-section-number">1</span> Introduction</a><ul> |
---|
18 | <li><a href="#goals"><span class="toc-section-number">1.1</span> Goals</a></li> |
---|
19 | <li><a href="#notes"><span class="toc-section-number">1.2</span> Notes</a></li> |
---|
20 | </ul></li> |
---|
21 | <li><a href="#exercises"><span class="toc-section-number">2</span> Exercises</a><ul> |
---|
22 | <li><a href="#create-a-plugin-script"><span class="toc-section-number">2.1</span> 1. Create a plugin script</a></li> |
---|
23 | <li><a href="#configure-the-plugin"><span class="toc-section-number">2.2</span> 2. Configure the plugin</a></li> |
---|
24 | <li><a href="#add-a-service-check"><span class="toc-section-number">2.3</span> 3. Add a service check</a></li> |
---|
25 | </ul></li> |
---|
26 | </ul> |
---|
27 | </div> |
---|
28 | <h1 id="introduction"><a href="#introduction"><span class="header-section-number">1</span> Introduction</a></h1> |
---|
29 | <h2 id="goals"><a href="#goals"><span class="header-section-number">1.1</span> Goals</a></h2> |
---|
30 | <ul> |
---|
31 | <li>Install and configure Nagios disk space plugin</li> |
---|
32 | </ul> |
---|
33 | <h2 id="notes"><a href="#notes"><span class="header-section-number">1.2</span> Notes</a></h2> |
---|
34 | <ul> |
---|
35 | <li>Commands preceded with "$" imply that you should execute the command as a general user - not as root.</li> |
---|
36 | <li>Commands preceded with "#" imply that you should be working as root.</li> |
---|
37 | <li>Commands with more specific command lines (e.g. "rtrX>" or "mysql>") imply that you are executing commands on remote equipment, or within another program.</li> |
---|
38 | </ul> |
---|
39 | <h1 id="exercises"><a href="#exercises"><span class="header-section-number">2</span> Exercises</a></h1> |
---|
40 | <p>It is possible to alert on disk space thresholds with the existing check_snmp plugin, but it is rather fiddly to set up (because, for example, you have to manually map the filesystem mountpoint to the OID index). So the approach given here is to install a new plugin, which handles this for you.</p> |
---|
41 | <h2 id="create-a-plugin-script"><a href="#create-a-plugin-script"><span class="header-section-number">2.1</span> 1. Create a plugin script</a></h2> |
---|
42 | <p>Create a file /usr/local/bin/check_hrstorage.pl with the following contents (the #! line must be the very first line in the file)</p> |
---|
43 | <pre><code>#!/usr/bin/perl -w |
---|
44 | |
---|
45 | unless ($ARGV[2]) { |
---|
46 | print STDERR "Usage: $0 <host> <community> <mountpoint> [<warn%> [<crit%>]]\n"; |
---|
47 | exit 3; |
---|
48 | } |
---|
49 | |
---|
50 | my $res = `snmpwalk -On -Oq -r 2 -t 1 -c '$ARGV[1]' -v2c '$ARGV[0]' .1.3.6.1.2.1.25.2.3`; |
---|
51 | unless ($res =~ /^\.1.3.6/) { |
---|
52 | print "Unable to contact via SNMP\n"; |
---|
53 | exit 3; |
---|
54 | } |
---|
55 | |
---|
56 | my $table = {}; |
---|
57 | my $index; |
---|
58 | foreach my $line (split(/\n/,$res)) { |
---|
59 | my ($k,$v) = split(/ /,$line,2); |
---|
60 | $table->{$k} = $v; |
---|
61 | if ($v eq $ARGV[2] && $k =~ /^.1.3.6.1.2.1.25.2.3.1.3\.(\d+)$/) { |
---|
62 | $index = $1; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | unless ($index) { |
---|
67 | print "Unable to find mountpoint $ARGV[2]\n"; |
---|
68 | exit 3; |
---|
69 | } |
---|
70 | |
---|
71 | my $size = $table->{".1.3.6.1.2.1.25.2.3.1.5.$index"}; |
---|
72 | $size += 4294967296 if $size < 0; |
---|
73 | my $used = $table->{".1.3.6.1.2.1.25.2.3.1.6.$index"}; |
---|
74 | $used += 4294967296 if $used < 0; |
---|
75 | my $percent = $used * 100.0 / $size; |
---|
76 | |
---|
77 | my $block = $table->{".1.3.6.1.2.1.25.2.3.1.4.$index"}; |
---|
78 | if ($block =~ /^(\d+)/) { |
---|
79 | $block = $1; |
---|
80 | $size = $size * 1.0 * $block / 1024 / 1024; |
---|
81 | $used = $used * 1.0 * $block / 1024 / 1024; |
---|
82 | } |
---|
83 | printf "%.2f%% used (%d out of %d MB)\n", $percent, $used, $size; |
---|
84 | if ($ARGV[4] && $percent >= $ARGV[4]) { |
---|
85 | exit 2; # Critical |
---|
86 | } |
---|
87 | if ($ARGV[3] && $percent >= $ARGV[3]) { |
---|
88 | exit 1; # Warning |
---|
89 | } |
---|
90 | exit 0; |
---|
91 | </code></pre> |
---|
92 | <p>Make it executable using the following command:</p> |
---|
93 | <pre><code># chmod +x /usr/local/bin/check_hrstorage.pl</code></pre> |
---|
94 | <h2 id="configure-the-plugin"><a href="#configure-the-plugin"><span class="header-section-number">2.2</span> 2. Configure the plugin</a></h2> |
---|
95 | <p>Create a new configuration file:</p> |
---|
96 | <pre><code># editor /etc/nagios-plugins/config/hrstorage.cfg</code></pre> |
---|
97 | <pre><code>define command { |
---|
98 | command_name check_hrstorage |
---|
99 | command_line /usr/local/bin/check_hrstorage.pl '$HOSTADDRESS$' '$ARG1$' '$ARG2$' '$ARG3$' '$ARG4$' |
---|
100 | }</code></pre> |
---|
101 | <h2 id="add-a-service-check"><a href="#add-a-service-check"><span class="header-section-number">2.3</span> 3. Add a service check</a></h2> |
---|
102 | <p>A service check can now be added to an individual host, or to a hostgroup. For example:</p> |
---|
103 | <pre><code>define service { |
---|
104 | host_name noc |
---|
105 | service_description Disk space / |
---|
106 | check_command check_hrstorage!NetManage!/!80!90 |
---|
107 | use generic-service |
---|
108 | notification_interval 0 |
---|
109 | }</code></pre> |
---|
110 | <p>The parameters to this check_hrstorage are:</p> |
---|
111 | <ul> |
---|
112 | <li>SNMP community</li> |
---|
113 | <li>Filesystem mount point</li> |
---|
114 | <li>Warning threshold (%)</li> |
---|
115 | <li>Critical threshold (%)</li> |
---|
116 | </ul> |
---|
117 | </body> |
---|
118 | </html> |
---|