minicron 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f28365c7bfec3d1aee7154ca2c0d92c71c9606b3
4
- data.tar.gz: 0764cab857b36939ca2a24482549a48fd2e5f0e8
3
+ metadata.gz: 70d5c6fda70a68b9ecfa2a36e281149e13698d24
4
+ data.tar.gz: 218a1309dac82cea4a52b68b9b439a828282c71d
5
5
  SHA512:
6
- metadata.gz: 68942a54bad7846305ce191398a84def24ba9ecad774edd83ab9195a148363ab4b22faa51bc1ae1eb1d198a2aa31afd6f5c4f401c997dd7be8978d7534ff9247
7
- data.tar.gz: 11736bb3645b87ed55ae95744a61022f0044f7706c1d51071cd5aaf211929b2b6056edbd17b53059488747cc37f1b6f54faa21c339e88d44e4077d406123b235
6
+ metadata.gz: ddea0612497a763de534ba45b673e88f3323a5d0073a8b9dbf157e1d017dba51aeefb03f11f546e0b2cbcd49cacdc5a6af5cf01d4c3755b46ee796dac3d95920
7
+ data.tar.gz: 1191ed1757310c295be9c4febe73e9de77e0808e5bb6e29f40affa6cd80a9ad94bf20f94dfde76baaefaf7cfaad7055beaad9c192d328b3bc992638cd7418d14
data/README.md CHANGED
@@ -3,7 +3,7 @@ minicron
3
3
 
