sensu-plugins-particle 0.0.1 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81947e22dea5205e12d1eeea324e336ef64cd025
4
- data.tar.gz: 74dcc2435a3b9a94ea5f3bdc6ae23ce28dc85001
3
+ metadata.gz: f6468fec95a3e478ac6fba4eabef4269dc8a9a2a
4
+ data.tar.gz: ca7c2cd6bca51dd68c19c0604469491fc25be251
5
5
  SHA512:
6
- metadata.gz: 6fe3f8de243a2e838bf6664bfa74fda75bc33a55010711161954aa05ef636ad04eee04b185ee0a89d7566c573be69577a5487b9b943d7780f661203a017cb1e2
7
- data.tar.gz: 17de9ff9425afff52ef4ae3664c5c48509ef1b0f6c7e7d610404c15926515966339cc976e3b606797879f7e83a6ead6160c4490dd9a45b32dec8c95661f84b12
6
+ metadata.gz: d9eb434092b25247661571d9f90c915391fc02830548284b2b34f1a19b14b19e4908213443893be0f2eb66c94cea7e679cf3f52fb87e4c5cd9c44381c75d9fb6
7
+ data.tar.gz: c3937e29a7227a8e28dd92e8780b984f9aac59ccf923560711903a529ddc05746b645c181a110a4a9f6086e07df76a62ec93645f12e1abb60831850a69ccad1c
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## 0.0.2 - 2018-07-15
9
+ ### Added
10
+ - add handler-particle-device-function.rb
11
+
8
12
  ## 0.0.1 - 2018-07-15
9
13
  ### Added
10
14
  - initial release: includes handler-particle-publish-event.rb
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2018 Jef Spaleta and contributors.
4
+ #
5
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
6
+ # for details.
7
+ #
8
+ # In order to use this plugin, you must first configure a
9
+ # particle.io cloud api account
10
+ # You'll make use of the particle.io login information
11
+ #
12
+
13
+ require 'sensu-handler'
14
+ require 'particle'
15
+ require 'json'
16
+
17
+ class ParticleHandler < Sensu::Handler
18
+ option :particle_config_file,
19
+ description: 'Particle config JSON file location',
20
+ short: '-c CONFIG_FILE',
21
+ long: '--config_file CONFIG_FILE'
22
+ option :particle_user,
23
+ description: 'Particle user',
24
+ short: '-u USER',
25
+ long: '--user USER'
26
+ option :particle_password,
27
+ description: 'Particle password',
28
+ short: '-p PASSWORD',
29
+ long: '--password PASSWORD'
30
+ option :particle_token,
31
+ description: 'Particle access token',
32
+ short: '-t TOKEN',
33
+ long: '--token TOKEN',
34
+ default: ENV['PARTICLE_ACCESS_TOKEN']
35
+ option :particle_device,
36
+ description: 'Particle device id or device name',
37
+ short: '-d DEVICE',
38
+ long: '--device DEVICE'
39
+ option :particle_function,
40
+ description: 'Particle device function name',
41
+ short: '-f FUNCTION_NAME',
42
+ long: '--function FUNCTION_NAME'
43
+ option :particle_argument,
44
+ description: 'Particle device function argument',
45
+ short: '-a FUNCTION_ARGUMENT',
46
+ long: '--argument FUNCTION_ARGUMENT'
47
+ option :verbose,
48
+ description: 'Verbose output',
49
+ short: '-v',
50
+ long: '--verbose'
51
+
52
+ ##
53
+ # Setup helper function to deal with configuration processing
54
+ ##
55
+ def setup
56
+ if config.key?(:particle_config_file)
57
+ if File.readable?(config[:particle_config_file])
58
+ file = File.read(config[:particle_config_file])
59
+ config_hash = JSON.parse(file)
60
+ keys = %w[particle_user particle_password particle_token particle_device particle_function particle_argument]
61
+ keys.each do |key|
62
+ config[key.to_sym] = config_hash[key] if config_hash.key?(key)
63
+ end
64
+ end
65
+ end
66
+
67
+ unless (config[:particle_user] && config[:particle_password]) || config[:particle_token]
68
+ puts 'Must supply user and password or token, check --help message for more information'
69
+ exit 2
70
+ end
71
+
72
+ unless config[:particle_device]
73
+ puts 'Must supply particle device, check --help message for more information'
74
+ exit 2
75
+ end
76
+
77
+ unless config[:particle_function]
78
+ puts 'Must supply particle device function, check --help message for more information'
79
+ exit 2
80
+ end
81
+
82
+ return unless config[:verbose]
83
+
84
+ if config[:particle_token]
85
+ puts "Post Setup:: Token: #{config[:particle_token]}"
86
+ else
87
+ puts 'Post Setup:: Using Login'
88
+ end
89
+ end
90
+
91
+ def handle
92
+ setup
93
+ client = Particle::Client.new
94
+ client.access_token = config[:particle_token] if config[:particle_token]
95
+ client.login(config[:particle_user], config[:particle_password]) if config[:particle_user] && config[:particle_password]
96
+
97
+ device = client.device(config[:particle_device])
98
+ device.ping
99
+
100
+ result = device.call(config[:particle_function], config[:particle_argument])
101
+ exit result
102
+ rescue Particle::Forbidden, Particle::BadRequest, Particle::MissingTokenError => e
103
+ puts "error: #{e.message}"
104
+ exit 3 # unknown
105
+ end
106
+ end
@@ -2,7 +2,7 @@ module SensuPluginsParticle
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-particle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jef Spaleta and contributors
@@ -156,24 +156,26 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0.8'
159
+ version: 0.9.11
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0.8'
166
+ version: 0.9.11
167
167
  description: Sensu plugins for interfacing with Particle.io Cloud API
168
168
  email: "<jspaleta@gmail.com>"
169
169
  executables:
170
170
  - handler-particle-publish-event.rb
171
+ - handler-particle-device-function.rb
171
172
  extensions: []
172
173
  extra_rdoc_files: []
173
174
  files:
174
175
  - CHANGELOG.md
175
176
  - LICENSE
176
177
  - README.md
178
+ - bin/handler-particle-device-function.rb
177
179
  - bin/handler-particle-publish-event.rb
178
180
  - lib/sensu-plugins-particle.rb
179
181
  - lib/sensu-plugins-particle/version.rb