1 | APRICOT 2010 |
---|
2 | Network Management and Monitoring Workshop |
---|
3 | |
---|
4 | |
---|
5 | Nagios and Request Tracker Ticket Creation |
---|
6 | ------------------------------------------ |
---|
7 | |
---|
8 | To configure RT and Nagios so that alerts from Nagios automatically |
---|
9 | create tickets require a few steps: |
---|
10 | |
---|
11 | * Create a proper contact entry for Nagios in |
---|
12 | /etc/nagios3/conf.d/contacts_nagios2.cfg |
---|
13 | * Create the proper command in Nagios to use the rt-mailgate |
---|
14 | interface. The command is defined in /etc/nagios3/commands.cfg |
---|
15 | |
---|
16 | These next two items should already be done in RT if you have |
---|
17 | finished the RT exercises. |
---|
18 | |
---|
19 | * Install the rt-mailgate software and configure it properly |
---|
20 | in your /etc/aliases file for your MTA in use. |
---|
21 | * Configure the appropriate queues in RT to receive emails |
---|
22 | passed to it from Nagios via the rt-mailgate software. |
---|
23 | |
---|
24 | 1.) Configure a Contact in Nagios |
---|
25 | --------------------------------- |
---|
26 | |
---|
27 | - Edit the file /etc/nagios3/conf.d/contacts_nagios2.cfg |
---|
28 | |
---|
29 | # vi /etc/nagios3/conf.d/contacts_nagios2.cfg |
---|
30 | |
---|
31 | - In this file we will first add a new contact name under |
---|
32 | the default root contact entry. The new contact should |
---|
33 | look like this: |
---|
34 | |
---|
35 | define contact{ |
---|
36 | contact_name net |
---|
37 | alias RT Alert Queue |
---|
38 | service_notification_period 24x7 |
---|
39 | host_notification_period 24x7 |
---|
40 | service_notification_options c |
---|
41 | host_notification_options d |
---|
42 | service_notification_commands notify-service-ticket-by-email |
---|
43 | host_notification_commands notify-host-ticket-by-email |
---|
44 | email net@pcX.mgmt |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | - the service_notification_option of "c" means only notify once a |
---|
49 | service is considered "critical" by Nagios (i.e. down). The |
---|
50 | host_notification_option of "d" means down. By specify only "c" |
---|
51 | and "d" this means that notifications will not be sent for other |
---|
52 | states. |
---|
53 | |
---|
54 | - Note the email address in use "net@pcX.mgmt" - this is important |
---|
55 | as this was previously defined for RT. |
---|
56 | |
---|
57 | *** Be sure to change this entry to be correct for your machine *** |
---|
58 | |
---|
59 | - Now we must create a Contact Group that contains this contact. |
---|
60 | We will call this group "tickets." Do this at the end of the file: |
---|
61 | |
---|
62 | define contactgroup{ |
---|
63 | contactgroup_name tickets |
---|
64 | alias email to ticket system for Trac |
---|
65 | members net,root |
---|
66 | } |
---|
67 | |
---|
68 | - You could leave off "root" as a member, but we've left this on to |
---|
69 | have another user that receives email to help us troubleshoot if |
---|
70 | there are issues. |
---|
71 | |
---|
72 | - Now that your contact have been created you need to create the commands |
---|
73 | that were referenced in the initial contact creation above, these are |
---|
74 | "notify-service-ticket-by-email" and "notify-host-ticket-by-email" |
---|
75 | |
---|
76 | |
---|
77 | 2.) Update Nagios Commands |
---|
78 | -------------------------- |
---|
79 | |
---|
80 | - To create the notify-service-ticket-by-email and notify-host-ticket-by-email |
---|
81 | commands we need to edit the file /etc/nagios3/commands.cfg. |
---|
82 | |
---|
83 | # vi /etc/nagios3/commands.cfg |
---|
84 | |
---|
85 | - In this file you should have two command definitions at the top of the file |
---|
86 | called notify-host-by-email and notify-service-by-email. Now we need to add |
---|
87 | in our new ticket notification commands below these two commands. I suggest |
---|
88 | you copy and paste the follow two command definitions. Do this below the |
---|
89 | notify-service-by-email command definition: |
---|
90 | |
---|
91 | ################################################################ |
---|
92 | # Additional commands creatred for network management workshop # |
---|
93 | ################################################################ |
---|
94 | |
---|
95 | # 'notifiy-host-ticket-by-email' command definition |
---|
96 | define command{ |
---|
97 | command_name notify-host-ticket-by-email |
---|
98 | command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$ |
---|
99 | } |
---|
100 | |
---|
101 | # 'notify-service-ticket-by-email' command definition |
---|
102 | define command{ |
---|
103 | command_name notify-service-ticket-by-email |
---|
104 | command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | - As you can see these are a bit complicated ;-) The key is that these define the format |
---|
109 | of the email that will be sent. In Nagios you've indicated that the contact |
---|
110 | named "net" will use these commands, and that this contact sends email to "net@pcX.mgmt" - |
---|
111 | as there should already be an alias entry in /etc/aliases for the user "net" and this |
---|
112 | points to the rt-mailgate defintion this means that email formatted as shown above |
---|
113 | will go to the user net@pcX.mgmt in this format and be passed to rt-mailgate, which, |
---|
114 | in turn will pass this to RT, which in turn has the proper queue set up for this. |
---|
115 | |
---|
116 | |
---|
117 | 3.) Choose a Service to Monitor with RT Tickets |
---|
118 | ----------------------------------------------- |
---|
119 | |
---|
120 | - The final step is to tell Nagios that you wish to notify the contact "tickets" for a |
---|
121 | particular service. If you look in /etc/nagios3/conf.d/eneric-service_nagios2.cfg the |
---|
122 | default contact_groups is "admins". To override this for a service edit the file |
---|
123 | /etc/nagios3/conf.d/services_nagios2.cfg and a contact_groups entry for one of the |
---|
124 | service defintions. For example, to send generates tickets in RT if HTTP go down on a |
---|
125 | box you would edit the HTTP service check so that it looks like this: |
---|
126 | |
---|
127 | # check that web services are running |
---|
128 | define service { |
---|
129 | hostgroup_name http-servers |
---|
130 | service_description HTTP |
---|
131 | check_command check_http |
---|
132 | use generic-service |
---|
133 | notification_interval 0 ; set > 0 if you want to be renotified |
---|
134 | contact_groups tickets |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | Note the additional item that we now have, "contact_groups." You can do this for other |
---|
139 | entries as well if you wish. |
---|
140 | |
---|
141 | - When you are done, save the file and exit. |
---|
142 | |
---|
143 | - Now restart Nagios to verify your changes are correct. |
---|
144 | |
---|
145 | # /etc/init.d/nagios3 stop |
---|
146 | # /etc/init.d/nagios3 start |
---|
147 | |
---|
148 | |
---|
149 | 4.) Generate RT Tickets for Hosts |
---|
150 | --------------------------------- |
---|
151 | |
---|
152 | - To do this you must either specify "contact_groups tickets" for individual host |
---|
153 | definitions, or you must update the template file for all hosts and change the |
---|
154 | default contact_groups entry to tickets. This file is generic-host_nagios2.cfg. |
---|
155 | |
---|
156 | - If you wish to do this go ahead. Tickets will be generated if a host goes down |
---|
157 | and you have specified the contact_groups for that host as being "tickets" |
---|
158 | |
---|
159 | 5. See Nagios Tickets in RT |
---|
160 | --------------------------- |
---|
161 | |
---|
162 | - To verify your changes have worked you will need to stop http service on your |
---|
163 | machine or another machine. |
---|
164 | |
---|
165 | # /etc/init.d/apache2 stop |
---|
166 | |
---|
167 | - It will take a while (up to 10 minutes) for Nagios to report that Apache is |
---|
168 | "critical", but once that happens a new ticket should appear in your RT instance |
---|
169 | in the Net queue generated by Nagios. |
---|