4
4
  [![Gem Version](http://img.shields.io/gem/v/minicron.svg)](https://rubygems.org/gems/minicron)
5
5
  [![Build Status](http://img.shields.io/travis/jamesrwhite/minicron.svg)](http://travis-ci.org/jamesrwhite/minicron)
6
- [![Coverage Status](http://img.shields.io/coveralls/jamesrwhite/minicron.svg)](https://coveralls.io/r/jamesrwhite/minicron?branch=master)
6
+ [![Coverage Status](https://coveralls.io/repos/jamesrwhite/minicron/badge.svg?branch=develop)](https://coveralls.io/r/jamesrwhite/minicron?branch=develop)
7
7
  [![Code Climate](http://img.shields.io/codeclimate/github/jamesrwhite/minicron.svg)](https://codeclimate.com/github/jamesrwhite/minicron)
8
8
  [![Dependency Status](http://img.shields.io/gemnasium/jamesrwhite/minicron.svg)](https://gemnasium.com/jamesrwhite/minicron)
9
9
  [![Inline docs](http://inch-ci.org/github/jamesrwhite/minicron.png)](http://inch-ci.org/github/jamesrwhite/minicron)
@@ -107,7 +107,7 @@ but I encourage you to give it a try in a non critical environment and help me t
107
107
 
108
108
  2. On some distributions you may need to install the ````ruby-dev```` and ````build-essential```` packages
109
109
 
110
- 3. To install the latest release (currently 0.7.7) you can ````gem install minicron````, depending on your ruby setup
110
+ 3. To install the latest release (currently 0.7.8) you can ````gem install minicron````, depending on your ruby setup
111
111
  you may need to run this with ````sudo````
112
112
 
113
113
  4. Set your database configuration options in ````/etc/minicron.toml````, you can use the [minicron.toml](https://github.com/jamesrwhite/minicron/blob/master/config/minicron.toml) as a guide on what options are configurable
@@ -52,6 +52,9 @@ module Minicron
52
52
  },
53
53
  'pagerduty' => {
54
54
  'enabled' => false
55
+ },
56
+ 'aws_sns' => {
57
+ 'enabled' => false
55
58
  }
56
59
  }
57
60
  }
@@ -2,6 +2,7 @@ module Minicron
2
2
  autoload :Email, 'minicron/alert/email'
3
3
  autoload :SMS, 'minicron/alert/sms'
4
4
  autoload :PagerDuty, 'minicron/alert/pagerduty'
5
+ autoload :AwsSns, 'minicron/alert/aws_sns'
5
6
 
6
7
  module Hub
7
8
  autoload :Alert, 'minicron/hub/models/alert'
@@ -19,6 +20,10 @@ module Minicron
19
20
  # @option options [Time] expected_at only applies to 'miss' alerts
20
21
  def send_all(options = {})
21
22
  Minicron.config['alerts'].each do |medium, value|
23
+
24
+ # Add the alert medium into the options hash so that it can be passed to sent?
25
+ options[:medium] = medium
26
+
22
27
  # Check if the medium is enabled and alert hasn't already been sent
23
28
  if value['enabled'] && !sent?(options)
24
29
  send(
@@ -27,7 +32,7 @@ module Minicron
27
32
  :execution_id => options[:execution_id],
28
33
  :job_id => options[:job_id],
29
34
  :expected_at => options[:expected_at],
30
- :medium => medium
35
+ :medium => options[:medium]
31
36
  )
32
37
  end
33
38
  end
@@ -53,6 +58,8 @@ module Minicron
53
58
  send_sms(options)
54
59
  when 'pagerduty'
55
60
  send_pagerduty(options)
61
+ when 'aws_sns'
62
+ send_aws_sns(options)
56
63
  else
57
64
  fail Exception, "The medium '#{options[:medium]}' is not supported!"
58
65
  end
@@ -99,6 +106,15 @@ module Minicron
99
106
  )
100
107
  end
101
108
 
109
+ # Send an aws sns alert, this has the same options as #send
110
+ def send_aws_sns(options = {})
111
+ sns = Minicron::AwsSns.new
112
+ sns.send(
113
+ "minicron alert for job '#{options[:job].name}'!",
114
+ sns.get_message(options)
115
+ )
116
+ end
117
+
102
118
  # Queries the database to determine if an alert for this kind has already
103
119
  # been sent
104
120
  #
@@ -0,0 +1,49 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module Minicron
4
+ # Allows the sending of AWS SNS alerts
5
+ class AwsSns
6
+ # Used to set up on the AWS::SNS::Topic
7
+ def initialize
8
+ # Get an instance of the sns client
9
+ @client = Aws::SNS::Client.new({
10
+ :access_key_id => Minicron.config['alerts']['aws_sns']['access_key_id'],
11
+ :secret_access_key => Minicron.config['alerts']['aws_sns']['secret_access_key'],
12
+ :region => Minicron.config['alerts']['aws_sns']['region']
13
+ })
14
+ end
15
+
16
+ # Return the message for an alert
17
+ #
18
+ # @option options [Minicron::Hub::Job] job a job instance
19
+ # @option options [String] kind 'fail' or 'miss'
20
+ # @option options [Integer, nil] schedule_id only applies to 'miss' alerts
21
+ # @option options [Integer, nil] execution_id only used by 'fail' alerts
22
+ # @option options [Integer] job_id used to look up the job name for the alert message
23
+ # @option options [Time] expected_at when the schedule was expected to execute
24
+ # @option options [String] medium the medium to send the alert via
25
+ def get_message(options = {})
26
+ case options[:kind]
27
+ when 'miss'
28
+ "minicron alert - job missed!\nJob ##{options[:job_id]} failed to execute at its expected time: #{options[:expected_at]}"
29
+ when 'fail'
30
+ "minicron alert - job failed!\nExecution ##{options[:execution_id]} of Job ##{options[:job_id]} failed"
31
+ else
32
+ fail Exception, "The kind '#{options[:kind]} is not supported!"
33
+ end
34
+ end
35
+
36
+ # Send an sns alert
37
+ #
38
+ # @param from [String]
39
+ # @param to [String]
40
+ # @param message [String]
41
+ def send(subject, message)
42
+ @client.publish(
43
+ :topic_arn => Minicron.config['alerts']['aws_sns']['topic_arn'],
44
+ :subject => subject,
45
+ :message => message
46
+ )
47
+ end
48
+ end
49
+ end
@@ -1,6 +1,6 @@
1
1
  # The minicron module
2
2
  module Minicron
3
- VERSION = '0.7.7'
3
+ VERSION = '0.7.8'
4
4
  DEFAULT_CONFIG_FILE = '/etc/minicron.toml'
5
5
  BASE_PATH = File.expand_path('../../../', __FILE__)
6
6
  LIB_PATH = File.expand_path('../../', __FILE__)
@@ -31,7 +31,7 @@
31
31
  // TODO: make this use a bootstrap model as a component
32
32
  var results = 'Test Results\n\n';
33
33
  results += 'connect: ' + data.connect + '\n';
34
- results += '/etc writeable: ' + data.etc.write + '\n';
34
+ results += '/etc writeable: ' + data.etc.write + '\n';
35
35
  results += '/etc executable: ' + data.etc.execute + '\n';
36
36
  results += 'crontab readable: ' + data.crontab.read + '\n';
37
37
  results += 'crontab writeable: ' + data.crontab.write;
@@ -108,8 +108,10 @@ module Minicron
108
108
  expected_by = expected_at + 60
109
109
 
110
110
  # We only need to check jobs that are expected to under the monitor start time
111
- # and jobs that have passed their expected by time
112
- if expected_at > @start_time && Time.now > expected_by
111
+ # and jobs that have passed their expected by time and the time the schedule
112
+ # was last updated isn't before when it was expected, i.e we aren't checking for something
113
+ # that should have happened earlier in the day.
114
+ if expected_at > @start_time && Time.now > expected_by && expected_by > schedule.updated_at
113
115
  # Check if this execution was created inside a minute window
114
116
  # starting when it was expected to run
115
117
  check = Minicron::Hub::Execution.exists?(
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'minicron/alert/aws_sns'
3
+
4
+ describe Minicron::AwsSns do
5
+ before (:each) do
6
+ Minicron.parse_config_hash({
7
+ 'alerts' => {
8
+ 'aws_sns' => {
9
+ 'secret_access_key' => 'fd;sflksk;lfsdlfksdfsd',
10
+ 'access_key_id' => 'fdsfsdfsdfsd',
11
+ 'region' => 'us-west-2',
12
+ 'topic_arn' => 'arn:aws:sns:us-west-2:2342423423:yo'
13
+ }
14
+ }
15
+ })
16
+ end
17
+
18
+ describe '#intiailize' do
19
+ it 'should create an instance of the SNS gem' do
20
+ sns = Minicron::AwsSns.new
21
+
22
+ expect(sns.instance_variable_get(:@client)).to be_a Aws::SNS::Client
23
+ end
24
+ end
25
+
26
+ describe '#get_message' do
27
+ context 'when kind is miss' do
28
+ it 'should return the correct message' do
29
+ sns = Minicron::AwsSns.new
30
+ time = Time.now.utc
31
+ options = {
32
+ :job_id => 1,
33
+ :expected_at => time,
34
+ :execution_id => 2,
35
+ :kind => 'miss'
36
+ }
37
+ message = "minicron alert - job missed!\nJob #1 failed to execute at its expected time: #{time}"
38
+
39
+ expect(sns.get_message(options)).to eq message
40
+ end
41
+ end
42
+
43
+ context 'when kind is fail' do
44
+ it 'should return the correct message' do
45
+ sns = Minicron::AwsSns.new
46
+ options = {
47
+ :job_id => 1,
48
+ :execution_id => 2,
49
+ :kind => 'fail'
50
+ }
51
+ message = "minicron alert - job failed!\nExecution #2 of Job #1 failed"
52
+
53
+ expect(sns.get_message(options)).to eq message
54
+ end
55
+ end
56
+
57
+ context 'when kind is not supported' do
58
+ it 'should raise an Exception' do
59
+ sns = Minicron::AwsSns.new
60
+ options = {
61
+ :kind => 'derp'
62
+ }
63
+
64
+ expect do
65
+ sns.get_message(options)
66
+ end.to raise_error Exception
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '#send' do
72
+ it 'sends message to the topic_arn' do
73
+ sns = Minicron::AwsSns.new
74
+ subject = 'subject'
75
+ message = 'message'
76
+ expect_any_instance_of(Aws::SNS::Client).to receive(:publish).with(
77
+ topic_arn: Minicron.config['alerts']['aws_sns']['topic_arn'],
78
+ subject: subject,
79
+ message: message
80
+ )
81
+
82
+ sns.send(subject, message)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'minicron/alert'
3
+ require 'minicron/alert/aws_sns'
4
+
5
+ describe Minicron::Alert do
6
+ describe '#send' do
7
+ context 'when medium is AWS SNS' do
8
+ it 'sends message' do
9
+ alert = Minicron::Alert.new
10
+ allow(Minicron::Hub::Job).to receive(:find).and_return(nil)
11
+ allow(Minicron::Hub::Alert).to receive(:create).and_return(nil)
12
+ expect_any_instance_of(Minicron::Alert).to receive(:send_aws_sns)
13
+
14
+ alert.send({
15
+ :medium => 'aws_sns',
16
+ :job_id => 1
17
+ })
18
+ end
19
+ end
20
+ end
21
+ end
@@ -101,6 +101,9 @@ describe Minicron do
101
101
  },
102
102
  'pagerduty' => {
103
103
  'enabled' => false
104
+ },
105
+ 'aws_sns' => {
106
+ 'enabled' => false
104
107
  }
105
108
  }
106
109
  }
@@ -49,3 +49,6 @@ dry_run = false
49
49
 
50
50
  [alerts.pagerduty]
51
51
  enabled = false
52
+
53
+ [alerts.aws_sns]
54
+ enabled = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minicron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -416,6 +416,20 @@ dependencies:
416
416
  - - "~>"
417
417
  - !ruby/object:Gem::Version
418
418
  version: '1.1'
419
+ - !ruby/object:Gem::Dependency
420
+ name: aws-sdk
421
+ requirement: !ruby/object:Gem::Requirement
422
+ requirements:
423
+ - - "~>"
424
+ - !ruby/object:Gem::Version
425
+ version: '2.1'
426
+ type: :runtime
427
+ prerelease: false
428
+ version_requirements: !ruby/object:Gem::Requirement
429
+ requirements:
430
+ - - "~>"
431
+ - !ruby/object:Gem::Version
432
+ version: '2.1'
419
433
  - !ruby/object:Gem::Dependency
420
434
  name: bundler
421
435
  requirement: !ruby/object:Gem::Requirement
@@ -472,6 +486,66 @@ dependencies:
472
486
  - - "~>"
473
487
  - !ruby/object:Gem::Version
474
488
  version: '0.8'
489
+ - !ruby/object:Gem::Dependency
490
+ name: guard
491
+ requirement: !ruby/object:Gem::Requirement
492
+ requirements:
493
+ - - "~>"
494
+ - !ruby/object:Gem::Version
495
+ version: '2.12'
496
+ - - ">="
497
+ - !ruby/object:Gem::Version
498
+ version: 2.12.6
499
+ type: :development
500
+ prerelease: false
501
+ version_requirements: !ruby/object:Gem::Requirement
502
+ requirements:
503
+ - - "~>"
504
+ - !ruby/object:Gem::Version
505
+ version: '2.12'
506
+ - - ">="
507
+ - !ruby/object:Gem::Version
508
+ version: 2.12.6
509
+ - !ruby/object:Gem::Dependency
510
+ name: guard-rspec
511
+ requirement: !ruby/object:Gem::Requirement
512
+ requirements:
513
+ - - "~>"
514
+ - !ruby/object:Gem::Version
515
+ version: '4.5'
516
+ - - ">="
517
+ - !ruby/object:Gem::Version
518
+ version: 4.5.2
519
+ type: :development
520
+ prerelease: false
521
+ version_requirements: !ruby/object:Gem::Requirement
522
+ requirements:
523
+ - - "~>"
524
+ - !ruby/object:Gem::Version
525
+ version: '4.5'
526
+ - - ">="
527
+ - !ruby/object:Gem::Version
528
+ version: 4.5.2
529
+ - !ruby/object:Gem::Dependency
530
+ name: guard-bundler
531
+ requirement: !ruby/object:Gem::Requirement
532
+ requirements:
533
+ - - "~>"
534
+ - !ruby/object:Gem::Version
535
+ version: '2.1'
536
+ - - ">="
537
+ - !ruby/object:Gem::Version
538
+ version: 2.1.0
539
+ type: :development
540
+ prerelease: false
541
+ version_requirements: !ruby/object:Gem::Requirement
542
+ requirements:
543
+ - - "~>"
544
+ - !ruby/object:Gem::Version
545
+ version: '2.1'
546
+ - - ">="
547
+ - !ruby/object:Gem::Version
548
+ version: 2.1.0
475
549
  description:
476
550
  email:
477
551
  - dev.jameswhite+minicron@gmail.com
@@ -486,6 +560,7 @@ files:
486
560
  - bin/minicron
487
561
  - lib/minicron.rb
488
562
  - lib/minicron/alert.rb
563
+ - lib/minicron/alert/aws_sns.rb
489
564
  - lib/minicron/alert/email.rb
490
565
  - lib/minicron/alert/pagerduty.rb
491
566
  - lib/minicron/alert/sms.rb
@@ -573,8 +648,10 @@ files:
573
648
  - lib/minicron/transport/server.rb
574
649
  - lib/minicron/transport/ssh.rb
575
650
  - spec/invalid_config.toml
651
+ - spec/minicron/alert/aws_sns_spec.rb
576
652
  - spec/minicron/alert/pagerduty_spec.rb
577
653
  - spec/minicron/alert/sms_spec.rb
654
+ - spec/minicron/alert_spec.rb
578
655
  - spec/minicron/cli_spec.rb
579
656
  - spec/minicron/transport/client_spec.rb
580
657
  - spec/minicron/transport/faye/client_spec.rb
@@ -613,8 +690,10 @@ specification_version: 4
613
690
  summary: A system to make it easier to manage and monitor cron jobs
614
691
  test_files:
615
692
  - spec/invalid_config.toml
693
+ - spec/minicron/alert/aws_sns_spec.rb
616
694
  - spec/minicron/alert/pagerduty_spec.rb
617
695
  - spec/minicron/alert/sms_spec.rb
696
+ - spec/minicron/alert_spec.rb
618
697
  - spec/minicron/cli_spec.rb
619
698
  - spec/minicron/transport/client_spec.rb
620
699
  - spec/minicron/transport/faye/client_spec.rb