nagios-herald 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +11 -0
  5. data/CONTRIBUTING.md +28 -0
  6. data/Gemfile +5 -0
  7. data/LICENSE +21 -0
  8. data/README.md +94 -0
  9. data/Rakefile +9 -0
  10. data/bin/draw_stack_bars +76 -0
  11. data/bin/dump_nagios_env.sh +25 -0
  12. data/bin/get_ganglia_graph +82 -0
  13. data/bin/get_graph +50 -0
  14. data/bin/get_graphite_graph +58 -0
  15. data/bin/nagios-herald +6 -0
  16. data/bin/splunk_alert_frequency +54 -0
  17. data/contrib/nrpe-plugins/check_cpu_stats.sh +186 -0
  18. data/contrib/nrpe-plugins/check_disk.sh +34 -0
  19. data/contrib/nrpe-plugins/check_mem.pl +181 -0
  20. data/contrib/nrpe-plugins/nrpe-plugin-examples.md +11 -0
  21. data/docs/config.md +62 -0
  22. data/docs/example_alerts.md +48 -0
  23. data/docs/formatters.md +180 -0
  24. data/docs/helpers.md +12 -0
  25. data/docs/images/cpu_no_context.png +0 -0
  26. data/docs/images/cpu_with_context.png +0 -0
  27. data/docs/images/disk_space_no_context.png +0 -0
  28. data/docs/images/disk_space_with_context.png +0 -0
  29. data/docs/images/memory_high_no_context.png +0 -0
  30. data/docs/images/memory_high_with_context.png +0 -0
  31. data/docs/images/nagios-herald-formatter-content-example.png +0 -0
  32. data/docs/images/nagios-herald.png +0 -0
  33. data/docs/images/stack-bars.png +0 -0
  34. data/docs/images/vanilla-nagios.png +0 -0
  35. data/docs/messages.md +16 -0
  36. data/docs/nagios-config.md +74 -0
  37. data/docs/tools.md +79 -0
  38. data/etc/config.yml.example +14 -0
  39. data/etc/readme.md +2 -0
  40. data/lib/nagios-herald/config.rb +25 -0
  41. data/lib/nagios-herald/executor.rb +265 -0
  42. data/lib/nagios-herald/formatter_loader.rb +82 -0
  43. data/lib/nagios-herald/formatters/base.rb +524 -0
  44. data/lib/nagios-herald/formatters/check_cpu.rb +71 -0
  45. data/lib/nagios-herald/formatters/check_disk.rb +143 -0
  46. data/lib/nagios-herald/formatters/check_logstash.rb +155 -0
  47. data/lib/nagios-herald/formatters/check_memory.rb +42 -0
  48. data/lib/nagios-herald/formatters/example.rb +19 -0
  49. data/lib/nagios-herald/formatters.rb +1 -0
  50. data/lib/nagios-herald/helpers/ganglia_graph.rb +99 -0
  51. data/lib/nagios-herald/helpers/graphite_graph.rb +85 -0
  52. data/lib/nagios-herald/helpers/logstash_query.rb +125 -0
  53. data/lib/nagios-herald/helpers/splunk_alert_frequency.rb +170 -0
  54. data/lib/nagios-herald/helpers/splunk_query.rb +119 -0
  55. data/lib/nagios-herald/helpers/url_image.rb +76 -0
  56. data/lib/nagios-herald/helpers.rb +5 -0
  57. data/lib/nagios-herald/logging.rb +48 -0
  58. data/lib/nagios-herald/message_loader.rb +40 -0
  59. data/lib/nagios-herald/messages/base.rb +56 -0
  60. data/lib/nagios-herald/messages/email.rb +150 -0
  61. data/lib/nagios-herald/messages/irc.rb +58 -0
  62. data/lib/nagios-herald/messages/pager.rb +75 -0
  63. data/lib/nagios-herald/messages.rb +3 -0
  64. data/lib/nagios-herald/test_helpers/base_test_case.rb +82 -0
  65. data/lib/nagios-herald/util.rb +45 -0
  66. data/lib/nagios-herald/version.rb +3 -0
  67. data/lib/nagios-herald.rb +7 -0
  68. data/lib/stackbars/__init__.py +0 -0
  69. data/lib/stackbars/chart_utils.py +25 -0
  70. data/lib/stackbars/grouped_stackbars.py +97 -0
  71. data/lib/stackbars/pilfonts/Tahoma.ttf +0 -0
  72. data/lib/stackbars/pilfonts/aerial.ttf +0 -0
  73. data/lib/stackbars/pilfonts/arial_black.ttf +0 -0
  74. data/lib/stackbars/stackbar.py +100 -0
  75. data/nagios-herald.gemspec +33 -0
  76. data/test/env_files/check_cpu_idle.CRITICAL +199 -0
  77. data/test/env_files/check_cpu_iowait.WARNING +199 -0
  78. data/test/env_files/check_disk.CRITICAL +197 -0
  79. data/test/env_files/check_disk.CRITICAL_ICINGA +197 -0
  80. data/test/env_files/check_disk.RECOVERY +197 -0
  81. data/test/env_files/check_memory.CRITICAL +197 -0
  82. data/test/env_files/nagios_vars.EXAMPLE +197 -0
  83. data/test/unit/test_config.rb +31 -0
  84. data/test/unit/test_executor.rb +65 -0
  85. data/test/unit/test_formatter_base.rb +131 -0
  86. data/test/unit/test_formatter_check_cpu_idle_critical.rb +135 -0
  87. data/test/unit/test_formatter_check_memory.rb +135 -0
  88. data/test/unit/test_icinga_variables.rb +31 -0
  89. data/test/unit/test_logging.rb +35 -0
  90. data/test/unit/test_message_email.rb +69 -0
  91. data/test/unit/test_message_pager.rb +69 -0
  92. metadata +204 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 335b4477670958112568a92c559b299ee3c992bf
