Imported Upstream version 0.13.6
Sébastien Delafond
8 years ago
0 | == 0.13.6 / 2015-02-21 | |
1 | * Minor Enhancements | |
2 | * sensu notifier (#199) | |
3 | ||
4 | == 0.13.5 / 2015-01-09 | |
5 | * Minor Enhancements | |
6 | * statsd notifier (#144) | |
7 | * Slack notifier (#172) | |
8 | * Bug fixes | |
9 | * Add support for Ruby 2.2.0 (#206) | |
10 | * Fix tests for Ruby 2.0 (#205) | |
11 | * Make group assignment more like login (#159) | |
12 | * Flush file descriptors to prevent too many processes from being started (#141) | |
13 | * Allow SSL URLs (#168) | |
14 | * Documentation fixes | |
15 | * Clarify Hipchat privilege requirements (#176) | |
16 | ||
0 | 17 | == 0.13.4 / 2014-03-05 |
1 | 18 | * Minor Enhancements |
2 | 19 | * Hipchat reporter (#162) |
435 | 435 | restart operations. You can define as many watches as you like. In the example |
436 | 436 | above, I've got some Rails instances running in Mongrels that I need to keep |
437 | 437 | alive. Every watch must have a unique `name` so that it can be identified |
438 | later on. The `start` and `stop` attributes specify the commands to start | |
439 | and stop the process. If no `restart` attribute is set, restart will be | |
438 | later on. The `start` and `stop` attributes specify the commands to start | |
439 | and stop the process. If no `restart` attribute is set, restart will be | |
440 | 440 | represented by a call to stop followed by a call to start. The |
441 | 441 | optional `grace` attribute sets the amount of time following a |
442 | 442 | start/stop/restart command to wait before resuming normal monitoring |
574 | 574 | Need to watch a script that doesn't have built in daemonization? No problem! |
575 | 575 | God will daemonize and keep track of your process for you. If you don't |
576 | 576 | specify a `pid_file` attribute for a watch, it will be auto-daemonized and a |
577 | PID file will be stored for it in `/var/run/god`. | |
577 | PID file will be stored for it in `/var/run/god`. | |
578 | 578 | |
579 | 579 | |
580 | 580 | ```ruby |
584 | 584 | God.watch do |w| |
585 | 585 | w.name = 'mongrel' |
586 | 586 | w.pid_file = w.pid_file = File.join(RAILS_ROOT, "log/mongrel.pid") |
587 | ||
587 | ||
588 | 588 | w.start = "mongrel_rails start -P #{RAILS_ROOT}/log/mongrel.pid -d" |
589 | ||
589 | ||
590 | 590 | # ... |
591 | 591 | end |
592 | 592 | |
594 | 594 | God.watch do |w| |
595 | 595 | w.name = 'worker' |
596 | 596 | # w.pid_file = is not set |
597 | ||
597 | ||
598 | 598 | w.start = "rake resque:worker" |
599 | ||
599 | ||
600 | 600 | # ... |
601 | 601 | end |
602 | 602 | ``` |
603 | 603 | |
604 | 604 | |
605 | If you'd rather have the PID file stored in a different location, you can | |
605 | If you'd rather have the PID file stored in a different location, you can | |
606 | 606 | set it at the top of your config: |
607 | 607 | |
608 | 608 | ```ruby |
1020 | 1020 | (default: false). |
1021 | 1021 | from - The String representing who the message should be sent as. |
1022 | 1022 | ``` |
1023 | ||
1024 | NOTE: in Hipchat you must have a token with 'admin' privileges. 'Notification' privileges will not be enough. | |
1023 | 1025 | |
1024 | 1026 | |
1025 | 1027 | ~~~~~ |
1242 | 1244 | apikey - The String API key. |
1243 | 1245 | ``` |
1244 | 1246 | |
1247 | Slack | |
1248 | ~~~~~ | |
1249 | ||
1250 | Send a message to a channel in Slack (https://slack.com/). | |
1251 | ||
1252 | First, set up an Incoming Webhook in your Slack account. | |
1253 | ||
1254 | Then, in your God configuration, set the defaults: | |
1255 | ||
1256 | ```ruby | |
1257 | God::Contacts::Slack.defaults do |d| | |
1258 | d.account = "foo" | |
1259 | d.token = "abc123abc123abc123" | |
1260 | c.notify_channel = true | |
1261 | c.format = '%{host} alert: %{message}' | |
1262 | end | |
1263 | ``` | |
1264 | ||
1265 | `account` is the name of your Slack account; if you view slack at | |
1266 | "foo.slack.com", then your account is "foo". `token` is from your | |
1267 | newly-created webhook, and will be a string of unintelligible | |
1268 | characters. | |
1269 | ||
1270 | The `notify_channel` and `format` settings are optional. The first | |
1271 | controls whether the message includes `@channel` (sending notifications | |
1272 | to everyone in the channel); the second controls how the message is | |
1273 | formatted. Acceptable values within the format are `priority`, `host`, | |
1274 | `message`, `category`, and `time`. | |
1275 | ||
1276 | Once you've set the defaults, create contacts for the channels that you | |
1277 | want to notify. You can create as many as you like, and they'll look | |
1278 | something like this: | |
1279 | ||
1280 | ```ruby | |
1281 | God.contact(:slack) do |c| | |
1282 | c.name = '#ops' | |
1283 | c.channel = '#ops' | |
1284 | end | |
1285 | ``` | |
1286 | ||
1245 | 1287 | ///////////////////////////////////////////////////////////////////////////// |
1246 | 1288 | ///////////////////////////////////////////////////////////////////////////// |
1247 | 1289 |
8 | 8 | end |
9 | 9 | end |
10 | 10 | |
11 | have_func('rb_wait_for_single_fd') | |
11 | 12 | case RUBY_PLATFORM |
12 | 13 | when /bsd/i, /darwin/i |
13 | 14 | unless have_header('sys/event.h') |
3 | 3 | #include <sys/event.h> |
4 | 4 | #include <sys/time.h> |
5 | 5 | #include <errno.h> |
6 | ||
7 | #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD | |
8 | #include <ruby/io.h> | |
9 | #endif | |
6 | 10 | |
7 | 11 | static VALUE mGod; |
8 | 12 | static VALUE cKQueueHandler; |
62 | 66 | { |
63 | 67 | int nevents, i, num_to_fetch; |
64 | 68 | struct kevent *events; |
69 | ||
70 | #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD | |
71 | rb_wait_for_single_fd(kq, RB_WAITFD_IN, NULL); | |
72 | #else | |
65 | 73 | fd_set read_set; |
66 | 74 | |
67 | 75 | FD_ZERO(&read_set); |
69 | 77 | |
70 | 78 | // Don't actually run this method until we've got an event |
71 | 79 | rb_thread_select(kq + 1, &read_set, NULL, NULL, NULL); |
72 | ||
80 | #endif | |
73 | 81 | // Grabbing num_events once for thread safety |
74 | 82 | num_to_fetch = num_events; |
75 | 83 | events = (struct kevent*)malloc(num_to_fetch * sizeof(struct kevent)); |
0 | 0 | #ifdef __linux__ /* only build on linux */ |
1 | 1 | |
2 | 2 | #include <ruby.h> |
3 | ||
4 | #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD | |
5 | #include <ruby/io.h> | |
6 | #endif | |
7 | ||
8 | ||
3 | 9 | #include <sys/types.h> |
4 | 10 | #include <unistd.h> |
5 | 11 | #include <sys/socket.h> |
30 | 36 | |
31 | 37 | VALUE extra_data; |
32 | 38 | |
39 | #ifdef HAVE_RB_WAIT_FOR_SINGLE_FD | |
40 | int ret; | |
41 | if((ret = rb_wait_for_single_fd(nl_sock, RB_WAITFD_IN, NULL)) < 0){ | |
42 | rb_raise(rb_eStandardError, "%s", strerror(errno)); | |
43 | } | |
44 | /* If there were no events detected, return */ | |
45 | if(!(ret & RB_WAITFD_IN)){ | |
46 | return INT2FIX(0); | |
47 | } | |
48 | #else | |
33 | 49 | fd_set fds; |
34 | 50 | |
35 | 51 | FD_ZERO(&fds); |
43 | 59 | if (! FD_ISSET(nl_sock, &fds)) { |
44 | 60 | return INT2FIX(0); |
45 | 61 | } |
62 | #endif | |
46 | 63 | |
47 | 64 | /* if there are events, make calls */ |
48 | 65 | if (-1 == recv(nl_sock, buff, sizeof(buff), 0)) { |
2 | 2 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= |
3 | 3 | |
4 | 4 | s.name = 'god' |
5 | s.version = '0.13.4' | |
6 | s.date = '2014-03-05' | |
5 | s.version = '0.13.6' | |
6 | s.date = '2015-03-21' | |
7 | 7 | |
8 | 8 | s.summary = "Process monitoring framework." |
9 | 9 | s.description = "An easy to configure, easy to extend monitoring framework written in Ruby." |
24 | 24 | |
25 | 25 | s.add_development_dependency('json', '~> 1.6') |
26 | 26 | s.add_development_dependency('rake') |
27 | s.add_development_dependency('minitest') | |
27 | 28 | s.add_development_dependency('rdoc', '~> 3.10') |
28 | 29 | s.add_development_dependency('twitter', '~> 4.0') |
29 | 30 | s.add_development_dependency('prowly', '~> 0.3') |
30 | 31 | s.add_development_dependency('xmpp4r', '~> 0.5') |
31 | 32 | s.add_development_dependency('dike', '~> 0.0.3') |
32 | s.add_development_dependency('rcov', '~> 0.9') | |
33 | # s.add_development_dependency('rcov', '~> 0.9') | |
33 | 34 | s.add_development_dependency('daemons', '~> 1.1') |
34 | 35 | s.add_development_dependency('mocha', '~> 0.10') |
35 | 36 | s.add_development_dependency('gollum', '~> 1.3.1') |
37 | #the last version to support 1.8.7 is 0.99.6 | |
38 | s.add_development_dependency('mustache', ['~> 0.99.0', '< 0.99.7']) | |
36 | 39 | s.add_development_dependency('airbrake', '~> 3.1.7') |
37 | 40 | s.add_development_dependency('nokogiri', '~> 1.5.0') |
38 | 41 | s.add_development_dependency('activesupport', [ '>= 2.3.10', '< 4.0.0' ]) |
42 | s.add_development_dependency('statsd-ruby') | |
43 | s.add_development_dependency('i18n', '< 0.7.0') | |
39 | 44 | # = MANIFEST = |
40 | 45 | s.files = %w[ |
41 | 46 | Announce.txt |
86 | 91 | lib/god/contacts/jabber.rb |
87 | 92 | lib/god/contacts/prowl.rb |
88 | 93 | lib/god/contacts/scout.rb |
94 | lib/god/contacts/sensu.rb | |
95 | lib/god/contacts/slack.rb | |
96 | lib/god/contacts/statsd.rb | |
89 | 97 | lib/god/contacts/twitter.rb |
90 | 98 | lib/god/contacts/webhook.rb |
91 | 99 | lib/god/driver.rb |
161 | 169 | test/test_process.rb |
162 | 170 | test/test_prowl.rb |
163 | 171 | test/test_registry.rb |
172 | test/test_sensu.rb | |
173 | test/test_slack.rb | |
164 | 174 | test/test_socket.rb |
175 | test/test_statsd.rb | |
165 | 176 | test/test_sugar.rb |
166 | 177 | test/test_system_portable_poller.rb |
167 | 178 | test/test_system_process.rb |
0 | # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
1 | # Send a notice to a SENSU client socket, port 3030 on 'localhost' only. | |
2 | # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
3 | # [mandatory] | |
4 | # check_name - a unique check name | |
5 | # | |
6 | # [optional] | |
7 | # status_code - status codes used are 0 for OK, 1 for WARNING, 2 for CRITICAL, and 3 or greater to indicate UNKNOWN or CUSTOM. | |
8 | # handler - default handler | |
9 | # | |
10 | ||
11 | CONTACT_DEPS[:sensu] = ['json'] | |
12 | CONTACT_DEPS[:sensu].each do |d| | |
13 | require d | |
14 | end | |
15 | ||
16 | module God | |
17 | module Contacts | |
18 | ||
19 | class Sensu < Contact | |
20 | class << self | |
21 | attr_accessor :check_name, :status_code, :handler, :host, :port | |
22 | end | |
23 | ||
24 | self.status_code = 2 | |
25 | self.handler = 'default' | |
26 | self.host = 'localhost' | |
27 | self.port = 3030 | |
28 | ||
29 | def valid? | |
30 | valid = true | |
31 | valid &= complain("Attribute 'check_name' must be specified", self) unless arg(:check_name) | |
32 | valid | |
33 | end | |
34 | ||
35 | attr_accessor :check_name, :status_code, :handler, :host, :port | |
36 | ||
37 | def sensu_client_socket(msg) | |
38 | u = UDPSocket.new | |
39 | u.send(msg + "\n", 0, arg(:host).nil? ? self.host : arg(:host), arg(:port).nil? ? self.port : arg(:port)) | |
40 | u.close | |
41 | end | |
42 | ||
43 | def notify(message, time, priority, category, host) | |
44 | data = { | |
45 | :category => category, | |
46 | :message => message, | |
47 | :priority => priority, | |
48 | :host => host, | |
49 | :time => time, | |
50 | } | |
51 | parcel = { 'name' => arg(:check_name), 'status' => arg(:status_code).nil? ? self.status_code : arg(:status_code), 'output' => data.to_json, 'handler' => arg(:handler).empty? ? self.handler : arg(:handler), 'executed' => Time.now.to_i } | |
52 | sensu_client_socket parcel.to_json | |
53 | self.info = "notified sensu: #{arg(:check_name)}" | |
54 | end | |
55 | end | |
56 | end | |
57 | end | |
58 |
0 | # Send a message to a Slack channel | |
1 | # | |
2 | # account - The name of your Slack account (visible in URL, e.g. foo.slack.com) | |
3 | # token - The token of the webhook created in Slack | |
4 | # channel - The name of the channel to send the message to, prefixed with # | |
5 | # notify_channel - Whether to send an "@channel" in the message, to alert everyone in the channel | |
6 | # format - An optional format string to change how the alert is displayed | |
7 | ||
8 | require 'net/http' | |
9 | require 'uri' | |
10 | ||
11 | CONTACT_DEPS[:slack] = ['json'] | |
12 | CONTACT_DEPS[:slack].each do |d| | |
13 | require d | |
14 | end | |
15 | ||
16 | module God | |
17 | module Contacts | |
18 | ||
19 | class Slack < Contact | |
20 | class << self | |
21 | attr_accessor :account, :token, :channel, :notify_channel, :format, :username, :emoji | |
22 | end | |
23 | ||
24 | self.channel = "#general" | |
25 | self.notify_channel = false | |
26 | self.format = "%{priority} alert on %{host}: %{message} (%{category}, %{time})" | |
27 | ||
28 | def valid? | |
29 | valid = true | |
30 | valid &= complain("Attribute 'account' must be specified", self) unless arg(:account) | |
31 | valid &= complain("Attribute 'token' must be specified", self) unless arg(:token) | |
32 | valid | |
33 | end | |
34 | ||
35 | attr_accessor :account, :token, :channel, :notify_channel, :format, :username, :emoji | |
36 | ||
37 | def text(data) | |
38 | text = "" | |
39 | text << "<!channel> " if arg(:notify_channel) | |
40 | ||
41 | if RUBY_VERSION =~ /^1\.8/ | |
42 | text << arg(:format).gsub(/%\{(\w+)\}/) do |match| | |
43 | data[$1.to_sym] | |
44 | end | |
45 | else | |
46 | text << arg(:format) % data | |
47 | end | |
48 | ||
49 | text | |
50 | end | |
51 | ||
52 | def notify(message, time, priority, category, host) | |
53 | text = text({ | |
54 | :message => message, | |
55 | :time => time, | |
56 | :priority => priority, | |
57 | :category => category, | |
58 | :host => host | |
59 | }) | |
60 | ||
61 | request(text) | |
62 | end | |
63 | ||
64 | def api_url | |
65 | URI.parse("https://#{arg(:account)}.slack.com/services/hooks/incoming-webhook?token=#{arg(:token)}") | |
66 | end | |
67 | ||
68 | def request(text) | |
69 | http = Net::HTTP.new(api_url.host, api_url.port) | |
70 | http.use_ssl = true | |
71 | ||
72 | req = Net::HTTP::Post.new(api_url.request_uri) | |
73 | req.body = { | |
74 | :link_names => 1, | |
75 | :text => text, | |
76 | :channel => arg(:channel) | |
77 | }.tap { |payload| | |
78 | payload[:username] = arg(:username) if arg(:username) | |
79 | payload[:icon_emoji] = arg(:emoji) if arg(:emoji) | |
80 | }.to_json | |
81 | ||
82 | res = http.request(req) | |
83 | ||
84 | case res | |
85 | when Net::HTTPSuccess | |
86 | self.info = "successfully notified slack on channel #{arg(:channel)}" | |
87 | else | |
88 | self.info = "failed to send webhook to #{arg(:url)}: #{res.error!}" | |
89 | end | |
90 | rescue Object => e | |
91 | applog(nil, :info, "failed to send webhook to #{arg(:url)}: #{e.message}") | |
92 | applog(nil, :debug, e.backtrace.join("\n")) | |
93 | end | |
94 | ||
95 | end | |
96 | ||
97 | end | |
98 | end | |
99 |
0 | # Send a notice to statsd | |
1 | # | |
2 | # host - statsd host | |
3 | # port - statsd port (optional) | |
4 | ||
5 | require 'statsd-ruby' | |
6 | ||
7 | module God | |
8 | module Contacts | |
9 | ||
10 | class Statsd < Contact | |
11 | class << self | |
12 | attr_accessor :host, :port | |
13 | end | |
14 | ||
15 | attr_accessor :host, :port | |
16 | ||
17 | def valid? | |
18 | valid = true | |
19 | valid &= complain("Attribute 'statsd_host' must be specified", self) unless arg(:host) | |
20 | valid | |
21 | end | |
22 | ||
23 | def notify(message, time, priority, category, hostname) | |
24 | statsd = ::Statsd.new host, (port ? port.to_i : 8125) # 8125 is the default statsd port | |
25 | ||
26 | hostname.gsub! /\./, '_' | |
27 | app = message.gsub /([^\s]*).*/, '\1' | |
28 | ||
29 | [ | |
30 | 'cpu out of bounds', | |
31 | 'memory out of bounds', | |
32 | 'process is flapping' | |
33 | ].each do |event_type| | |
34 | statsd.increment "god.#{event_type.gsub(/\s/, '_')}.#{hostname}.#{app}" if message.include? event_type | |
35 | end | |
36 | ||
37 | self.info = 'sent statsd alert' | |
38 | rescue => e | |
39 | applog(nil, :info, "failed to send statsd alert: #{e.message}") | |
40 | applog(nil, :debug, e.backtrace.join("\n")) | |
41 | end | |
42 | end | |
43 | ||
44 | end | |
45 | end |
40 | 40 | |
41 | 41 | uri = URI.parse(arg(:url)) |
42 | 42 | http = Net::HTTP.new(uri.host, uri.port) |
43 | http.use_ssl = true if uri.scheme == "https" | |
43 | 44 | |
44 | 45 | req = nil |
45 | 46 | res = nil |
31 | 31 | begin |
32 | 32 | uid_num = Etc.getpwnam(self.uid).uid if self.uid |
33 | 33 | gid_num = Etc.getgrnam(self.gid).gid if self.gid |
34 | gid_num = Etc.getpwnam(self.uid).gid if self.gid.nil? && self.uid | |
34 | 35 | |
35 | 36 | ::Dir.chroot(self.chroot) if self.chroot |
36 | ::Process.groups = [gid_num] if self.gid | |
37 | ::Process::Sys.setgid(gid_num) if self.gid | |
37 | ::Process.groups = [gid_num] if gid_num | |
38 | ::Process.initgroups(self.uid, gid_num) if self.uid && gid_num | |
39 | ::Process::Sys.setgid(gid_num) if gid_num | |
38 | 40 | ::Process::Sys.setuid(uid_num) if self.uid |
39 | 41 | rescue ArgumentError, Errno::EPERM, Errno::ENOENT |
40 | 42 | exit(1) |
41 | 43 | end |
42 | 44 | |
43 | File.writable?(file_in_chroot(file)) ? exit(0) : exit(1) | |
45 | File.writable?(file_in_chroot(file)) ? exit!(0) : exit!(1) | |
44 | 46 | end |
45 | 47 | |
46 | 48 | wpid, status = ::Process.waitpid2(pid) |
245 | 247 | r.close |
246 | 248 | pid = self.spawn(command) |
247 | 249 | puts pid.to_s # send pid back to forker |
250 | exit!(0) | |
248 | 251 | end |
249 | 252 | |
250 | 253 | ::Process.waitpid(opid, 0) |
294 | 297 | File.umask self.umask if self.umask |
295 | 298 | uid_num = Etc.getpwnam(self.uid).uid if self.uid |
296 | 299 | gid_num = Etc.getgrnam(self.gid).gid if self.gid |
300 | gid_num = Etc.getpwnam(self.uid).gid if self.gid.nil? && self.uid | |
297 | 301 | |
298 | 302 | ::Dir.chroot(self.chroot) if self.chroot |
299 | 303 | ::Process.setsid |
300 | ::Process.groups = [gid_num] if self.gid | |
301 | ::Process::Sys.setgid(gid_num) if self.gid | |
304 | ::Process.groups = [gid_num] if gid_num | |
305 | ::Process.initgroups(self.uid, gid_num) if self.uid && gid_num | |
306 | ::Process::Sys.setgid(gid_num) if gid_num | |
302 | 307 | ::Process::Sys.setuid(uid_num) if self.uid |
303 | 308 | self.dir ||= '/' |
304 | 309 | Dir.chdir self.dir |
89 | 89 | load_contact(:jabber) |
90 | 90 | load_contact(:prowl) |
91 | 91 | load_contact(:scout) |
92 | load_contact(:statsd) | |
92 | 93 | load_contact(:twitter) |
93 | 94 | load_contact(:webhook) |
94 | 95 | load_contact(:airbrake) |
96 | load_contact(:slack) | |
97 | load_contact(:sensu) | |
95 | 98 | |
96 | 99 | $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god]) |
97 | 100 | |
157 | 160 | |
158 | 161 | module God |
159 | 162 | # The String version number for this package. |
160 | VERSION = '0.13.4' | |
163 | VERSION = '0.13.6' | |
161 | 164 | |
162 | 165 | # The Integer number of lines of backlog to keep for the logger. |
163 | 166 | LOG_BUFFER_SIZE_DEFAULT = 100 |
0 | 0 | --- !ruby/object:Gem::Specification |
1 | 1 | name: god |
2 | 2 | version: !ruby/object:Gem::Version |
3 | hash: 35 | |
3 | hash: 39 | |
4 | 4 | prerelease: |
5 | 5 | segments: |
6 | 6 | - 0 |
7 | 7 | - 13 |
8 | - 4 | |
9 | version: 0.13.4 | |
8 | - 6 | |
9 | version: 0.13.6 | |
10 | 10 | platform: ruby |
11 | 11 | authors: |
12 | 12 | - Tom Preston-Werner |
16 | 16 | bindir: bin |
17 | 17 | cert_chain: [] |
18 | 18 | |
19 | date: 2014-03-05 00:00:00 -08:00 | |
19 | date: 2015-03-21 00:00:00 -07:00 | |
20 | 20 | default_executable: |
21 | 21 | dependencies: |
22 | 22 | - !ruby/object:Gem::Dependency |
50 | 50 | type: :development |
51 | 51 | - !ruby/object:Gem::Dependency |
52 | 52 | version_requirements: &id003 !ruby/object:Gem::Requirement |
53 | none: false | |
54 | requirements: | |
55 | - - ">=" | |
56 | - !ruby/object:Gem::Version | |
57 | hash: 3 | |
58 | segments: | |
59 | - 0 | |
60 | version: "0" | |
61 | prerelease: false | |
62 | requirement: *id003 | |
63 | name: minitest | |
64 | type: :development | |
65 | - !ruby/object:Gem::Dependency | |
66 | version_requirements: &id004 !ruby/object:Gem::Requirement | |
53 | 67 | none: false |
54 | 68 | requirements: |
55 | 69 | - - ~> |
60 | 74 | - 10 |
61 | 75 | version: "3.10" |
62 | 76 | prerelease: false |
63 | requirement: *id003 | |
77 | requirement: *id004 | |
64 | 78 | name: rdoc |
65 | 79 | type: :development |
66 | 80 | - !ruby/object:Gem::Dependency |
67 | version_requirements: &id004 !ruby/object:Gem::Requirement | |
81 | version_requirements: &id005 !ruby/object:Gem::Requirement | |
68 | 82 | none: false |
69 | 83 | requirements: |
70 | 84 | - - ~> |
75 | 89 | - 0 |
76 | 90 | version: "4.0" |
77 | 91 | prerelease: false |
78 | requirement: *id004 | |
92 | requirement: *id005 | |
79 | 93 | name: twitter |
80 | 94 | type: :development |
81 | 95 | - !ruby/object:Gem::Dependency |
82 | version_requirements: &id005 !ruby/object:Gem::Requirement | |
96 | version_requirements: &id006 !ruby/object:Gem::Requirement | |
83 | 97 | none: false |
84 | 98 | requirements: |
85 | 99 | - - ~> |
90 | 104 | - 3 |
91 | 105 | version: "0.3" |
92 | 106 | prerelease: false |
93 | requirement: *id005 | |
107 | requirement: *id006 | |
94 | 108 | name: prowly |
95 | 109 | type: :development |
96 | 110 | - !ruby/object:Gem::Dependency |
97 | version_requirements: &id006 !ruby/object:Gem::Requirement | |
111 | version_requirements: &id007 !ruby/object:Gem::Requirement | |
98 | 112 | none: false |
99 | 113 | requirements: |
100 | 114 | - - ~> |
105 | 119 | - 5 |
106 | 120 | version: "0.5" |
107 | 121 | prerelease: false |
108 | requirement: *id006 | |
122 | requirement: *id007 | |
109 | 123 | name: xmpp4r |
110 | 124 | type: :development |
111 | 125 | - !ruby/object:Gem::Dependency |
112 | version_requirements: &id007 !ruby/object:Gem::Requirement | |
126 | version_requirements: &id008 !ruby/object:Gem::Requirement | |
113 | 127 | none: false |
114 | 128 | requirements: |
115 | 129 | - - ~> |
121 | 135 | - 3 |
122 | 136 | version: 0.0.3 |
123 | 137 | prerelease: false |
124 | requirement: *id007 | |
138 | requirement: *id008 | |
125 | 139 | name: dike |
126 | type: :development | |
127 | - !ruby/object:Gem::Dependency | |
128 | version_requirements: &id008 !ruby/object:Gem::Requirement | |
129 | none: false | |
130 | requirements: | |
131 | - - ~> | |
132 | - !ruby/object:Gem::Version | |
133 | hash: 25 | |
134 | segments: | |
135 | - 0 | |
136 | - 9 | |
137 | version: "0.9" | |
138 | prerelease: false | |
139 | requirement: *id008 | |
140 | name: rcov | |
141 | 140 | type: :development |
142 | 141 | - !ruby/object:Gem::Dependency |
143 | 142 | version_requirements: &id009 !ruby/object:Gem::Requirement |
191 | 190 | requirements: |
192 | 191 | - - ~> |
193 | 192 | - !ruby/object:Gem::Version |
193 | hash: 403 | |
194 | segments: | |
195 | - 0 | |
196 | - 99 | |
197 | - 0 | |
198 | version: 0.99.0 | |
199 | - - < | |
200 | - !ruby/object:Gem::Version | |
201 | hash: 413 | |
202 | segments: | |
203 | - 0 | |
204 | - 99 | |
205 | - 7 | |
206 | version: 0.99.7 | |
207 | prerelease: false | |
208 | requirement: *id012 | |
209 | name: mustache | |
210 | type: :development | |
211 | - !ruby/object:Gem::Dependency | |
212 | version_requirements: &id013 !ruby/object:Gem::Requirement | |
213 | none: false | |
214 | requirements: | |
215 | - - ~> | |
216 | - !ruby/object:Gem::Version | |
194 | 217 | hash: 13 |
195 | 218 | segments: |
196 | 219 | - 3 |
198 | 221 | - 7 |
199 | 222 | version: 3.1.7 |
200 | 223 | prerelease: false |
201 | requirement: *id012 | |
224 | requirement: *id013 | |
202 | 225 | name: airbrake |
203 | 226 | type: :development |
204 | 227 | - !ruby/object:Gem::Dependency |
205 | version_requirements: &id013 !ruby/object:Gem::Requirement | |
228 | version_requirements: &id014 !ruby/object:Gem::Requirement | |
206 | 229 | none: false |
207 | 230 | requirements: |
208 | 231 | - - ~> |
214 | 237 | - 0 |
215 | 238 | version: 1.5.0 |
216 | 239 | prerelease: false |
217 | requirement: *id013 | |
240 | requirement: *id014 | |
218 | 241 | name: nokogiri |
219 | 242 | type: :development |
220 | 243 | - !ruby/object:Gem::Dependency |
221 | version_requirements: &id014 !ruby/object:Gem::Requirement | |
244 | version_requirements: &id015 !ruby/object:Gem::Requirement | |
222 | 245 | none: false |
223 | 246 | requirements: |
224 | 247 | - - ">=" |
238 | 261 | - 0 |
239 | 262 | version: 4.0.0 |
240 | 263 | prerelease: false |
241 | requirement: *id014 | |
264 | requirement: *id015 | |
242 | 265 | name: activesupport |
266 | type: :development | |
267 | - !ruby/object:Gem::Dependency | |
268 | version_requirements: &id016 !ruby/object:Gem::Requirement | |
269 | none: false | |
270 | requirements: | |
271 | - - ">=" | |
272 | - !ruby/object:Gem::Version | |
273 | hash: 3 | |
274 | segments: | |
275 | - 0 | |
276 | version: "0" | |
277 | prerelease: false | |
278 | requirement: *id016 | |
279 | name: statsd-ruby | |
280 | type: :development | |
281 | - !ruby/object:Gem::Dependency | |
282 | version_requirements: &id017 !ruby/object:Gem::Requirement | |
283 | none: false | |
284 | requirements: | |
285 | - - < | |
286 | - !ruby/object:Gem::Version | |
287 | hash: 3 | |
288 | segments: | |
289 | - 0 | |
290 | - 7 | |
291 | - 0 | |
292 | version: 0.7.0 | |
293 | prerelease: false | |
294 | requirement: *id017 | |
295 | name: i18n | |
243 | 296 | type: :development |
244 | 297 | description: An easy to configure, easy to extend monitoring framework written in Ruby. |
245 | 298 | email: god-rb@googlegroups.com |
298 | 351 | - lib/god/contacts/jabber.rb |
299 | 352 | - lib/god/contacts/prowl.rb |
300 | 353 | - lib/god/contacts/scout.rb |
354 | - lib/god/contacts/sensu.rb | |
355 | - lib/god/contacts/slack.rb | |
356 | - lib/god/contacts/statsd.rb | |
301 | 357 | - lib/god/contacts/twitter.rb |
302 | 358 | - lib/god/contacts/webhook.rb |
303 | 359 | - lib/god/driver.rb |
373 | 429 | - test/test_process.rb |
374 | 430 | - test/test_prowl.rb |
375 | 431 | - test/test_registry.rb |
432 | - test/test_sensu.rb | |
433 | - test/test_slack.rb | |
376 | 434 | - test/test_socket.rb |
435 | - test/test_statsd.rb | |
377 | 436 | - test/test_sugar.rb |
378 | 437 | - test/test_system_portable_poller.rb |
379 | 438 | - test/test_system_process.rb |
440 | 499 | - test/test_process.rb |
441 | 500 | - test/test_prowl.rb |
442 | 501 | - test/test_registry.rb |
502 | - test/test_sensu.rb | |
503 | - test/test_slack.rb | |
443 | 504 | - test/test_socket.rb |
505 | - test/test_statsd.rb | |
444 | 506 | - test/test_sugar.rb |
445 | 507 | - test/test_system_portable_poller.rb |
446 | 508 | - test/test_system_process.rb |
6 | 6 | require File.join(File.dirname(__FILE__), *%w[.. lib god]) |
7 | 7 | God::EventHandler.load |
8 | 8 | |
9 | require 'test/unit' | |
9 | require 'minitest/autorun' | |
10 | require 'minitest/unit' | |
10 | 11 | require 'set' |
11 | 12 | |
12 | 13 | include God |
114 | 115 | # end |
115 | 116 | # end |
116 | 117 | |
117 | module Test::Unit::Assertions | |
118 | module Minitest::Assertions | |
118 | 119 | def assert_abort |
119 | assert_raise SystemExit do | |
120 | assert_raises SystemExit do | |
120 | 121 | yield |
121 | 122 | end |
123 | end | |
124 | ||
125 | def assert_nothing_raised | |
126 | yield | |
122 | 127 | end |
123 | 128 | end |
124 | 129 |
0 | 0 | #!/usr/bin/env ruby |
1 | 1 | require File.dirname(__FILE__) + '/helper' |
2 | 2 | |
3 | class TestAirbrake < Test::Unit::TestCase | |
3 | class TestAirbrake < Minitest::Test | |
4 | 4 | def test_notify |
5 | 5 | airbrake = God::Contacts::Airbrake.new |
6 | 6 | airbrake.apikey = "put_your_apikey_here" |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestBehavior < Test::Unit::TestCase | |
2 | class TestBehavior < Minitest::Test | |
3 | 3 | def test_generate_should_return_an_object_corresponding_to_the_given_type |
4 | 4 | assert_equal Behaviors::FakeBehavior, Behavior.generate(:fake_behavior, nil).class |
5 | 5 | end |
6 | 6 | |
7 | 7 | def test_generate_should_raise_on_invalid_type |
8 | assert_raise NoSuchBehaviorError do | |
8 | assert_raises NoSuchBehaviorError do | |
9 | 9 | Behavior.generate(:foo, nil) |
10 | 10 | end |
11 | 11 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestCampfire < Test::Unit::TestCase | |
2 | class TestCampfire < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | @campfire = God::Contacts::Campfire.new |
5 | 5 | end |
2 | 2 | class BadlyImplementedCondition < PollCondition |
3 | 3 | end |
4 | 4 | |
5 | class TestCondition < Test::Unit::TestCase | |
5 | class TestCondition < Minitest::Test | |
6 | 6 | |
7 | 7 | # generate |
8 | 8 | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def test_generate_should_raise_on_invalid_type |
14 | assert_raise NoSuchConditionError do | |
14 | assert_raises NoSuchConditionError do | |
15 | 15 | Condition.generate(:foo, nil) |
16 | 16 | end |
17 | 17 | end |
44 | 44 | def test_test_should_raise_if_not_defined_in_subclass |
45 | 45 | c = BadlyImplementedCondition.new |
46 | 46 | |
47 | assert_raise AbstractMethodNotOverriddenError do | |
47 | assert_raises AbstractMethodNotOverriddenError do | |
48 | 48 | c.test |
49 | 49 | end |
50 | 50 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestConditionsDiskUsage < Test::Unit::TestCase | |
2 | class TestConditionsDiskUsage < Minitest::Test | |
3 | 3 | # valid? |
4 | 4 | |
5 | 5 | def test_valid_should_return_false_if_no_above_given |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestHttpResponseCode < Test::Unit::TestCase | |
2 | class TestHttpResponseCode < Minitest::Test | |
3 | 3 | def valid_condition |
4 | 4 | c = Conditions::HttpResponseCode.new() |
5 | 5 | c.watch = stub(:name => 'foo') |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestConditionsProcessRunning < Test::Unit::TestCase | |
2 | class TestConditionsProcessRunning < Minitest::Test | |
3 | 3 | def test_missing_pid_file_returns_opposite |
4 | 4 | [true, false].each do |r| |
5 | 5 | c = Conditions::ProcessRunning.new |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestConditionsSocketResponding < Test::Unit::TestCase | |
2 | class TestConditionsSocketResponding < Minitest::Test | |
3 | 3 | # valid? |
4 | 4 | |
5 | 5 | def test_valid_should_return_false_if_no_options_set |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestConditionsTries < Test::Unit::TestCase | |
2 | class TestConditionsTries < Minitest::Test | |
3 | 3 | # valid? |
4 | 4 | |
5 | 5 | def test_valid_should_return_false_if_times_not_set |
10 | 10 | end |
11 | 11 | |
12 | 12 | |
13 | class TestConditionsTries < Test::Unit::TestCase | |
13 | class TestConditionsTries < Minitest::Test | |
14 | 14 | def setup |
15 | 15 | @c = Conditions::Tries.new |
16 | 16 | @c.times = 3 |
41 | 41 | end |
42 | 42 | |
43 | 43 | |
44 | class TestConditionsTriesWithin < Test::Unit::TestCase | |
44 | class TestConditionsTriesWithin < Minitest::Test | |
45 | 45 | def setup |
46 | 46 | @c = Conditions::Tries.new |
47 | 47 | @c.times = 3 |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestContact < Test::Unit::TestCase | |
2 | class TestContact < Minitest::Test | |
3 | 3 | def test_exists |
4 | 4 | God::Contact |
5 | 5 | end |
7 | 7 | # generate |
8 | 8 | |
9 | 9 | def test_generate_should_raise_on_invalid_kind |
10 | assert_raise(NoSuchContactError) do | |
10 | assert_raises(NoSuchContactError) do | |
11 | 11 | Contact.generate(:invalid) |
12 | 12 | end |
13 | 13 | end |
58 | 58 | |
59 | 59 | def test_normalize_should_raise_on_non_string_array_hash |
60 | 60 | input = 1 |
61 | assert_raise ArgumentError do | |
61 | assert_raises ArgumentError do | |
62 | 62 | Contact.normalize(input) |
63 | 63 | end |
64 | 64 | end |
65 | 65 | |
66 | 66 | def test_normalize_should_raise_on_non_string_array_contacts_key |
67 | 67 | input = {:contacts => 1} |
68 | assert_raise ArgumentError do | |
68 | assert_raises ArgumentError do | |
69 | 69 | Contact.normalize(input) |
70 | 70 | end |
71 | 71 | end |
72 | 72 | |
73 | 73 | def test_normalize_should_raise_on_non_string_containing_array |
74 | 74 | input = [1] |
75 | assert_raise ArgumentError do | |
75 | assert_raises ArgumentError do | |
76 | 76 | Contact.normalize(input) |
77 | 77 | end |
78 | 78 | end |
79 | 79 | |
80 | 80 | def test_normalize_should_raise_on_non_string_containing_array_contacts_key |
81 | 81 | input = {:contacts => [1]} |
82 | assert_raise ArgumentError do | |
82 | assert_raises ArgumentError do | |
83 | 83 | Contact.normalize(input) |
84 | 84 | end |
85 | 85 | end |
86 | 86 | |
87 | 87 | def test_normalize_should_raise_on_absent_contacts_key |
88 | 88 | input = {} |
89 | assert_raise ArgumentError do | |
89 | assert_raises ArgumentError do | |
90 | 90 | Contact.normalize(input) |
91 | 91 | end |
92 | 92 | end |
93 | 93 | |
94 | 94 | def test_normalize_should_raise_on_extra_keys |
95 | 95 | input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'} |
96 | assert_raise ArgumentError do | |
96 | assert_raises ArgumentError do | |
97 | 97 | Contact.normalize(input) |
98 | 98 | end |
99 | 99 | end |
101 | 101 | # notify |
102 | 102 | |
103 | 103 | def test_notify_should_be_abstract |
104 | assert_raise(AbstractMethodNotOverriddenError) do | |
104 | assert_raises(AbstractMethodNotOverriddenError) do | |
105 | 105 | Contact.new.notify(:a, :b, :c, :d, :e) |
106 | 106 | end |
107 | 107 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestDriver < Test::Unit::TestCase | |
2 | class TestDriver < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | |
5 | 5 | end |
6 | 6 | |
7 | 7 | def test_push_pop_wait |
8 | ||
8 | 9 | eq = God::DriverEventQueue.new |
9 | ||
10 | MonitorMixin::ConditionVariable.any_instance.expects(:wait).times(1) | |
10 | cond = eq.instance_variable_get(:@resource) | |
11 | cond.expects(:wait).times(1) | |
11 | 12 | |
12 | 13 | eq.push(God::TimedEvent.new(0)) |
13 | 14 | eq.push(God::TimedEvent.new(0.1)) |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestEmail < Test::Unit::TestCase | |
2 | class TestEmail < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | God::Contacts::Email.to_email = 'dev@example.com' |
5 | 5 | God::Contacts::Email.from_email = 'god@example.com' |
16 | 16 | end |
17 | 17 | end |
18 | 18 | |
19 | class TestEventHandler < Test::Unit::TestCase | |
19 | class TestEventHandler < Minitest::Test | |
20 | 20 | def setup |
21 | 21 | @h = God::EventHandler |
22 | 22 | end |
73 | 73 | |
74 | 74 | # This doesn't currently work: |
75 | 75 | # |
76 | # class TestEventHandlerOperational < Test::Unit::TestCase | |
76 | # class TestEventHandlerOperational < Minitest::Test | |
77 | 77 | # def test_operational |
78 | 78 | # God::EventHandler.start |
79 | 79 | # assert God::EventHandler.loaded? |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | ||
2 | class TestGod < Test::Unit::TestCase | |
1 | class TestGod < MiniTest::Test | |
3 | 2 | def setup |
4 | 3 | God::Socket.stubs(:new).returns(true) |
5 | 4 | God.stubs(:setup).returns(true) |
15 | 14 | w.driver.thread.kill |
16 | 15 | end |
17 | 16 | end |
17 | God.reset | |
18 | #Some of the tests in this file intentionally set pid_file_directory to an invalid value | |
19 | #This can cause a later test failure since God will call abort if pid_file_directory is not writable | |
20 | God.pid_file_directory = '~/.god/pids' | |
18 | 21 | end |
19 | 22 | |
20 | 23 | # applog |
31 | 34 | assert_equal Hash.new, God.watches |
32 | 35 | end |
33 | 36 | |
34 | # init | |
37 | # # init | |
35 | 38 | |
36 | 39 | def test_pid_file_directory_should_abort_if_called_after_watch |
37 | 40 | God.watch { |w| w.name = 'foo'; w.start = 'bar' } |
38 | ||
39 | 41 | assert_abort do |
40 | 42 | God.pid_file_directory = 'foo' |
41 | 43 | end |
312 | 314 | def test_control_should_raise_on_invalid_command |
313 | 315 | God.watch { |w| w.name = 'foo'; w.start = 'bar' } |
314 | 316 | |
315 | assert_raise InvalidCommandError do | |
317 | assert_raises InvalidCommandError do | |
316 | 318 | God.control('foo', 'invalid') |
317 | 319 | end |
318 | 320 | end |
450 | 452 | |
451 | 453 | def test_running_log_should_raise_on_unknown_watch |
452 | 454 | God.internal_init |
453 | assert_raise(NoSuchWatchError) do | |
455 | assert_raises(NoSuchWatchError) do | |
454 | 456 | God.running_log('foo', Time.now) |
455 | 457 | end |
456 | 458 | end |
661 | 663 | end |
662 | 664 | |
663 | 665 | |
664 | # class TestGodOther < Test::Unit::TestCase | |
666 | # class TestGodOther < Minitest::Test | |
665 | 667 | # def setup |
666 | 668 | # God::Socket.stubs(:new).returns(true) |
667 | 669 | # God.internal_init |
1 | 1 | |
2 | 2 | if God::EventHandler.event_system == "kqueue" |
3 | 3 | |
4 | class TestHandlersKqueueHandler < Test::Unit::TestCase | |
4 | class TestHandlersKqueueHandler < Minitest::Test | |
5 | 5 | def test_register_process |
6 | 6 | KQueueHandler.expects(:monitor_process).with(1234, 2147483648) |
7 | 7 | KQueueHandler.register_process(1234, [:proc_exit]) |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestHipchat < Test::Unit::TestCase | |
2 | class TestHipchat < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | @hipchat = God::Contacts::Hipchat.new |
5 | 5 | end |
0 | 0 | #!/usr/bin/env ruby |
1 | 1 | require File.dirname(__FILE__) + '/helper' |
2 | 2 | |
3 | class TestJabber < Test::Unit::TestCase | |
3 | class TestJabber < Minitest::Test | |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @jabber = God::Contacts::Jabber.new |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestLogger < Test::Unit::TestCase | |
2 | class TestLogger < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | @log = God::Logger.new(StringIO.new('/dev/null')) |
5 | 5 | end |
40 | 40 | |
41 | 41 | out = @log.watch_log_since('foo', t2) |
42 | 42 | |
43 | assert_no_match(/one/, out) | |
44 | assert_no_match(/two/, out) | |
43 | assert(/one/ !~ out) | |
44 | assert(/two/ !~ out) | |
45 | 45 | assert_match(/three/, out) |
46 | 46 | end |
47 | 47 |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestMetric < Test::Unit::TestCase | |
2 | class TestMetric < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | @metric = Metric.new(stub(:interval => 10), nil) |
5 | 5 | end |
11 | 11 | end |
12 | 12 | end |
13 | 13 | |
14 | class TestProcessChild < Test::Unit::TestCase | |
14 | class TestProcessChild < Minitest::Test | |
15 | 15 | def setup |
16 | 16 | God.internal_init |
17 | 17 | @p = God::Process.new |
43 | 43 | @p.start = 'qux' |
44 | 44 | @p.log = '/tmp/foo.log' |
45 | 45 | @p.uid = 'root' |
46 | ||
47 | ::Process.stubs(:groups=) | |
48 | ::Process.stubs(:initgroups) | |
46 | 49 | |
47 | 50 | assert @p.valid? |
48 | 51 | end |
141 | 144 | # |
142 | 145 | ############################################################################### |
143 | 146 | |
144 | class TestProcessDaemon < Test::Unit::TestCase | |
147 | class TestProcessDaemon < Minitest::Test | |
145 | 148 | def setup |
146 | 149 | God.internal_init |
147 | 150 | @p = God::Process.new |
148 | 151 | @p.name = 'foo' |
149 | 152 | @p.pid_file = 'blah.pid' |
150 | 153 | @p.stubs(:test).returns true # so we don't try to mkdir_p |
154 | God::System::Process.stubs(:fetch_system_poller).returns(God::System::PortablePoller) | |
151 | 155 | Process.stubs(:detach) # because we stub fork |
152 | 156 | end |
153 | 157 | |
242 | 246 | |
243 | 247 | assert @p.valid? |
244 | 248 | |
245 | assert_raise NotImplementedError do | |
249 | assert_raises NotImplementedError do | |
246 | 250 | @p.call_action(:start) |
247 | 251 | end |
248 | 252 | end |
0 | 0 | #!/usr/bin/env ruby |
1 | 1 | require File.dirname(__FILE__) + '/helper' |
2 | 2 | |
3 | class TestProwl < Test::Unit::TestCase | |
3 | class TestProwl < Minitest::Test | |
4 | 4 | def test_live_notify |
5 | 5 | prowl = God::Contacts::Prowl.new |
6 | 6 | prowl.name = "Prowly" |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestRegistry < Test::Unit::TestCase | |
2 | class TestRegistry < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | God.registry.reset |
5 | 5 | end |
0 | require File.dirname(__FILE__) + '/helper' | |
1 | ||
2 | class TestSensu < Minitest::Test | |
3 | def test_sensu_notify | |
4 | sensu = God::Contacts::Sensu.new | |
5 | sensu.check_name = "TestSensuContact" | |
6 | ||
7 | UDPSocket.any_instance.expects(:send) | |
8 | sensu.notify("Test", Time.now, "Test", "Test", "") | |
9 | end | |
10 | end |
0 | require File.dirname(__FILE__) + '/helper' | |
1 | ||
2 | class TestSlack < Minitest::Test | |
3 | def setup | |
4 | @slack = God::Contacts::Slack.new | |
5 | @slack.account = "foo" | |
6 | @slack.token = "foo" | |
7 | ||
8 | @sample_data = { | |
9 | :message => "a sample message", | |
10 | :time => "2038-01-01 00:00:00", | |
11 | :priority => "High", | |
12 | :category => "Test", | |
13 | :host => "example.com" | |
14 | } | |
15 | end | |
16 | ||
17 | def test_api_url | |
18 | assert_equal "https://foo.slack.com/services/hooks/incoming-webhook?token=foo", @slack.api_url.to_s | |
19 | end | |
20 | ||
21 | def test_notify | |
22 | Net::HTTP.any_instance.expects(:request).returns(Net::HTTPSuccess.new('a', 'b', 'c')) | |
23 | ||
24 | @slack.channel = "#ops" | |
25 | ||
26 | @slack.notify('msg', Time.now, 'prio', 'cat', 'host') | |
27 | assert_equal "successfully notified slack on channel #ops", @slack.info | |
28 | end | |
29 | ||
30 | def test_default_channel | |
31 | Net::HTTP.any_instance.expects(:request).returns(Net::HTTPSuccess.new('a', 'b', 'c')) | |
32 | ||
33 | @slack.notify('msg', Time.now, 'prio', 'cat', 'host') | |
34 | assert_equal "successfully notified slack on channel #general", @slack.info | |
35 | end | |
36 | ||
37 | def test_default_formatting | |
38 | text = @slack.text(@sample_data) | |
39 | assert_equal "High alert on example.com: a sample message (Test, 2038-01-01 00:00:00)", text | |
40 | end | |
41 | ||
42 | def test_custom_formatting | |
43 | @slack.format = "%{host}: %{message}" | |
44 | text = @slack.text(@sample_data) | |
45 | assert_equal "example.com: a sample message", text | |
46 | end | |
47 | ||
48 | def test_notify_channel | |
49 | @slack.notify_channel = true | |
50 | @slack.format = "" | |
51 | text = @slack.text(@sample_data) | |
52 | assert_equal "<!channel> ", text | |
53 | end | |
54 | end | |
55 |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestSocket < Test::Unit::TestCase | |
2 | class TestSocket < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | silence_warnings do |
5 | 5 | Object.const_set(:DRb, stub_everything) |
0 | require File.dirname(__FILE__) + '/helper' | |
1 | ||
2 | class TestStatsd < Minitest::Test | |
3 | def setup | |
4 | @statsd = God::Contacts::Statsd.new | |
5 | end | |
6 | ||
7 | def test_exists | |
8 | God::Contacts::Statsd | |
9 | end | |
10 | ||
11 | def test_notify | |
12 | [ | |
13 | 'cpu out of bounds', | |
14 | 'memory out of bounds', | |
15 | 'process is flapping' | |
16 | ].each do |event_type| | |
17 | ::Statsd.any_instance.expects(:increment).with("god.#{event_type.gsub(/\s/, '_')}.127_0_0_1.myapp-thin-1234") | |
18 | @statsd.notify("myapp-thin-1234 [trigger] #{event_type}", Time.now, 'some priority', 'and some category', '127.0.0.1') | |
19 | end | |
20 | end | |
21 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestSugar < Test::Unit::TestCase | |
2 | class TestSugar < Minitest::Test | |
3 | 3 | def test_seconds |
4 | 4 | assert_equal 1, 1.seconds |
5 | 5 | assert_equal 1, 1.second |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestSystemPortablePoller < Test::Unit::TestCase | |
2 | class TestSystemPortablePoller < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | pid = Process.pid |
5 | 5 | @process = System::PortablePoller.new(pid) |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestSystemProcess < Test::Unit::TestCase | |
2 | class TestSystemProcess < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | pid = Process.pid |
5 | 5 | @process = System::Process.new(pid) |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestTask < Test::Unit::TestCase | |
2 | class TestTask < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | God.internal_init |
5 | 5 | @task = Task.new |
45 | 45 | end |
46 | 46 | |
47 | 47 | def test_method_missing_should_raise_for_non_states |
48 | assert_raise NoMethodError do | |
48 | assert_raises NoMethodError do | |
49 | 49 | @task.baz = 5 |
50 | 50 | end |
51 | 51 | end |
52 | 52 | |
53 | 53 | def test_method_missing_should_raise_for_non_setters |
54 | assert_raise NoMethodError do | |
54 | assert_raises NoMethodError do | |
55 | 55 | @task.baz |
56 | 56 | end |
57 | 57 | end |
74 | 74 | |
75 | 75 | def test_action_should_raise_not_implemented_on_non_string_or_lambda_action |
76 | 76 | @task.driver.stubs(:in_driver_context?).returns(true) |
77 | assert_raise NotImplementedError do | |
77 | assert_raises NotImplementedError do | |
78 | 78 | @task.foo = 7 |
79 | 79 | @task.action(:foo, nil) |
80 | 80 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestTimeline < Test::Unit::TestCase | |
2 | class TestTimeline < Minitest::Test | |
3 | 3 | def setup |
4 | 4 | @timeline = Timeline.new(5) |
5 | 5 | end |
0 | 0 | require File.dirname(__FILE__) + '/helper' |
1 | 1 | |
2 | class TestTrigger < Test::Unit::TestCase | |
2 | class TestTrigger < Minitest::Test | |
3 | 3 | def setup |
4 | Trigger.reset | |
5 | end | |
6 | ||
7 | def teardown | |
4 | 8 | Trigger.reset |
5 | 9 | end |
6 | 10 |