├── .gitignore ├── Ansiblefile ├── Ansiblefile.lock ├── LICENSE.txt ├── README.md ├── defaults └── main.yml ├── files ├── nagios.conf ├── nagios.key ├── nagios.pem └── pagerduty_nagios.pl ├── handlers └── main.yml ├── meta └── main.yml ├── tasks ├── apache.yml ├── build-nagios.yml ├── build-nrpe.yml ├── build-plugins.yml ├── main.yml ├── pagerduty.yml └── ses.yml └── templates ├── contacts.cfg.j2 ├── nagios.vhost.j2 ├── pagerduty_nagios.cfg.j2 └── ses_nagios.cfg.j2 /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | librarian_roles 3 | /tmp 4 | -------------------------------------------------------------------------------- /Ansiblefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | #^syntax detection 3 | 4 | role "laggyluke.nodejs" 5 | -------------------------------------------------------------------------------- /Ansiblefile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: https://github.com/laggyluke/ansible-role-nodejs 3 | ref: master 4 | sha: 9ae7523efd4ab5680aa967e418c329b695b7c4b1 5 | specs: 6 | laggyluke.nodejs (0.0.0) 7 | 8 | DEPENDENCIES 9 | laggyluke.nodejs (>= 0) 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2014, Benjamin Coe 4 | 5 | Permission to use, copy, modify, and/or distribute this software 6 | for any purpose with or without fee is hereby granted, provided 7 | that the above copyright notice and this permission notice 8 | appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 12 | OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE 13 | LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES 14 | OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 15 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 16 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ansible Nagios 2 | ============== 3 | 4 | Ansible role to install Nagios from source. 5 | 6 | Features 7 | -------- 8 | 9 | * Installs and configures Nagios 4 (not currently available through a PPA). 10 | * Installs the [Pagerduty integration](https://www.pagerduty.com/docs/guides/nagios-integration-guide/) 11 | * Support for sending notifications via [SES](http://github.com/npm/notify-by-ses) 12 | * Installs NRPE, for performing remote checks. 13 | * Installs a recent build of nagios-plugins. 14 | 15 | Installation 16 | ------------ 17 | 18 | Ansible Nagios has some dependencies on other roles, checkout [librarian-ansible](https://github.com/bcoe/librarian-ansible) 19 | a great tool for managing Ansible dependencies. 20 | 21 | Configuration 22 | ------------- 23 | 24 | To get things up and running on an Ubuntu machine, here are the variables you will need to set: 25 | 26 | ```yaml 27 | nagios_user: nagiosadmin 28 | nagios_password: nagiosadmin 29 | nagios_host: nagios.example.com 30 | nagios_pagerduty_key: xxxxxxxxxxxxxxxxxxxxx 31 | nagios_admin_email: ops@example.com 32 | nagios_amdin_name: 'Nagios Admin' 33 | 34 | nagios_aws_access_key_id: xxxxxxxxxxxxxxxx 35 | nagios_aws_access_key_secret: xxxxxxxxxxxxxxx 36 | nagios_ses_region: email.us-east-1.amazonaws.com 37 | 38 | nagios_enable_pagerduty_notifications: true 39 | nagios_enable_ses_notifications: true 40 | 41 | legacy: false # set to true, for older builds of Ubuntu like Precise. 42 | ``` 43 | 44 | * See `/vars/main.yml` for more configuration options. 45 | 46 | How it Works? 47 | ------------ 48 | 49 | * Create a playbook that references the nagios role. 50 | * Set the appropriate variables. 51 | * Run this role on a clean server. 52 | * You will now be able to access nagios on the host at **https://your-host/nagios**. 53 | 54 | Ansible-Nagios-Config 55 | --------------------- 56 | 57 | This Ansible role is designed to be used along with [Ansible-Nagios-Config](http://github.com/npm/ansible-nagios-config). 58 | Use this role to set up Nagios' configuration. 59 | 60 | Compatibility 61 | --------- 62 | 63 | This role has been tested on the following Linux distributions: 64 | 65 | **Ubuntu:** 66 | 67 | * Precise. 68 | * Trusty. 69 | 70 | Please open an issue if you confirm the role works on other distributions. 71 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | nagios_packages: 2 | - apache2 3 | - libapache2-mod-php5 4 | - build-essential 5 | - libgd2-xpm-dev 6 | - libssl-dev 7 | - sendmail-bin 8 | - sendmail 9 | - heirloom-mailx 10 | - wget 11 | - curl 12 | - daemon 13 | - apt-file 14 | - libnet-snmp-perl 15 | - libpq5 16 | - libradius1 17 | - libsensors4 18 | - libsnmp-base 19 | - libtalloc2 20 | - libtdb1 21 | - libwbclient0 22 | - samba-common 23 | - samba-common-bin 24 | - smbclient 25 | - snmp 26 | - whois 27 | - libmysqlclient15-dev 28 | - checkinstall 29 | - python-passlib 30 | - libwww-perl 31 | - libcrypt-ssleay-perl 32 | 33 | nagios_legacy_packages: 34 | - libperl5.14 35 | - libsnmp15 36 | 37 | nagios_version: 4.0.6 38 | nagios_plugins_version: 2.0 39 | nagios_nrpe_version: 2.15 40 | nagios_build_directory: /tmp 41 | nagios_ssl_lib_path: /usr/lib/x86_64-linux-gnu 42 | nagios_password: nagiosadmin 43 | nagios_user: nagiosadmin 44 | nagios_admin_email: ops@example.com 45 | nagios_admin_name: 'Nagios Admin' 46 | nagios_host: nagios.exmple.com 47 | nagios_log_directory: /var/log 48 | 49 | nagios_pagerduty_key: xxxxxxxxxxxxxxxxxxxxxx 50 | nagios_enable_pagerduty_notifications: true 51 | 52 | nagios_enable_ses_notifications: true 53 | nagios_aws_access_key_id: xxxxxxxxxxxxxxxx 54 | nagios_aws_access_key_secret: xxxxxxxxxxxxxxx 55 | nagios_ses_region: email.us-east-1.amazonaws.com 56 | 57 | nagios_tarball: http://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz 58 | nagios_tarball_sha256sum: d400190c771eb90e0ba16351f6358fa7e22e42a7be986f2066db63518a14397b 59 | 60 | nagios_plugin_tarball: https://www.nagios-plugins.org/download/nagios-plugins-2.0.tar.gz 61 | nagios_plugin_tarball_sha256sum: ba1080648abd912f55c18b248e7065db77a87d0c72611ab16c17af8b65da7684 62 | 63 | nagios_nrpe_tarball: http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz 64 | nagios_nrpe_tarball_sha256sum: 66383b7d367de25ba031d37762d83e2b55de010c573009c6f58270b137131072 65 | 66 | nagios_ssl_cert_pem: /etc/apache2/ssl/nagios.pem 67 | nagios_ssl_cert_key: /etc/apache2/ssl/nagios.key 68 | -------------------------------------------------------------------------------- /files/nagios.conf: -------------------------------------------------------------------------------- 1 | # nagios - monitoriong system 2 | # by https://raymii.org 3 | 4 | description "nagios monitoring system" 5 | 6 | start on virtual-filesystems 7 | stop on runlevel [06] 8 | 9 | respawn 10 | respawn limit 5 30 11 | limit nofile 65550 65550 12 | 13 | chdir /usr/local/nagios/ 14 | setuid nagios 15 | setgid nagios 16 | console log 17 | 18 | script 19 | exec bin/nagios etc/nagios.cfg 20 | end script 21 | -------------------------------------------------------------------------------- /files/nagios.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQDCLQ/muQSmGpNN 3 | rfWuHdSDtBp7HRFcZeOVUZD2tiCp7oWnD51PXnmvl8ZpbuqcLKomALrM4R6xrBfY 4 | sHRpsu/vzrj0MYKUppp8gH68qjWVqPWfSRcAt+aNt3sddDcwnnbT6Cfs3A1zDwID 5 | VEJOESd22y/MXp+j6Cwi+vdnE4zWKRoqHZpLYRjJz02/zgPNfhjLLRMUTJ79YFEu 6 | 2pOdXmEObzHQTH1jlaLPxso7h3X63V3JYfmm8NlyBBcJmg6CENCB15Thp1l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MFZFzB4Db+oSC+yjuVJDGVOXkWkf/P+mRxs1cn+t1/doXNf62F 39 | ElyTNjgk+352bsmRkj9qkGTXFiJsiTErr8Z3ZvgX3QFL6CSWZKpZ0sZRMcIQj7GU 40 | sNqszODEkXG9a6w0Jmqv8YZEKvSCHXvds2wv5H+fMQKCAQAIrTVx1/yBSfaa2BSS 41 | 73IuIACQwQY+2BUTnaX/R/qXmylZXAPujdTC6xT/fkHQgSx0XXKB97BQAdchCa4E 42 | p0RYSmFI67SyYPXF0MTslLrhCWQ++pbJYysmN89HWc3XArSp0BWzwTnOfHSjD6aQ 43 | XayLGSjIfPYCJDmbnzUMAsL12w+XbgWJ0bWeAFqBmiA1j8R6fUKoZjCF63D7o9DG 44 | zy1cWwIisS9pwbROlxwwADARqlAfH6NuFaK5sMAtBtnSEgDeFUwziLeB6sUSZFXP 45 | oKhy/DB4WJxgjw8po1C0/iwSzKKd5W9XYfSqTE/1PG0F3XQg2O4XckKpNkPRJtSi 46 | JuxnAoIBAQCERuulT1SE4hFLeoYhoIa06g6z1GY9fmUf/gX6WBq7W2jbLhBFKuUv 47 | 14FQcvN0sb/2pUSeuwZmhDuEHzVtTrJJ2mjQfGYrFsmF+lSZ3d7AVhK21qE4ME1Z 48 | SVl73130v8GG/ajvaHMxTnxX0RwKLqdh17bE1QdF0IDaTq7fBoBlv9O3AmSQ/eIX 49 | 3E75DejiYsDEIxN6xecBH+9n0M0m563hsMkDdeK6dBkTmTcmroiKGHbMI+n6N6S/ 50 | 5HIarqVNzJ0TvHqoEF7y3xKsFLh+ej0PBAgYMaVvFbbHCkzRaudWw4jy6pzlhrNZ 51 | yx1ZvsN8Fc6tkdnZsc0linzHBkA9ndMC 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /files/nagios.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFXzCCA0egAwIBAgIJANgePsTBsi6XMA0GCSqGSIb3DQEBBQUAMEYxCzAJBgNV 3 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4wwHwYDVR0jBBgwFoAUGYYK 19 | l0gWzmlOM0x0WMdAEV0Gs4wwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC 20 | AgEAh6RMsRjVDenoK/mEIHB8QzYrQPvsvPBz5tD+EfpxaEhyuls6dCsPZ3ORyjON 21 | CuPejQj64+JMQhyLwgKJppOl4oLyeiPDIU9LuDPlqUFHxbZs0J+04Svx5wXNB5ym 22 | UY5OlTHRue+4Goz/iovFUmNguQ/jvyixJA6DUvRaHvNE4MIqZTp8/Yg1BxcPpOxh 23 | ecuS+Zb5G9WNLu+U5StbiZ7YGx5rK6TL9IyKr/cE9+UPRPtR3PsLvDkaNYaHcG8A 24 | YSfyH+HpRBkwetrtHeq+1hf8eRRhTGeOmVYj/qkJOSot0esmOT/WLg6c8eXW+scV 25 | Z9MRRYyIoS6Lm1V1xfyMNmfc2vgX//bLXF6aRvXdnJo+mFL5NWuyZSbQwfB0K0tt 26 | Htm+9dO5Q0VI1u8IOBFy/2sSOYpifGvWFuEkO0H4GtT/Yw2G9b94Bw9DI8p392kK 27 | +nQ+Mk2CL8UQWaWaH7BiV2qoYCmtQOdbKq2D+h4blbkgQck92S6Wl/ERB2b0TE82 28 | KKbydN1F4k/CpQDH8Wc+5LWp/Ian+JHpMCOeTK3aDaBichKa8BYlW3Rlenm76D4X 29 | AAavgD65NiWoNHatnmu614eq4D8o58UBZN0xPaJa0/XFP7dyJUeCl27O1zOcxYRE 30 | PhfQFVQ0eb/8a1aVj8MC1+1tQ/kU2o3+yZyy0mZ4Bzogj70= 31 | -----END CERTIFICATE----- 32 | -------------------------------------------------------------------------------- /files/pagerduty_nagios.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | 4 | # Nagios plugin that sends Nagios events to PagerDuty. 5 | # 6 | # Copyright (c) 2011, PagerDuty, Inc. 7 | # All rights reserved. 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions are met: 11 | # * Redistributions of source code must retain the above copyright 12 | # notice, this list of conditions and the following disclaimer. 13 | # * Redistributions in binary form must reproduce the above copyright 14 | # notice, this list of conditions and the following disclaimer in the 15 | # documentation and/or other materials provided with the distribution. 16 | # * Neither the name of PagerDuty Inc nor the 17 | # names of its contributors may be used to endorse or promote products 18 | # derived from this software without specific prior written permission. 19 | # 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | # DISCLAIMED. IN NO EVENT SHALL PAGERDUTY INC BE LIABLE FOR ANY 24 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | 32 | use Pod::Usage; 33 | use Getopt::Long; 34 | use Sys::Syslog; 35 | use HTTP::Request::Common qw(POST); 36 | use HTTP::Status qw(is_client_error); 37 | use LWP::UserAgent; 38 | use File::Path; 39 | use Fcntl qw(:flock); 40 | 41 | 42 | =head1 NAME 43 | 44 | pagerduty_nagios -- Send Nagios events to the PagerDuty alert system 45 | 46 | =head1 SYNOPSIS 47 | 48 | pagerduty_nagios enqueue [options] 49 | 50 | pagerduty_nagios flush [options] 51 | 52 | =head1 DESCRIPTION 53 | 54 | This script passes events from Nagios to the PagerDuty alert system. It's 55 | meant to be run as a Nagios notification plugin. For more details, please see 56 | the PagerDuty Nagios integration docs at: 57 | http://www.pagerduty.com/docs/nagios-integration. 58 | 59 | When called in the "enqueue" mode, the script loads a Nagios notification out 60 | of the environment and into the event queue. It then tries to flush the 61 | queue by sending any enqueued events to the PagerDuty server. The script is 62 | typically invoked in this mode from a Nagios notification handler. 63 | 64 | When called in the "flush" mode, the script simply tries to send any enqueued 65 | events to the PagerDuty server. This mode is typically invoked by cron. The 66 | purpose of this mode is to retry any events that couldn't be sent to the 67 | PagerDuty server for whatever reason when they were initially enqueued. 68 | 69 | =head1 OPTIONS 70 | 71 | --api-base URL 72 | The base URL used to communicate with PagerDuty. The default option here 73 | should be fine, but adjusting it may make sense if your firewall doesn't 74 | pass HTTPS traffic for some reason. See the PagerDuty Nagios integration 75 | docs for details. 76 | 77 | --field KEY=VALUE 78 | Add this key-value pair to the event being passed to PagerDuty. The script 79 | automatically gathers Nagios macros out of the environment, so there's no 80 | need to specify these explicitly. This option can be repeated as many 81 | times as necessary to pass multiple key-value pairs. This option is only 82 | useful when an event is being enqueued.0 83 | 84 | --help 85 | Display documentation for the script. 86 | 87 | --queue-dir DIR 88 | Path to the directory to use to store the event queue. By default, we use 89 | /tmp/pagerduty_nagios. 90 | 91 | --verbose 92 | Turn on extra debugging information. Useful for debugging. 93 | 94 | --proxy 95 | Use a proxy for the connections like "--proxy http://127.0.0.1:8888/" 96 | 97 | =cut 98 | 99 | # This release tested on: 100 | # Debian Sarge (Perl 5.8.4) 101 | # Ubuntu 9.04 (Perl 5.10.0) 102 | 103 | my $opt_api_base = "https://events.pagerduty.com/nagios/2010-04-15"; 104 | my %opt_fields; 105 | my $opt_help; 106 | my $opt_queue_dir = "/tmp/pagerduty_nagios"; 107 | my $opt_verbose; 108 | my $opt_proxy; 109 | 110 | 111 | sub get_queue_from_dir { 112 | my $dh; 113 | 114 | unless (opendir($dh, $opt_queue_dir)) { 115 | syslog(LOG_ERR, "opendir %s failed: %s", $opt_queue_dir, $!); 116 | die $!; 117 | } 118 | 119 | my @files; 120 | while (my $f = readdir($dh)) { 121 | next unless $f =~ /^pd_(\d+)_\d+\.txt$/; 122 | push @files, [int($1), $f]; 123 | } 124 | 125 | closedir($dh); 126 | 127 | @files = sort { @{$a}[0] <=> @{$b}[0] } @files; 128 | return map { @{$_}[1] } @files; 129 | } 130 | 131 | 132 | sub flush_queue { 133 | my @files = get_queue_from_dir(); 134 | my $ua = LWP::UserAgent->new; 135 | 136 | # It's not a big deal if we don't get the message through the first time. 137 | # It will get sent the next time cron fires. 138 | $ua->timeout(15); 139 | 140 | if ($opt_proxy) { 141 | $ua->proxy (['http', 'https'], $opt_proxy); 142 | } 143 | 144 | foreach (@files) { 145 | my $filename = "$opt_queue_dir/$_"; 146 | my $fd; 147 | my %event; 148 | 149 | print STDERR "==== Now processing: $filename\n" if $opt_verbose; 150 | 151 | unless (open($fd, "<", $filename)) { 152 | syslog(LOG_ERR, "open %s for read failed: %s", $filename, $!); 153 | die $!; 154 | } 155 | 156 | while (<$fd>) { 157 | chomp; 158 | my @fields = split("=", $_, 2); 159 | $event{$fields[0]} = $fields[1]; 160 | } 161 | 162 | close($fd); 163 | 164 | my $req = POST("$opt_api_base/create_event", \%event); 165 | 166 | if ($opt_verbose) { 167 | my $s = $req->as_string; 168 | print STDERR "Request:\n$s\n"; 169 | } 170 | 171 | my $resp = $ua->request($req); 172 | 173 | if ($opt_verbose) { 174 | my $s = $resp->as_string; 175 | print STDERR "Response:\n$s\n"; 176 | } 177 | 178 | if ($resp->is_success) { 179 | syslog(LOG_INFO, "Nagios event in file %s ACCEPTED by the PagerDuty server.", $filename); 180 | unlink($filename); 181 | } 182 | elsif (is_client_error($resp->code)) { 183 | syslog(LOG_WARNING, "Nagios event in file %s REJECTED by the PagerDuty server. Server says: %s", $filename, $resp->content); 184 | unlink($filename); 185 | } 186 | else { 187 | # Something else went wrong. 188 | syslog(LOG_WARNING, "Nagios event in file %s DEFERRED due to network/server problems.", $filename); 189 | return 0; 190 | } 191 | } 192 | 193 | # Everything that needed to be sent was sent. 194 | return 1; 195 | } 196 | 197 | 198 | sub lock_and_flush_queue { 199 | # Serialize access to the queue directory while we flush. 200 | # (We don't want more than one flush at once.) 201 | 202 | my $lock_filename = "$opt_queue_dir/lockfile"; 203 | my $lock_fd; 204 | 205 | unless (open($lock_fd, ">", $lock_filename)) { 206 | syslog(LOG_ERR, "open %s for write failed: %s", $lock_filename, $!); 207 | die $!; 208 | } 209 | 210 | unless (flock($lock_fd, LOCK_EX)) { 211 | syslog(LOG_ERR, "flock %s failed: %s", $lock_filename, $!); 212 | die $!; 213 | } 214 | 215 | my $ret = flush_queue(); 216 | 217 | close($lock_fd); 218 | 219 | return $ret; 220 | } 221 | 222 | 223 | sub enqueue_event { 224 | my %event; 225 | 226 | # Scoop all the Nagios related stuff out of the environment. 227 | while ((my $k, my $v) = each %ENV) { 228 | next unless $k =~ /^(ICINGA|NAGIOS)_(.*)$/; 229 | $event{$2} = $v; 230 | } 231 | 232 | # Apply any other variables that were passed in. 233 | %event = (%event, %opt_fields); 234 | 235 | $event{"pd_version"} = "1.0"; 236 | 237 | # Right off the bat, enqueue the event. Nothing tiem consuming should come 238 | # before here (i.e. no locks or remote connections), because we want to 239 | # make sure we get the event written out within the Nagios notification 240 | # timeout. If we get killed off after that, it isn't a big deal. 241 | 242 | my $filename = sprintf("$opt_queue_dir/pd_%u_%u.txt", time(), $$); 243 | my $fd; 244 | 245 | unless (open($fd, ">", $filename)) { 246 | syslog(LOG_ERR, "open %s for write failed: %s", $filename, $!); 247 | die $!; 248 | } 249 | 250 | while ((my $k, my $v) = each %event) { 251 | # "=" can't occur in the keyname, and "\n" can't occur anywhere. 252 | # (Nagios follows this already, so I think we're safe) 253 | print $fd "$k=$v\n"; 254 | } 255 | 256 | close($fd); 257 | } 258 | 259 | ########### 260 | 261 | GetOptions("api-base=s" => \$opt_api_base, 262 | "field=s%" => \%opt_fields, 263 | "help" => \$opt_help, 264 | "queue-dir=s" => \$opt_queue_dir, 265 | "verbose" => \$opt_verbose, 266 | "proxy=s" => \$opt_proxy 267 | ) || pod2usage(2); 268 | 269 | pod2usage(2) if @ARGV < 1 || 270 | (($ARGV[0] ne "enqueue") && ($ARGV[0] ne "flush")); 271 | 272 | pod2usage(-verbose => 3) if $opt_help; 273 | 274 | my @log_mode = ("nofatal", "pid"); 275 | push(@log_mode, "perror") if $opt_verbose; 276 | 277 | openlog("pagerduty_nagios", join(",", @log_mode), LOG_LOCAL0); 278 | 279 | # This function automatically terminates the program on things like permission 280 | # errors. 281 | mkpath($opt_queue_dir); 282 | 283 | if ($ARGV[0] eq "enqueue") { 284 | enqueue_event(); 285 | lock_and_flush_queue(); 286 | } 287 | elsif ($ARGV[0] eq "flush") { 288 | lock_and_flush_queue(); 289 | } 290 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | - name: restart apache 2 | become: true 3 | service: name=apache2 state=restarted 4 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Benjamin Coe 4 | description: A role for installing Nagios 4 with PagerDuty and SES support. 5 | min_ansible_version: 1.4 6 | version: 0.0.1 7 | license: ISC 8 | platforms: 9 | - name: Ubuntu 10 | versions: 11 | - precise 12 | - trusty 13 | categories: 14 | - system 15 | - monitoring 16 | dependencies: 17 | - role: laggyluke.nodejs 18 | when: nagios_enable_ses_notifications 19 | -------------------------------------------------------------------------------- /tasks/apache.yml: -------------------------------------------------------------------------------- 1 | - name: add apache user to nagios group 2 | become: true 3 | user: > 4 | groups=nagios 5 | name=apache 6 | 7 | - name: add passwords for nagios 8 | become: true 9 | htpasswd: > 10 | name="{{nagios_user}}" 11 | password="{{nagios_password}}" 12 | path=/usr/local/nagios/etc/htpasswd.users 13 | 14 | - name: set permissions on new password file 15 | become: true 16 | file: > 17 | path=/usr/local/nagios/etc/htpasswd.users 18 | owner=nagios 19 | group=nagcmd 20 | 21 | - name: create certs directory 22 | become: true 23 | file: > 24 | state=directory 25 | path=/etc/apache2/ssl 26 | owner=root 27 | group=root 28 | mode=770 29 | 30 | - name: create certs directory 31 | become: true 32 | file: > 33 | state=directory 34 | path=/etc/apache2/ssl 35 | owner=root 36 | group=root 37 | mode=770 38 | 39 | - name: copy nagios.pem 40 | become: true 41 | copy: > 42 | src=nagios.pem 43 | dest=/etc/apache2/ssl/nagios.pem 44 | owner=root 45 | group=root 46 | mode=640 47 | 48 | - name: copy nagios.key 49 | become: true 50 | copy: > 51 | src=nagios.key 52 | dest=/etc/apache2/ssl/nagios.key 53 | owner=root 54 | group=root 55 | mode=640 56 | 57 | - name: copy nagios vhost 58 | become: true 59 | template: > 60 | src=nagios.vhost.j2 61 | dest=/etc/apache2/sites-available/nagios.conf 62 | owner=root 63 | group=root 64 | mode=640 65 | when: not (legacy | default(false)) 66 | 67 | - name: copy nagios vhost for pre-trusty 68 | become: true 69 | template: > 70 | src=nagios.vhost.j2 71 | dest=/etc/apache2/sites-available/nagios 72 | owner=root 73 | group=root 74 | mode=640 75 | when: legacy | default(false) 76 | 77 | - name: enable nagios vhost 78 | become: true 79 | command: "a2ensite nagios" 80 | 81 | - name: enable apache ssl 82 | become: true 83 | command: "a2enmod ssl" 84 | 85 | - name: enable apache cgi 86 | become: true 87 | command: "a2enmod cgi" 88 | -------------------------------------------------------------------------------- /tasks/build-nagios.yml: -------------------------------------------------------------------------------- 1 | - name: download nagios tarball 2 | become: true 3 | get_url: > 4 | dest={{nagios_build_directory}} 5 | url={{nagios_tarball}} 6 | sha256sum={{nagios_tarball_sha256sum}} 7 | 8 | - name: untar the tarball 9 | become: true 10 | command: "tar -xvf nagios-{{nagios_version}}.tar.gz chdir={{nagios_build_directory}}" 11 | 12 | - name: create stylesheets directory 13 | become: true 14 | file: > 15 | state=directory 16 | path=/usr/local/nagios/share/stylesheets 17 | owner=nagios 18 | group=nagios 19 | mode=770 20 | 21 | - name: create images directory 22 | become: true 23 | file: > 24 | state=directory 25 | path=/usr/local/nagios/share/images 26 | owner=nagios 27 | group=nagios 28 | mode=770 29 | 30 | - name: create apache config directory 31 | become: true 32 | file: > 33 | state=directory 34 | path=/etc/httpd/conf.d/ 35 | owner=nagios 36 | group=nagios 37 | mode=770 38 | 39 | - name: configure 40 | become: true 41 | command: "./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-command-user=nagios --with-command-group=nagcmd chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 42 | 43 | - name: make 44 | become: true 45 | command: "make all chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 46 | 47 | - name: install nagios package 48 | become: true 49 | command: "checkinstall --pkgname=nagios4 --requires='perl,libc6' --default chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 50 | 51 | - name: install sample config files 52 | become: true 53 | command: "checkinstall --pkgname=nagios-config --requires='perl,libc6' --default make install-config chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 54 | 55 | - name: configure external command permissions 56 | become: true 57 | command: "checkinstall --pkgname=nagios-commandmode --requires='perl,libc6' --default make install-commandmode chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 58 | 59 | - name: install apache config files 60 | become: true 61 | command: "checkinstall --pkgname=nagios-webconf --requires='perl,libc6' --default make install-webconf chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 62 | 63 | - name: install the exfoliation theme for the Nagios web interface 64 | become: true 65 | command: "checkinstall --install=no --pkgname=nagios-exfoliation --requires='perl,libc6' --default make install-exfoliation chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 66 | 67 | - name: install exfoliation 68 | become: true 69 | command: "dpkg --force-overwrite -i nagios-exfoliation_{{nagios_version}}-1_amd64.deb chdir={{nagios_build_directory}}/nagios-{{nagios_version}}" 70 | -------------------------------------------------------------------------------- /tasks/build-nrpe.yml: -------------------------------------------------------------------------------- 1 | - name: download nagios nrpe tarball 2 | become: true 3 | get_url: > 4 | dest={{nagios_build_directory}} 5 | url={{nagios_nrpe_tarball}} 6 | sha256sum={{nagios_nrpe_tarball_sha256sum}} 7 | 8 | - name: untar the tarball 9 | become: true 10 | command: "tar -xvf nrpe-{{nagios_nrpe_version}}.tar.gz chdir={{nagios_build_directory}}" 11 | 12 | - name: configure 13 | become: true 14 | command: "./configure --with-ssl=/usr/bin/openssl --with-ssl-lib={{nagios_ssl_lib_path}} chdir={{nagios_build_directory}}/nrpe-{{nagios_nrpe_version}}" 15 | 16 | - name: make 17 | become: true 18 | command: "make all chdir={{nagios_build_directory}}/nrpe-{{nagios_nrpe_version}}" 19 | 20 | - name: install nagios nrpe package 21 | become: true 22 | command: "checkinstall --pkgname=nrpe --requires='perl,libc6' --default chdir={{nagios_build_directory}}/nrpe-{{nagios_nrpe_version}}" 23 | -------------------------------------------------------------------------------- /tasks/build-plugins.yml: -------------------------------------------------------------------------------- 1 | - name: download nagios plugins tarball 2 | become: true 3 | get_url: > 4 | dest="{{nagios_build_directory}}" 5 | url={{nagios_plugin_tarball}} 6 | sha256sum={{nagios_plugin_tarball_sha256sum}} 7 | 8 | - name: untar the tarball 9 | become: true 10 | command: "tar -xvf nagios-plugins-{{nagios_plugins_version}}.tar.gz chdir={{nagios_build_directory}}" 11 | 12 | - name: configure 13 | become: true 14 | command: "./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules --enable-libtap chdir={{nagios_build_directory}}/nagios-plugins-{{nagios_plugins_version}}" 15 | 16 | - name: make 17 | become: true 18 | command: "make all chdir={{nagios_build_directory}}/nagios-plugins-{{nagios_plugins_version}}" 19 | 20 | - name: install nagios plugins package 21 | become: true 22 | command: "checkinstall --pkgname=nagios-plugins --requires='perl,libc6' --default chdir={{nagios_build_directory}}/nagios-plugins-{{nagios_plugins_version}}" 23 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Update and install dependent packages. 2 | - name: install nagios' dependent packages 3 | become: true 4 | apt: pkg={{ item }} state=present force=true update_cache=yes 5 | with_items: nagios_packages 6 | 7 | - name: install legacy packages 8 | become: true 9 | apt: pkg={{ item }} state=present force=true update_cache=yes 10 | with_items: nagios_legacy_packages 11 | when: legacy | default(false) 12 | 13 | # Create nagios users and groups. 14 | - name: create nagios group 15 | become: true 16 | group: > 17 | gid=3000 18 | name=nagios 19 | 20 | - name: create nagcmd group 21 | become: true 22 | group: > 23 | gid=3001 24 | name=nagcmd 25 | 26 | - name: create nagios user 27 | become: true 28 | user: > 29 | uid=3000 30 | group=nagios 31 | groups=nagcmd 32 | name=nagios 33 | home=/usr/local/nagios 34 | comment="Nagios Admin" 35 | 36 | - name: add user www-data to nagcmd group 37 | become: true 38 | user: > 39 | groups=nagcmd 40 | name=www-data 41 | 42 | # build and install nagios. 43 | - tasks: 44 | include: build-nagios.yml 45 | 46 | # Build and install nagios check plugins. 47 | - tasks: 48 | include: build-plugins.yml 49 | 50 | # Build and install nagios remote checks. 51 | - tasks: 52 | include: build-nrpe.yml 53 | 54 | # Setup apache. 55 | - tasks: 56 | include: apache.yml 57 | 58 | # Setup pagerduty. 59 | - tasks: 60 | include: pagerduty.yml 61 | when: nagios_enable_pagerduty_notifications 62 | 63 | # Setup SES for notifications. 64 | - tasks: 65 | include: ses.yml 66 | when: nagios_enable_ses_notifications 67 | 68 | - name: disable flap detection 69 | become: true 70 | lineinfile: > 71 | dest=/usr/local/nagios/etc/nagios.cfg 72 | line="enable_flap_detection=0" 73 | regexp="^enable_flap_detection.*$" 74 | 75 | - name: overwrite contacts.cfg 76 | become: true 77 | template: > 78 | src=contacts.cfg.j2 79 | dest=/usr/local/nagios/etc/objects/contacts.cfg 80 | owner=nagios 81 | group=nagios 82 | mode=640 83 | 84 | - name: install nagios upstart script 85 | become: true 86 | copy: > 87 | src=nagios.conf 88 | dest=/etc/init/nagios.conf 89 | owner=nagios 90 | group=nagios 91 | mode=640 92 | 93 | - name: restart nagios 94 | become: true 95 | service: name=nagios state=restarted 96 | notify: restart apache 97 | -------------------------------------------------------------------------------- /tasks/pagerduty.yml: -------------------------------------------------------------------------------- 1 | - name: copy pagerduty contact 2 | become: true 3 | template: > 4 | src=pagerduty_nagios.cfg.j2 5 | dest=/usr/local/nagios/etc/objects/pagerduty_nagios.cfg 6 | owner=nagios 7 | group=nagios 8 | mode=640 9 | 10 | - name: copy pagerduty script 11 | become: true 12 | copy: > 13 | src=pagerduty_nagios.pl 14 | dest=/usr/local/bin/pagerduty_nagios.pl 15 | owner=nagios 16 | group=nagios 17 | mode=755 18 | 19 | - name: enable environment macros 20 | become: true 21 | lineinfile: > 22 | dest=/usr/local/nagios/etc/nagios.cfg 23 | line="enable_environment_macros=1" 24 | regexp='^enable_environment_macros.*$' 25 | 26 | - name: "add pagerduty flush queue to cron" 27 | become: true 28 | cron: > 29 | name="pagerduty flush queue" 30 | job="/usr/local/bin/pagerduty_nagios.pl flush" 31 | user=nagios 32 | state=present 33 | 34 | - name: add pagerduty contact to nagios.cfg 35 | become: true 36 | lineinfile: > 37 | dest=/usr/local/nagios/etc/nagios.cfg 38 | line="cfg_file=/usr/local/nagios/etc/objects/pagerduty_nagios.cfg" 39 | regexp="cfg_file\=/usr/local/nagios/etc/objects/pagerduty_nagios\.cfg" 40 | -------------------------------------------------------------------------------- /tasks/ses.yml: -------------------------------------------------------------------------------- 1 | - name: copy ses contact 2 | become: true 3 | template: > 4 | src=ses_nagios.cfg.j2 5 | dest=/usr/local/nagios/etc/objects/ses_nagios.cfg 6 | owner=nagios 7 | group=nagios 8 | mode=640 9 | 10 | - name: create notify-by-ses log 11 | become: true 12 | copy: > 13 | content="" 14 | dest="{{nagios_log_directory}}/notify-by-ses.log" 15 | owner=nagios 16 | group=nagios 17 | mode=770 18 | 19 | - name: install ses notifier 20 | become: true 21 | command: npm install notify-by-ses -g 22 | 23 | - name: add ses contact to nagios.cfg 24 | become: true 25 | lineinfile: > 26 | dest=/usr/local/nagios/etc/nagios.cfg 27 | line="cfg_file=/usr/local/nagios/etc/objects/ses_nagios.cfg" 28 | regexp="cfg_file\=/usr/local/nagios/etc/objects/ses_nagios\.cfg" 29 | -------------------------------------------------------------------------------- /templates/contacts.cfg.j2: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # CONTACTS.CFG - SAMPLE CONTACT/CONTACTGROUP DEFINITIONS 3 | # 4 | # 5 | # NOTES: This config file provides you with some example contact and contact 6 | # group definitions that you can reference in host and service 7 | # definitions. 8 | # 9 | # You don't need to keep these definitions in a separate file from your 10 | # other object definitions. This has been done just to make things 11 | # easier to understand. 12 | # 13 | ############################################################################### 14 | 15 | 16 | 17 | ############################################################################### 18 | ############################################################################### 19 | # 20 | # CONTACTS 21 | # 22 | ############################################################################### 23 | ############################################################################### 24 | 25 | # Just one contact defined by default - the Nagios admin (that's you) 26 | # This contact definition inherits a lot of default values from the 'generic-contact' 27 | # template which is defined elsewhere. 28 | 29 | define contact{ 30 | contact_name nagiosadmin ; Short name of user 31 | use generic-contact ; Inherit default values from generic-contact template (defined above) 32 | alias {{nagios_admin_name}} ; Full name of user 33 | email {{nagios_admin_email}} ; 34 | } 35 | 36 | 37 | 38 | ############################################################################### 39 | ############################################################################### 40 | # 41 | # CONTACT GROUPS 42 | # 43 | ############################################################################### 44 | ############################################################################### 45 | 46 | # We only have one contact in this simple configuration file, so there is 47 | # no need to create more than one contact group. 48 | 49 | define contactgroup{ 50 | contactgroup_name admins 51 | alias Nagios Administrators 52 | members nagiosadmin{% if nagios_enable_pagerduty_notifications %},pagerduty{% endif %}{% if nagios_enable_ses_notifications %},ses{% endif %} 53 | 54 | } 55 | -------------------------------------------------------------------------------- /templates/nagios.vhost.j2: -------------------------------------------------------------------------------- 1 | 2 | ServerAdmin {{nagios_admin_email}} 3 | ServerName {{nagios_host}} 4 | Redirect / https://{{nagios_host}}/ 5 | 6 | 7 | 8 | ServerAdmin {{nagios_admin_email}} 9 | ServerName {{nagios_host}} 10 | 11 | ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" 12 | 13 | RedirectMatch ^/$ /nagios/ 14 | 15 | 16 | Options ExecCGI 17 | AllowOverride None 18 | Order allow,deny 19 | Allow from all 20 | AuthName "Nagios Access" 21 | AuthType Basic 22 | AuthUserFile /usr/local/nagios/etc/htpasswd.users 23 | Require valid-user 24 | 25 | 26 | Alias /nagios "/usr/local/nagios/share" 27 | 28 | 29 | Options None 30 | AllowOverride None 31 | Order allow,deny 32 | Allow from all 33 | AuthName "Nagios Access" 34 | AuthType Basic 35 | AuthUserFile /usr/local/nagios/etc/htpasswd.users 36 | Require valid-user 37 | 38 | 39 | SSLEngine On 40 | SSLCertificateFile {{nagios_ssl_cert_pem}} 41 | SSLCertificateKeyFile {{nagios_ssl_cert_key}} 42 | 43 | -------------------------------------------------------------------------------- /templates/pagerduty_nagios.cfg.j2: -------------------------------------------------------------------------------- 1 | define contact { 2 | contact_name pagerduty 3 | alias PagerDuty Pseudo-Contact 4 | service_notification_period 24x7 5 | host_notification_period 24x7 6 | service_notification_options w,u,c,r 7 | host_notification_options d,u,r 8 | service_notification_commands notify-service-by-pagerduty 9 | host_notification_commands notify-host-by-pagerduty 10 | pager {{nagios_pagerduty_key}} 11 | } 12 | 13 | define command { 14 | command_name notify-service-by-pagerduty 15 | command_line /usr/local/bin/pagerduty_nagios.pl enqueue -f pd_nagios_object=service -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f SERVICEDESC="$SERVICEDESC$" -f SERVICESTATE="$SERVICESTATE$" 16 | } 17 | 18 | define command { 19 | command_name notify-host-by-pagerduty 20 | command_line /usr/local/bin/pagerduty_nagios.pl enqueue -f pd_nagios_object=host -f CONTACTPAGER="$CONTACTPAGER$" -f NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" -f HOSTNAME="$HOSTNAME$" -f HOSTSTATE="$HOSTSTATE$" 21 | } 22 | -------------------------------------------------------------------------------- /templates/ses_nagios.cfg.j2: -------------------------------------------------------------------------------- 1 | # contact configuration file used by ansible-nagios. 2 | define contact { 3 | contact_name ses 4 | alias SES Pseudo-Contact 5 | service_notification_period 24x7 6 | host_notification_period 24x7 7 | service_notification_options w,u,c,r 8 | host_notification_options d,u,r 9 | service_notification_commands notify-by-ses-service 10 | host_notification_commands notify-by-ses-host 11 | pager {{nagios_admin_email}} 12 | } 13 | 14 | define command { 15 | command_name notify-by-ses-service 16 | command_line /usr/bin/notify-by-ses -k "{{nagios_aws_access_key_id}}" -s "{{nagios_aws_access_key_secret}}" -n "$NOTIFICATIONTYPE$" -h "$HOSTNAME$" -t "$SERVICESTATE$" -d "$SERVICEDISPLAYNAME$" -a "$HOSTADDRESS$" -o "$SERVICEOUTPUT$" -p "$CONTACTPAGER$" -r "{{nagios_ses_region}}" 17 | } 18 | 19 | define command { 20 | command_name notify-by-ses-host 21 | command_line /usr/bin/notify-by-ses -y Host -k "{{nagios_aws_access_key_id}}" -s "{{nagios_aws_access_key_secret}}" -n "$NOTIFICATIONTYPE$" -h "$HOSTNAME$" -t "$HOSTSTATE$" -d "$HOSTDISPLAYNAME$" -a "$HOSTADDRESS$" -o "$HOSTOUTPUT$" -p "$CONTACTPAGER$" -r "{{nagios_ses_region}}" 22 | } 23 | --------------------------------------------------------------------------------