4
+ data.tar.gz: dd284b572df136d6afd4b18ec80312923a3b5b8f
5
+ SHA512:
6
+ metadata.gz: 711870cc088ec314c383a2a97f16a43a2af7c00284b3858f23dad0e00d8727ba284634f505c674f86cb4c09b602343c7f464c9e85b626a969c3880ab59216e3a
7
+ data.tar.gz: 4b2981598b689cf8390c62aae5bb863f6c916cdf90cf884a693835e33a585202f11043dc6781324475e55b8f6869315c89e7776dfd731a935b055570b295361f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.swp
2
+ *.pyc
3
+ .DS_STORE
4
+ etc/config.yml
5
+ mail.html
6
+ *.gem
7
+ .idea
8
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ sudo: false
5
+ cache: bundler
6
+ before_install:
7
+ - "echo 'gem: --no-ri --no-rdoc' >> ~/.gemrc"
8
+ before_script:
9
+ - bundle exec mailcatcher
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 0.0.2 (23rd June, 2014)
2
+
3
+ Features:
4
+
5
+ - LogstashQuery helper, check_logstash formatter, CHANGELOG added
6
+
7
+ ## 0.0.1 (6th June, 2014)
8
+
9
+ Features:
10
+
11
+ - Initial Release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,28 @@
1
+ # Contribute
2
+
3
+ To contribute to ``nagios-herald``, you need to follow a few easy steps:
4
+
5
+ 1. Fork the repo.
6
+ 2. Clone your fork.
7
+ 3. Hack on your favorite bits like the formatters, helpers, etc.
8
+ 4. If you are adding new functionality, document it in its own file under ``docs/``.
9
+ 5. If necessary, rebase your commits into logical chunks, without errors.
10
+ 6. Verify your code by running the test suite, and adding additional tests if you can.
11
+ 7. Push the branch up to GitHub.
12
+ 8. Send a pull request.
13
+
14
+ We'll do our best to get your changes in!
15
+
16
+ ## How to Run Tests
17
+
18
+ The tests are written using Ruby's minitest.
19
+
20
+ Name your tests with the ``test_`` prefix and place them in the ``test/unit/``
21
+ directory.
22
+
23
+ When you're ready to run your tests, simply run ``rake``:
24
+
25
+ ```
26
+ % rake test
27
+ ```
28
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'rake'
5
+ gem 'mailcatcher'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # nagios-herald [![Travis Build Status](https://travis-ci.org/etsy/nagios-herald.svg?branch=master)](https://travis-ci.org/etsy/nagios-herald)
2
+
3
+ ``nagios-herald`` is a project that aims to make it easy to provide context in Nagios alerts.
4
+
5
+ It was created from a desire to supplement an on-call engineer's awareness of conditions surrounding a notifying event. In other words, if a computer is going to page me at 3AM, I expect it to do some work for me to help me understand what's failing.
6
+
7
+ ## Customizing Nagios Alerts
8
+
9
+ Nagios is a time-tested monitoring and alerting tool used by many Operations teams to keep an eye
10
+ on the shop. It does an excellent job of executing scheduled checks, determining when a threshold has been exceeded, and sending alerts.
11
+
12
+ Past experience with Nagios has shown that, typically, those alerts provide little information beyond the fact that a host is down or a service is not responding as defined by check thresholds. It's bad enough to be woken up by an alert; it would make the on-call experience more bearable if the alerts could tell the engineer more about what's going on. But what's useful in an alert?
13
+
14
+ When notified, an engineer often performs a set of procedures to gather information about the event before attempting to correct it. Imagine being able to automatically perform those procedures (or some subset) at the time of the alert. Imagine further, that the results of those procedures are embedded in the alert!
15
+
16
+ Enter ``nagios-herald``!
17
+
18
+ ### Generic Nagios Alert
19
+
20
+ Using the canonical (and oft-maligned) disk space check, here's an example notification:
21
+
22
+ ![vanilla-nagios-alert](/docs/images/vanilla-nagios.png)
23
+
24
+ While it does provide necessary information, it could be formatted for better legibility. For example,
25
+ the following line, which contains the information we need, is dense and may be difficult to
26
+ parse in the wee hours of the morning:
27
+
28
+ Additional Info: DISK WARNING - free space: / 1597 MB (8% inode=57%):
29
+ /dev/shm 24127 MB (100% inode=99%): /boot 152 MB (83% inode=99%):
30
+
31
+ Common questions would be **"Which volume is problematic?"** or
32
+ **"Why is this considered a 'WARNING' alert?"** In this example, it's not readily apparent what
33
+ those answers are. Let's add that context with ``nagios-herald``.
34
+
35
+ ### Nagios Alert with Context
36
+
37
+ ``nagios-herald`` can **highlight and colorize text**, **embed images** (such as Ganglia graphs), **include search results**, and much more.
38
+
39
+ The previous disk space alert example can be tailored to look like this:
40
+
41
+ ![html nagios email](docs/images/nagios-herald.png)
42
+
43
+ Notice the handy **stack bar** that clearly illustrates the problematic volume? See that **Ganglia graph**
44
+ showing disk space utilization for the node in the last 24 hours. Curious why the alert fired? Check
45
+ the **highlighted ``df`` output** that neatly defines which threshold was exceeded and why.
46
+
47
+ **NOTE**: In this example, the Nagios check ran ``df`` and supplied that input.
48
+
49
+ ### More Examples
50
+
51
+ For more examples of ``nagios-herald`` in action, see the [example alerts](/docs/example_alerts.md) page.
52
+
53
+ This is possible because ``nagios-herald`` provides extensible formatters.
54
+
55
+ ## Formatters
56
+
57
+ Adding context to alerts is done by the formatters. Formatters generate all the content that may
58
+ be used by one or more message types. For example, text returned by a Nagios check
59
+ can be highlighted to grab the operator's attention.
60
+
61
+ To learn more, see the [formatters](/docs/formatters.md) page.
62
+
63
+ # Installing ``nagios-herald``
64
+
65
+ Installation of ``nagios-herald`` is as easy as cloning this repository to a location of your choice.
66
+ To enable ``nagios-herald`` to send notifications, [configure Nagios](/docs/nagios-config.md) and,
67
+ optionally, write a [config.yml](/docs/config.md) file. At a minimum, specify the ``logfile`` configuration
68
+ variable.
69
+
70
+ ## Dependencies
71
+
72
+ ### Ruby Gems
73
+
74
+ ``nagios-herald`` and its tools depend on the following Ruby gems:
75
+
76
+ * ``app_conf``
77
+ * ``choice``
78
+ * ``mail``
79
+
80
+ ### Stack Bars
81
+
82
+ Generating stack bars requires the following (which are included in this project for your convenience):
83
+
84
+ * Python
85
+ * Python Image Library (PIL)
86
+
87
+ ## Configuring Nagios
88
+
89
+ To configure Nagios to use ``nagios-herald`` for notifications, see the [Nagios Configuration](/docs/nagios-config.md) page.
90
+
91
+ ### Icinga Support
92
+
93
+ ``nagios-herald`` supports Icinga too! Follow the instructions [here](/docs/config.md#icinga-support) to make it so.
94
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/unit/test_*.rb']
6
+ t.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Draw a set of 2 values stack bars
4
+ # Requires PIL and python > 2.6
5
+ # Install PIL using: yum install python-imaging
6
+
7
+ import sys
8
+ import os
9
+ from optparse import OptionParser
10
+
11
+ try:
12
+ import PIL
13
+ except ImportError:
14
+ sys.stderr.write("The Python Image Library (PIL) is required to use the draw_stack_bar module")
15
+ sys.stderr.write(" - you may try : 'sudo pip install pillow'\n")
16
+ sys.exit(1)
17
+
18
+ lib_path = os.path.normpath(os.path.join(os.path.dirname(__file__), '../', 'lib', 'stackbars'))
19
+ sys.path.append(lib_path)
20
+ from grouped_stackbars import GroupedStackbars
21
+
22
+ def parseData(data):
23
+ series = []
24
+ for i in data:
25
+ label, value = i.split('=')
26
+ try:
27
+ series.append((label.strip(), int(value)))
28
+ except:
29
+ print "Invalid format - value is not a number %s in '%s'" % (value, i)
30
+ sys.exit(1)
31
+ return series
32
+
33
+ def drawStackBars(series, options):
34
+ stacked_bars = GroupedStackbars(options)
35
+ stacked_bars.render(series)
36
+ stacked_bars.save(options.get('output_file'))
37
+
38
+ def parse_options():
39
+ usage = "usage: %prog [options] label=value label=value"
40
+
41
+ parser = OptionParser(usage = usage)
42
+
43
+ parser.add_option("-w", "--width", type="int",
44
+ help="Picture width",
45
+ dest="width", default=300)
46
+
47
+ parser.add_option("-o", "--output", type="string",
48
+ help="The file name to save the results in",
49
+ dest="output_file", default='stacked_bars.png')
50
+
51
+ parser.add_option("--bar-area-ratio", type="float",
52
+ help="How wide should the bar area be compared to the total width",
53
+ dest="bar_area_ratio", default=.75)
54
+
55
+ parser.add_option("--bar-height-ratio", type="float",
56
+ help="How tall should the bars be compared to their width",
57
+ dest="bar_height_ratio", default=.2)
58
+
59
+ parser.add_option("--bar-border", type="int",
60
+ help="Width of the border around the bars",
61
+ dest="bar_border", default=1)
62
+
63
+ options, data = parser.parse_args()
64
+ if not data:
65
+ sys.stderr.write("No data to plot !\n\n")
66
+ parser.print_help()
67
+ sys.exit(1)
68
+ return options, data
69
+
70
+ if __name__=='__main__':
71
+ options, data = parse_options()
72
+ series = parseData(data)
73
+ drawStackBars(series, vars(options))
74
+
75
+
76
+
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+ # Dump the environment as Nagios sees it; useful for generating environment files to test with new formatters
3
+ #
4
+ # CONFIG NOTES
5
+ # In commands.cfg, add a definition similar to the following:
6
+ #
7
+ # 'dump-env' command definition; dump Nagios' environment (use sparingly)
8
+ #define command {
9
+ # command_name dump-env
10
+ # command_line /usr/local/nagios-herald/bin/dump_nagios_env.sh
11
+ #}
12
+ #
13
+ # In contacts.cfg, append the 'dump-env' short command to one's 'service_notification_commands' like so:
14
+ #
15
+ #define contact {
16
+ # contact_name ops
17
+ # alias Ops Engineer
18
+ # email ops@example.com
19
+ # use generic-contact
20
+ # service_notification_commands notify-service-by-email,dump-env
21
+ #}
22
+
23
+ LOGFILE="/tmp/nagios_env_$(date +%Y%m%d).log"
24
+ date >> $LOGFILE
25
+ env >> $LOGFILE
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'choice'
4
+ require 'app_conf'
5
+
6
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'nagios-herald'
8
+
9
+ program_name = File.basename($0)
10
+
11
+ Choice.options do
12
+ header ""
13
+ header "#{program_name} is used to generate images from Ganglia graphs."
14
+ header ""
15
+ header "It takes one or more hostnames and a single metric to build the appropriate URI(s) from which to generate images."
16
+ header "The script outputs the full path for each of the images that have been written."
17
+ header ""
18
+
19
+ option :config_file do
20
+ short "-c"
21
+ long "--config-file"
22
+ desc "Specify an alternate location for the config file."
23
+ default File.expand_path(File.join(File.dirname(__FILE__), '..', 'etc', 'config.yml'))
24
+ end
25
+
26
+ option :hosts, :required => true do
27
+ short "-h"
28
+ long "--host *HOST"
29
+ desc "The FQDN of the host required to look up a metric/image in Ganglia. Specify multiple hosts with multiple \'-h\' arguments."
30
+ end
31
+
32
+ option :metric, :required => true do
33
+ short "-m"
34
+ long "--metric"
35
+ desc "The name of the metric we want to see."
36
+ end
37
+
38
+ option :path do
39
+ short "-p"
40
+ long "--path"
41
+ desc "An optional path in which to write the image files."
42
+ desc "DEFAULT: /tmp"
43
+ default "/tmp"
44
+ end
45
+
46
+ option :range do
47
+ short "-r"
48
+ long "--range"
49
+ desc "The range of time for which the graph should look back."
50
+ desc "Acceptable values are the same as thouse used by Ganglia (i.e '8hours', '8h, '1day', '1d', '3weeks', '3w')"
51
+ desc "DEFAULT: 8h (8 hours)"
52
+ default "8h"
53
+ end
54
+
55
+ footer ""
56
+ footer "EXAMPLES"
57
+ footer "--------"
58
+ footer "1. Passing a single hostname and metric to #{program_name}:"
59
+ footer ""
60
+ footer "#{program_name} -h mysql01.example.com -m part_max_used"
61
+ footer ""
62
+ footer "2. Passing multiple hostnames and a metric to #{program_name}:"
63
+ footer ""
64
+ footer "#{program_name} -h mysql01.example.com -h memcached01.example.com -m disk_free"
65
+ footer ""
66
+ footer "3. Including an optional time range (12 hours):"
67
+ footer ""
68
+ footer "#{program_name} -h mysql01.example.com -h memcached01.example.com -m disk_free -r 12h"
69
+ footer ""
70
+ end
71
+
72
+ options = Choice.choices
73
+
74
+ # Load the config
75
+ abort("Config file not found #{options.config_file}") unless File.exists? options.config_file
76
+ config = AppConf.new
77
+ config.load( options.config_file )
78
+
79
+ ganglia = NagiosHerald::Helpers::GangliaGraph.new
80
+
81
+ image_paths = ganglia.get_graphs( options.hosts, options.metric, options.path, options.range )
82
+ puts image_paths.join( ", " ) if image_paths
data/bin/get_graph ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'choice'
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'nagios-herald'
6
+
7
+ program_name = File.basename($0)
8
+
9
+ Choice.options do
10
+ header ""
11
+ header "#{program_name} is used to generate images from given URIs."
12
+ header ""
13
+ header "It takes one or more URIs from which to generate images."
14
+ header "The script outputs the full path for each of the images that have been written."
15
+ header ""
16
+
17
+ option :path do
18
+ short "-p"
19
+ long "--path"
20
+ desc "An optional path in which to write the image files."
21
+ desc "DEFAULT: /tmp"
22
+ default "/tmp"
23
+ end
24
+
25
+ option :uris, :required => true do
26
+ short "-u"
27
+ long "--uri *URI"
28
+ desc "The URI from which to generate an image. Specify multiple URIs with multiple \'-u\' arguments."
29
+ end
30
+
31
+ footer ""
32
+ footer "EXAMPLES"
33
+ footer "--------"
34
+ footer "1. Passing a single URI to #{program_name}:"
35
+ footer ""
36
+ footer "#{program_name} -u \"http://graphite.example.com/render/?target=mysql.connections.count\""
37
+ footer ""
38
+ footer "2. Passing multiple URIs to #{program_name}:"
39
+ footer "(line breaks added for clarity)"
40
+ footer ""
41
+ footer "#{program_name} -u \"http://graphite.example.com/render/?target=mysql.connections.count\" \\"
42
+ footer " -u \"http://graphite.example.com/render/?target=apache.requests_per_second\""
43
+ footer ""
44
+ end
45
+
46
+ path = Choice[:path] if Choice[:path]
47
+ uris = Choice[:uris] if Choice[:uris]
48
+
49
+ image_paths = NagiosHerald::Helpers::UrlImage.download_images( uris, path )
50
+ puts image_paths.join( ", " )
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'choice'
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'nagios-herald'
6
+
7
+ program_name = File.basename($0)
8
+
9
+ Choice.options do
10
+ header ""
11
+ header "#{program_name} is used to generate images from Graphite URIs."
12
+ header ""
13
+ header "It takes a URI from which to generate a Graphite image."
14
+ header "Optionally, an historical graph can be generated to compare to the first."
15
+ header "The script outputs the full path for each of the images that have been written."
16
+ header ""
17
+
18
+ option :historical_graph do
19
+ short "-h"
20
+ long "--historical-graph"
21
+ desc "Generate an historical graph to compare to the original image (i.e. past 24-hour period)."
22
+ default false
23
+ end
24
+
25
+ option :path do
26
+ short "-p"
27
+ long "--path"
28
+ desc "An optional path in which to write the image files."
29
+ desc "DEFAULT: /tmp"
30
+ default "/tmp"
31
+ end
32
+
33
+ option :uri, :required => true do
34
+ short "-u"
35
+ long "--uri"
36
+ desc "The URI from which to generate an image."
37
+ end
38
+
39
+ footer ""
40
+ footer "EXAMPLES"
41
+ footer "--------"
42
+ footer "1. Passing a URI to #{program_name}:"
43
+ footer ""
44
+ footer "#{program_name} -u \"http://graphite.example.com/render/?target=mysql.connections.count\""
45
+ footer ""
46
+ footer "2. Passing a URI to #{program_name} and generating an historical graph:"
47
+ footer ""
48
+ footer "#{program_name} -u \"http://graphite.example.com/render/?target=mysql.connections.count\" -h"
49
+ footer ""
50
+ end
51
+
52
+ historical_graph = true if Choice[:historical_graph]
53
+ path = Choice[:path]
54
+ uri = Choice[:uri]
55
+
56
+ graphite = NagiosHerald::Helpers::GraphiteGraph.new
57
+ image_paths = graphite.get_graph(uri, path, historical_graph)
58
+ puts image_paths.join(", ") if image_paths
data/bin/nagios-herald ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'nagios-herald'
4
+ require 'nagios-herald/executor'
5
+
6
+ NagiosHerald::Executor.new.announce
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # splunk_alert_frequency.rb
5
+ #
6
+
7
+ require 'choice'
8
+ require 'app_conf'
9
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
10
+ require 'nagios-herald'
11
+
12
+ program_name = File.basename( $0 )
13
+ Choice.options do
14
+ header ""
15
+ header "#{program_name} will search Splunk for Nagios events, that match the given service name, in the past n days."
16
+ header ""
17
+
18
+ option :duration do
19
+ short "-d"
20
+ long "--duration"
21
+ desc "The number of days to search back through Nagios events. DEFAULT: 1 day"
22
+ default 1
23
+ end
24
+
25
+ option :hostname, :required => true do
26
+ short "-h"
27
+ long "--hostname"
28
+ desc "[REQUIRED] The hostname to search for. Expects the Etsy Nagios-type hostname (i.e. web0200.ny4)."
29
+ desc "NOTE: If '--service-name' is not specified, will look for alert where this host was in the DOWN state."
30
+ end
31
+
32
+ option :service_name do
33
+ short "-s"
34
+ long "--service-name"
35
+ desc "The name of the service to search for. It may be necessary to surround the service name with double quotes."
36
+ default nil
37
+ end
38
+
39
+ option :config_file do
40
+ short "-c"
41
+ long "--config-file"
42
+ desc "Specify an alternate location for the config file."
43
+ default File.expand_path(File.join(File.dirname(__FILE__), '..', 'etc', 'config.yml'))
44
+ end
45
+
46
+ footer ""
47
+ end
48
+
49
+ config = AppConf.new
50
+ config.load( Choice[:config_file] )
51
+
52
+ reporter = NagiosHerald::Helpers::SplunkReporter.new(config['splunk']['url'],config['splunk']['username'], config['splunk']['password'])
53
+ puts reporter.get_alert_frequency(Choice[:hostname], Choice[:service_name], {:duration => Choice[:duration]})
54
+