sensu-plugins-stackstorm 0.0.2 → 0.1.1

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: be14a142d09aa3425b4a138764b62fbd2f3fa9ee
4
- data.tar.gz: 3cbc5eea735cde517d23f385bc374aae8530a097
3
+ metadata.gz: 33eeae3a3a44a8091ccb1a0ed48defe122ef6bdb
4
+ data.tar.gz: e94b67363bf388bb9cd9954f8784f21aca3ea04a
5
5
  SHA512:
6
- metadata.gz: 1a3b5e462bd30c6ab63c4a8c33e9002f28c072badf755e5ef7115ed13198bff9ad73b27229ecbc4e3eedaf90d6fd35d0cf59aa55c5dff8b2293dd87aed5670db
7
- data.tar.gz: 64ad6a92f02447001988d552c97337f2ee0821bc2815c4a32ff34aea63b6859f167c91d9467cc93df870cec67f9f473c098c8756c2da5eee8cedbf9ab9fe7004
6
+ metadata.gz: 846c6217e64faaff9ff015f93ec46d3633cbee498d5c5bd4c8cb4d876653fb3258cb40194c4a67d262fad31aba65162f013d4abfd9c3006bb5c45e99541fed65
7
+ data.tar.gz: f98ccc752e68e9f90f2b80fad7c91baadd905fe601c15731b2c047196e2f3d097d6ef5708271b5cfe0cec571a8104d8213d7a3a5a29e0900cc159be4976a8316
@@ -25,6 +25,9 @@ except ImportError:
25
25
  raise ImportError('Missing dependency "pyyaml". \
26
26
  Do ``pip install pyyaml``.')
27
27
 
28
+ import re
29
+ import six
30
+
28
31
  # ST2 configuration
29
32
 
30
33
  ST2_API_BASE_URL = None # 'https://localhost/api/v1/'
@@ -60,6 +63,56 @@ TOKEN_AUTH_HEADER = 'X-Auth-Token'
60
63
  API_KEY_AUTH_HEADER = 'St2-Api-Key'
61
64
 
62
65
 
66
+ class ConfigMeta(type):
67
+ def __getitem__(kls, key):
68
+ loaded_config = {}
69
+ for fpath in kls.get_config_files():
70
+ with open(fpath, 'r') as f:
71
+ loaded_config.update(json.loads(f.read()))
72
+
73
+ return loaded_config.get(key)
74
+
75
+ def __contains__(kls, key):
76
+ is_contains = False
77
+ for fpath in kls.get_config_files():
78
+ if is_contains:
79
+ break
80
+
81
+ with open(fpath, 'r') as f:
82
+ is_contains = key in json.loads(f.read())
83
+
84
+ return is_contains
85
+
86
+ class ConfigBase(six.with_metaclass(ConfigMeta)):
87
+ @classmethod
88
+ def get_config_files(kls):
89
+ config_files = []
90
+ if (os.environ.get('SENSU_LOADED_TEMPFILE') and
91
+ os.path.exists(os.environ.get('SENSU_LOADED_TEMPFILE'))):
92
+ with open(os.environ.get('SENSU_LOADED_TEMPFILE'), 'r') as f:
93
+ config_files = f.read().split(':')
94
+ return config_files
95
+
96
+ elif os.environ.get('SENSU_CONFIG_FILES'):
97
+ return os.environ.get('SENSU_CONFIG_FILES').split(':')
98
+
99
+ else:
100
+ for basedir, _, files in os.walk(kls.CONFIG_DIR_BASE):
101
+ config_files.extend(['%s/%s' % (basedir, x) for x in files
102
+ if re.match(".*\.json$", x)])
103
+ return config_files
104
+
105
+ @classmethod
106
+ def get(kls, key, default=None):
107
+ if key not in kls:
108
+ return default
109
+ else:
110
+ return kls[key]
111
+
112
+ class Config(ConfigBase):
113
+ CONFIG_DIR_BASE = '/etc/sensu'
114
+
115
+
63
116
  def _get_sensu_request_headers():
64
117
  b64auth = base64.b64encode(
65
118
  "%s:%s" %
@@ -293,7 +346,7 @@ def _register_with_st2(verbose=False):
293
346
  sys.exit(2)
294
347
 
295
348
 
296
- def _set_config_opts(config_file, verbose=False, unauthed=False, ssl_verify=False):
349
+ def _set_config_opts(verbose=False, unauthed=False, ssl_verify=False):
297
350
  global ST2_USERNAME
298
351
  global ST2_PASSWORD
299
352
  global ST2_API_KEY
@@ -312,29 +365,33 @@ def _set_config_opts(config_file, verbose=False, unauthed=False, ssl_verify=Fals
312
365
  UNAUTHED = unauthed
313
366
  ST2_SSL_VERIFY = ssl_verify
314
367
 
315
- if not os.path.exists(config_file):
316
- print('Configuration file %s not found. Exiting!!!' % config_file)
317
- sys.exit(1)
368
+ # These are default configurations
369
+ config = {
370
+ 'st2_username': 'st2admin',
371
+ 'st2_password': 'password',
372
+ 'st2_api_key': '',
373
+ 'st2_api_base_url': 'http://localhost:9101/v1/',
374
+ 'st2_auth_base_url': 'http://localhost:9100/',
375
+ }
318
376
 
319
- with open(config_file) as f:
320
- config = yaml.safe_load(f)
377
+ config.update(Config.get('st2_handler', {}))
321
378
 
322
- if verbose:
323
- print('Contents of config file: %s' % config)
324
-
325
- ST2_USERNAME = config['st2_username']
326
- ST2_PASSWORD = config['st2_password']
327
- ST2_API_KEY = config['st2_api_key']
328
- ST2_API_BASE_URL = config['st2_api_base_url']
329
- if not ST2_API_BASE_URL.endswith('/'):
330
- ST2_API_BASE_URL += '/'
331
- ST2_AUTH_BASE_URL = config['st2_auth_base_url']
332
- if not ST2_AUTH_BASE_URL.endswith('/'):
333
- ST2_AUTH_BASE_URL += '/'
334
- SENSU_HOST = config.get('sensu_host', 'localhost')
335
- SENSU_PORT = config.get('sensu_port', '4567')
336
- SENSU_USER = config.get('sensu_user', None)
337
- SENSU_PASS = config.get('sensu_pass', None)
379
+ if verbose:
380
+ print('Contents of config file: %s' % config)
381
+
382
+ ST2_USERNAME = config['st2_username']
383
+ ST2_PASSWORD = config['st2_password']
384
+ ST2_API_KEY = config['st2_api_key']
385
+ ST2_API_BASE_URL = config['st2_api_base_url']
386
+ if not ST2_API_BASE_URL.endswith('/'):
387
+ ST2_API_BASE_URL += '/'
388
+ ST2_AUTH_BASE_URL = config['st2_auth_base_url']
389
+ if not ST2_AUTH_BASE_URL.endswith('/'):
390
+ ST2_AUTH_BASE_URL += '/'
391
+ SENSU_HOST = Config['api'].get('host', 'localhost')
392
+ SENSU_PORT = Config['api'].get('port', '4567')
393
+ SENSU_USER = Config['api'].get('user', None)
394
+ SENSU_PASS = Config['api'].get('password', None)
338
395
 
339
396
  if ST2_API_KEY:
340
397
  IS_API_KEY_AUTH = True
@@ -356,17 +413,14 @@ def _set_config_opts(config_file, verbose=False, unauthed=False, ssl_verify=Fals
356
413
  sys.exit(1)
357
414
 
358
415
 
359
- def main(config_file, payload, verbose=False, unauthed=False, ssl_verify=False):
360
- _set_config_opts(config_file=config_file, unauthed=unauthed, verbose=verbose,
361
- ssl_verify=ssl_verify)
416
+ def main(payload, verbose=False, unauthed=False, ssl_verify=False):
417
+ _set_config_opts(unauthed=unauthed, verbose=verbose, ssl_verify=ssl_verify)
362
418
  _register_with_st2(verbose=verbose)
363
419
  _post_event_to_st2(payload, verbose=verbose)
364
420
 
365
421
 
366
422
  if __name__ == '__main__':
367
423
  parser = argparse.ArgumentParser(description='StackStorm sensu event handler.')
368
- parser.add_argument('config_path',
369
- help='Exchange to listen on')
370
424
  parser.add_argument('--verbose', '-v', required=False, action='store_true',
371
425
  help='Verbose mode.')
372
426
  parser.add_argument('--unauthed', '-u', required=False, action='store_true',
@@ -376,5 +430,4 @@ if __name__ == '__main__':
376
430
  help='Turn on SSL verification for st2 APIs.')
377
431
  args = parser.parse_args()
378
432
  payload = sys.stdin.read().strip()
379
- main(config_file=args.config_path, payload=payload, verbose=args.verbose,
380
- unauthed=args.unauthed, ssl_verify=args.ssl_verify)
433
+ main(payload=payload, verbose=args.verbose, unauthed=args.unauthed, ssl_verify=args.ssl_verify)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "sensu-plugins-stackstorm"
4
+
5
+ SensuPluginsStackStorm::Command.run_python *ARGV
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-stackstorm/command'
@@ -0,0 +1,10 @@
1
+ module SensuPluginsStackStorm
2
+ class Command
3
+ def self.run_python(*argv)
4
+ bin_dir = File.expand_path(File.dirname(__FILE__)) + '/../../bin/'
5
+ shell_script_path = File.join(bin_dir, File.basename($PROGRAM_NAME, '.rb') + '.py')
6
+
7
+ exec shell_script_path, *argv
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module SensuPluginsStackStorm
2
+ VERSION = '0.1.1'
3
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-stackstorm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
+ - StackStorm, Inc.
7
8
  - Hiroyasu OHYAMA
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
12
+ date: 2017-09-13 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rspec
@@ -40,21 +41,18 @@ dependencies:
40
41
  version: '12.0'
41
42
  description: ''
42
43
  email:
44
+ - info@stackstorm.com
43
45
  - user.localhost2000@gmail.com
44
46
  executables:
45
- - st2_handler.py
47
+ - st2_handler.rb
46
48
  extensions: []
47
49
  extra_rdoc_files: []
48
50
  files:
49
- - ".gitignore"
50
- - ".travis.yml"
51
- - Gemfile
52
- - README.md
53
- - Rakefile
54
51
  - bin/st2_handler.py
55
- - etc/st2_handler.conf
56
- - lib/.gitkeep
57
- - sensu-plugins-stackstorm.gemspec
52
+ - bin/st2_handler.rb
53
+ - lib/sensu-plugins-stackstorm.rb
54
+ - lib/sensu-plugins-stackstorm/command.rb
55
+ - lib/sensu-plugins-stackstorm/version.rb
58
56
  homepage: https://github.com/userlocalhost2000/sensu-plugins-stackstorm
59
57
  licenses:
60
58
  - Apache-2.0
@@ -75,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
73
  version: '0'
76
74
  requirements: []
77
75
  rubyforge_project:
78
- rubygems_version: 2.6.11
76
+ rubygems_version: 2.6.13
79
77
  signing_key:
80
78
  specification_version: 4
81
79
  summary: Sensu plugins for StackStorm
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *.sw[p-z]
2
- *.gem
@@ -1,34 +0,0 @@
1
- language: ruby
2
- cache:
3
- - bundler
4
- install:
5
- - bundle install
6
- rvm:
7
- - 2.0
8
- - 2.1
9
- - 2.2
10
- - 2.3.0
11
- - 2.4.1
12
- notifications:
13
- email:
14
- recipients:
15
- - user.localhost2000@gmail.com
16
- on_success: change
17
- on_failure: always
18
- script:
19
- - bundle exec rake default
20
- - gem build sensu-plugins-stackstorm.gemspec
21
- - gem install sensu-plugins-stackstorm-*.gem
22
- deploy:
23
- provider: rubygems
24
- api_key:
25
- secure: m6eh9IW8L2RCDzfFcnVNuWyr74ywhw+G+4WWwvTTUb7kp5cPu1dkqSeyVM8UobwKuFDwiJTh5rsGVfa2gTnPkaj7jaAWOVDAJcjs8q+oYxMob+dpe++eu3N1adbsqZC27wNH2AlfmIiuEohTHNTMYv6CTiIkr6OVkZCLeD1lLxx9+OyhNaxkb53hmPPgvADmvITK1ZKKyAKb43rCGrKV1/nQDFu+aL/+CmqlH0JLw7vYrx3uVFOmjoVmPWM5VWS1BO2xOZIJ2leInql85C4DK4K3FoqIDhAg+d1o5RqMEz9DvfLHhl2f2EWgHxGk2PyolVUu7JxIoPT1WgCQnKjZ4vOZZBpsdMLzjvnFJBHrFIp0wUTAUgDxHzCA16BKLEoZg0IMcPh+aVPd3jdVJg+RsUuhCr+5wZEsu8LB/LfKiLhSdaM70sjM6CsZXyfhrLFN809f32vGm/fFc3FOKy/ZHEDaVG2jIspcg2pwDwzaQ8wPYwsgp9q+RDpFF49zyk+5f9FjEyftcUwaZhzDb1WIvzQCKtR2dBNgooUZJKrCicyc/L409P1Q1XMeV7BFew+fXChteh4upbzYiqp1yile1EO3QDIDmHpPALh2CbWRwyCmpbn0y8ZfAE4YDs0Bd1V1rJqdsuUFJlEDw7coKrR9uPWzB66om8nlz3KQGfyva3I=
26
- gem: sensu-plugins-stackstorm
27
- on:
28
- tags: true
29
- all_branches: true
30
- rvm: 2.4.1
31
- repo: sensu-plugins/sensu-plugins-stackstorm
32
- addons:
33
- code_climate:
34
- repo_token:
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/README.md DELETED
@@ -1,7 +0,0 @@
1
- # Sensu-Plugins-StackStorm
2
-
3
- # Functionality
4
-
5
- ## Files
6
-
7
- * st2_handler.py
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,14 +0,0 @@
1
- ---
2
- # st2 credentials. you can either use username/password combo or specify an API key.
3
- st2_username: ""
4
- st2_password: ""
5
- st2_api_key: ""
6
-
7
- # trailing slash mandatory
8
- st2_api_base_url: "https://localhost/api/v1/"
9
- st2_auth_base_url: "https://localhost/auth/v1/"
10
-
11
- sensu_host: localhost
12
- sensu_port: 4567
13
- sensu_user: sensu
14
- sensu_pass: ""
File without changes
@@ -1,20 +0,0 @@
1
- # coding: utf-8
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "sensu-plugins-stackstorm"
5
- spec.version = '0.0.2'
6
- spec.authors = ["Hiroyasu OHYAMA"]
7
- spec.email = ["user.localhost2000@gmail.com"]
8
-
9
- spec.summary = %q{Sensu plugins for StackStorm}
10
- spec.description = %q{}
11
- spec.homepage = "https://github.com/userlocalhost2000/sensu-plugins-stackstorm"
12
-
13
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
- spec.bindir = "bin"
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.license = "Apache-2.0"
17
-
18
- spec.add_development_dependency 'rspec', '~> 3.6'
19
- spec.add_development_dependency 'rake', '~> 12.0'
20
- end