| 1 | % Nagios Installation and Configuration | 
|---|
| 2 | % | 
|---|
| 3 |  | 
|---|
| 4 | # Introduction | 
|---|
| 5 |  | 
|---|
| 6 | ## Goals | 
|---|
| 7 |  | 
|---|
| 8 | * Optional exercises for Nagios | 
|---|
| 9 |  | 
|---|
| 10 | ## Notes | 
|---|
| 11 |  | 
|---|
| 12 | * Commands preceded with "$" imply that you should execute the command as | 
|---|
| 13 | a general user - not as root. | 
|---|
| 14 | * Commands preceded with "#" imply that you should be working as root. | 
|---|
| 15 | * Commands with more specific command lines (e.g. "rtrX>" or "mysql>") | 
|---|
| 16 | imply that you are executing commands on remote equipment, or within | 
|---|
| 17 | another program. | 
|---|
| 18 |  | 
|---|
| 19 | # Exercises | 
|---|
| 20 |  | 
|---|
| 21 |  | 
|---|
| 22 |  | 
|---|
| 23 | # PART IX - Optional Exercises | 
|---|
| 24 |  | 
|---|
| 25 | ## 1. Check that nagios is Running | 
|---|
| 26 |  | 
|---|
| 27 | As opposed to just checking that a web server is running on the classroom PCs, | 
|---|
| 28 | you could also check that t | 
|---|
| 29 | he nagios3 service is available, by requesting the | 
|---|
| 30 | /nagios3/ path. This means passing extra options to the check_http plugin. | 
|---|
| 31 |  | 
|---|
| 32 | For a description of the available options, type this: | 
|---|
| 33 |  | 
|---|
| 34 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 35 | # /usr/lib/nagios/plugins/check_http                                    (short help) | 
|---|
| 36 | # /usr/lib/nagios/plugins/check_http --help                     (detailed help) | 
|---|
| 37 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 38 |  | 
|---|
| 39 | and of course you can browse the online nagios documentation or google | 
|---|
| 40 | for information on check_http. You can even run the plugin by hand to | 
|---|
| 41 | perform a one-shot service check: | 
|---|
| 42 |  | 
|---|
| 43 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 44 | # /usr/lib/nagios/plugins/check_http -H localhost -u /nagios3/ | 
|---|
| 45 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 46 |  | 
|---|
| 47 | So the goal is to configure nagios to call check_http in this way. | 
|---|
| 48 |  | 
|---|
| 49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 50 | {hint, /etc/nagios-plugins/config/http.cfg) | 
|---|
| 51 |  | 
|---|
| 52 | define command{ | 
|---|
| 53 | command_name    check_http_url | 
|---|
| 54 | command_line    /usr/lib/nagios/plugins/check_http -H '$HOSTADDRESS$' -u '$ARG1$' | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | (hint, /etc/nagios3/conf.d/services_nagios2.cfg_ | 
|---|
| 58 |  | 
|---|
| 59 | define service { | 
|---|
| 60 | hostgroup_name                  nagios-servers | 
|---|
| 61 | service_description             NAGIOS | 
|---|
| 62 | check_command                   check_http_url!/nagios3/ | 
|---|
| 63 | use                             generic-service | 
|---|
| 64 | } | 
|---|
| 65 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 66 |  | 
|---|
| 67 | and of course you'll need to create a hostgroup called nagios-servers to | 
|---|
| 68 | link to this service check. (hint, /etc/nagios3/conf.d/hostgroups_nagios2.cfg) | 
|---|
| 69 |  | 
|---|
| 70 | Once you have done this, check that Nagios warns you about failing | 
|---|
| 71 | authentication (because it's trying to fetch the page without providing | 
|---|
| 72 | the username/password). There's an extra parameter you can pass to | 
|---|
| 73 | check_http to provide that info, so we need to define a new command | 
|---|
| 74 | with an additional argument: | 
|---|
| 75 |  | 
|---|
| 76 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 77 | define command{ | 
|---|
| 78 | command_name    check_http_url_auth | 
|---|
| 79 | command_line    /usr/lib/nagios/plugins/check_http -H '$HOSTADDRESS$' -u '$ARG1$' -a '$ARG2$' | 
|---|
| 80 | } | 
|---|
| 81 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 82 |  | 
|---|
| 83 | And you invoke it: | 
|---|
| 84 |  | 
|---|
| 85 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 86 | check_command                   check_http_url_auth!/nagios3/!nagiosadmin:password | 
|---|
| 87 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 88 |  | 
|---|
| 89 | WARNING: in the tradition of "Debian Knows Best", their definition of the | 
|---|
| 90 | check_http command in /etc/nagios-plugins/config/http.cfg | 
|---|
| 91 | is *not* the same as that recommended in the nagios3 documentation. | 
|---|
| 92 | It is missing $ARG1$, so any parameters to pass to check_http are | 
|---|
| 93 | ignored. So you might think you are monitoring /nagios3/ but actually | 
|---|
| 94 | you are monitoring root! | 
|---|
| 95 |  | 
|---|
| 96 | This is why we had to make a new command definition "check_http_url". | 
|---|
| 97 | You could make a more specific one like "check_nagios", or you could | 
|---|
| 98 | modify the Ubuntu check_http definition to fit the standard usage. | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | ## 2. Check that SNMP is running on the classroom NOC | 
|---|
| 102 |  | 
|---|
| 103 |  | 
|---|
| 104 | This exercise will not work if you did not complete the installation of additional | 
|---|
| 105 | SNMP MIBs at the start of the week and configure /etc/snmp/snmp.conf properly. Please refer to the original snmp exercises if you are unsure. | 
|---|
| 106 |  | 
|---|
| 107 | First you will need to add in the appropriate service check for SNMP in the file | 
|---|
| 108 | /etc/nagios3/conf.d/services_nagios2.cfg. This is where Nagios is impressive. There | 
|---|
| 109 | are hundreds, if not thousands, of service checks available via the various Nagios | 
|---|
| 110 | sites on the web. You can see what plugins are installed by Ubuntu in the nagios3 | 
|---|
| 111 | package that we've installed by looking in the following directory: | 
|---|
| 112 |  | 
|---|
| 113 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 114 | # ls /usr/lib/nagios/plugins | 
|---|
| 115 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 116 |  | 
|---|
| 117 | As you'll see there is already a check_snmp plugin available to us. If you are | 
|---|
| 118 | interested in the options the plugin takes you can execute the plugin from the | 
|---|
| 119 | command line by typing: | 
|---|
| 120 |  | 
|---|
| 121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 122 | # /usr/lib/nagios/plugins/check_snmp                                    (short help) | 
|---|
| 123 | # /usr/lib/nagios/plugins/check_snmp --help                             (detailed help) | 
|---|
| 124 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 125 |  | 
|---|
| 126 | to see what options are available, etc. You can use the check_snmp plugin and | 
|---|
| 127 | Nagios to create very complex or specific system checks. | 
|---|
| 128 |  | 
|---|
| 129 | Now to see all the various service/host checks that have been created using the | 
|---|
| 130 | check_snmp plugin you can look in /etc/nagios-plugins/config/snmp.cfg. You will | 
|---|
| 131 | see that there are a lot of preconfigured checks using snmp, including: | 
|---|
| 132 |  | 
|---|
| 133 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 134 | snmp_load | 
|---|
| 135 | snmp_cpustats | 
|---|
| 136 | snmp_procname | 
|---|
| 137 | snmp_disk | 
|---|
| 138 | snmp_mem | 
|---|
| 139 | snmp_swap | 
|---|
| 140 | snmp_procs | 
|---|
| 141 | snmp_users | 
|---|
| 142 | snmp_mem2 | 
|---|
| 143 | snmp_swap2 | 
|---|
| 144 | snmp_mem3 | 
|---|
| 145 | snmp_swap3 | 
|---|
| 146 | snmp_disk2 | 
|---|
| 147 | snmp_tcpopen | 
|---|
| 148 | snmp_tcpstats | 
|---|
| 149 | snmp_bgpstate | 
|---|
| 150 | check_netapp_uptime | 
|---|
| 151 | check_netapp_cupuload | 
|---|
| 152 | check_netapp_numdisks | 
|---|
| 153 | check_compaq_thermalCondition | 
|---|
| 154 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 155 |  | 
|---|
| 156 | And, even better, you can create additional service checks quite easily. | 
|---|
| 157 | For the case of verifying that snmpd (the SNMP service on Linux) is running we | 
|---|
| 158 | need to ask SNMP a question. If we don't get an answer, then Nagios can assume | 
|---|
| 159 | that the SNMP service is down on that host. When you use service checks such as | 
|---|
| 160 | check_http, check_ssh and check_telnet this is what they are doing as well. | 
|---|
| 161 |  | 
|---|
| 162 | In our case, let's create a new service check and call it "check_system". This | 
|---|
| 163 | service check will connect with the specified host, use the private community | 
|---|
| 164 | string we have defined in class and ask a question of snmp on that host - in this | 
|---|
| 165 | case we'll ask about the System Description, or the OID "sysDescr.0" - | 
|---|
| 166 |  | 
|---|
| 167 | To do this start by editing the file /etc/nagios-plugins/config/snmp.cfg: | 
|---|
| 168 |  | 
|---|
| 169 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 170 | # editor /etc/nagios-plugins/config/snmp.cfg | 
|---|
| 171 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 172 |  | 
|---|
| 173 | At the top (or the bottom, your choice) add the following entry to the file: | 
|---|
| 174 |  | 
|---|
| 175 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 176 | # 'check_system' command definition | 
|---|
| 177 | define command{ | 
|---|
| 178 | command_name    check_system | 
|---|
| 179 | command_line    /usr/lib/nagios/plugins/check_snmp -H '$HOSTADDRESS$' -C '$ARG1$' -o sysDescr.0 | 
|---|
| 180 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 181 | } | 
|---|
| 182 |  | 
|---|
| 183 | COPY and PASTE this. Do not type this by hand and make sure that the command_line line | 
|---|
| 184 | does not wrap. | 
|---|
| 185 |  | 
|---|
| 186 | Note that "command_line" is a single line. If you copy and paste in | 
|---|
| 187 | your editor, the line may not wrap properly and you may have to manually | 
|---|
| 188 | "join" the two lines so they are one. | 
|---|
| 189 |  | 
|---|
| 190 | Now you need to edit the file /etc/nagios3/conf.d/services_nagios2.cfg and add | 
|---|
| 191 | in this service check. We'll run this check against all our servers in the | 
|---|
| 192 | classroom, or the hostgroup "debian-servers" | 
|---|
| 193 |  | 
|---|
| 194 | Edit the file /etc/nagios3/conf.d/services_nagios2.cfg | 
|---|
| 195 |  | 
|---|
| 196 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 197 | # editor /etc/nagios3/conf.d/services_nagios2.cfg | 
|---|
| 198 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 199 |  | 
|---|
| 200 | At the bottom of the file add the following definition: | 
|---|
| 201 |  | 
|---|
| 202 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 203 | # check that snmp is up on all servers | 
|---|
| 204 | define service { | 
|---|
| 205 | hostgroup_name                  snmp-servers | 
|---|
| 206 | service_description             SNMP | 
|---|
| 207 | check_command                   check_system!xxxxxx | 
|---|
| 208 | use                             generic-service | 
|---|
| 209 | notification_interval           0 ; set > 0 if you want to be renotified | 
|---|
| 210 | } | 
|---|
| 211 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 212 |  | 
|---|
| 213 | The "xxxxxx" is the community string previously (or to be) defined in class. | 
|---|
| 214 |  | 
|---|
| 215 | Note that we have included our own community string here vs. hard-coding | 
|---|
| 216 | it in the snmp.cfg file earlier. You must change the "xxxxx" to be the snmp | 
|---|
| 217 | community string given in class or this check will not work. | 
|---|
| 218 |  | 
|---|
| 219 | Now we must create the "snmp-servers" group in our hostgroups_nagios2.cfg file. | 
|---|
| 220 | Edit the file /etc/nagios3/conf.d/hostgroups_nagios2.cfg and go to the end of the | 
|---|
| 221 | file. Add in the following hostgroup definition: | 
|---|
| 222 |  | 
|---|
| 223 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 224 | # A list of snmp-enabled devices on which we wish to run the snmp service check | 
|---|
| 225 | define hostgroup { | 
|---|
| 226 | hostgroup_name       snmp-servers | 
|---|
| 227 | alias        snmp servers | 
|---|
| 228 | members      noc,localhost,pc1,pc2,pc3,pc4...pc36,rtr1,rtr2,rtr3...rtr9 | 
|---|
| 229 | } | 
|---|
| 230 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 231 |  | 
|---|
| 232 | Note that for "members" you can add in all PCs and routers as they should all | 
|---|
| 233 | have snmp up and running at this time. Remember to EXCLUDE our pc and use | 
|---|
| 234 | localhost instead. | 
|---|
| 235 |  | 
|---|
| 236 | Now verify that your changes are correct and restart Nagios. | 
|---|
| 237 |  | 
|---|
| 238 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 239 | # service nagios3 restart | 
|---|
| 240 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 241 |  | 
|---|
| 242 | **** Defect / Bug in Ubuntu 12.04 LTS *** | 
|---|
| 243 |  | 
|---|
| 244 | The net-snmp 5.6.x package appears to not install one of the IANA mibs (IANAifType-MIB). | 
|---|
| 245 | This causes a MIB error, which, in turn causes the snmp check plugin to fail. To fix | 
|---|
| 246 | this problem do the following (as root): | 
|---|
| 247 |  | 
|---|
| 248 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 249 | # cd /usr/share/mibs | 
|---|
| 250 | # wget http://www.iana.org/assignments/ianaiftype-mib/ianaiftype-mib | 
|---|
| 251 | # mv ianaiftype-mib ianaiftype-mib.my | 
|---|
| 252 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
|---|
| 253 |  | 
|---|
| 254 | And, now you can continue. | 
|---|
| 255 |  | 
|---|
| 256 | If you click on the Service Detail menu choice in web interface you should see | 
|---|
| 257 | the SNMP check appear for the noc host, or for any other hosts you may have | 
|---|
| 258 | included on the "members" line above. | 
|---|
| 259 |  | 
|---|
| 260 |  | 
|---|
| 261 |  | 
|---|