sensucronic 0.1.0 → 0.2.0

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: 4e6fe2076af1cbc5abb22a7ba3c44f69681e48f6
4
- data.tar.gz: 4ecb05e178254f4bca2db044de92bc4eff4c934e
3
+ metadata.gz: 9e01cc5d1c42a8bd017202854743c02ce9f898d8
4
+ data.tar.gz: 3391b35378ab5cb3af477a40ae9c71b10274e9fa
5
5
  SHA512:
6
- metadata.gz: e226aa25c316211ba25f6e2956b8f481532849db6a5993dddbe1ca542d427c3fc0609b07bd7516c93fe8e1350e74588f97a07cf62293820fad82f83af1907442
7
- data.tar.gz: b369c708948112ecbe4b6f7002cf2352b07dc44faab71e1895ddfe3d67a1ab13ca57acae9cba9905f11716f891e56182bf60784ff7830a7f0fe809cc9d7b1ca4
6
+ metadata.gz: 7a92ee79252c5e4dec6b1fe7587db98d4ed5cb7b0fe1fe896ae95789b5f571cd7af53933c220011b95905a68e6b84bf757fcf51d2d1b187330a3a200bb291e95
7
+ data.tar.gz: d56e75d329047d178d736861c29675a297d737dc385f8d5da9db113db53bafd2c58034b9b695e040dfc630f3b84210059e6013d495a4d4ad2bdf57f307b04732
data/README.md CHANGED
@@ -8,8 +8,6 @@ sensu ecosystem
8
8
 
9
9
  ## Installation
10
10
 
11
- TODO: release gem so this works.
12
-
13
11
  Add this line to your application's Gemfile:
14
12
 
15
13
  ```ruby
@@ -36,6 +34,19 @@ sensucronic [ OPTIONS ] [ -- ] 'COMMAND [ ARGS ]'
36
34
  sensucronic runs COMMAND with ARGS it generates a json report and submits
37
35
  it to the sensu-client input socket
38
36
 
37
+ use --help to view options
38
+ ```
39
+ prompt% sensucronic --help
40
+ s@otfess-3-1645% bundle exec exe/sensucronic --help
41
+ Usage: sensucronic (options)
42
+ -d, --dry-run output result to stdout only
43
+ -f, --field "key: value" add a field to the json report
44
+ -h, --help print this message
45
+ -p, --port PORT the port number for the sensu client input socket
46
+ -s, --source SOURCE set the source attribute on the sensu result
47
+
48
+ ```
49
+
39
50
  the OPTION --dryrun causes sensucronic to issue it's report to stdout
40
51
  instead of the sensu client input socket.
41
52
 
@@ -92,19 +103,27 @@ prompt% sensucronic --dry-run 'exit 3'
92
103
 
93
104
  ```
94
105
 
95
- use --help to view options
106
+ the option --field allows you to add arbitrary attributes to the json
107
+ report. you can repeat it as often as you need. note that you can't override the built in fields.
108
+
96
109
  ```
97
- prompt% sensucronic --help
98
- Usage: sensucronic (options)
99
- -d, --dry-run output result to stdout only
100
- -h, --help print this message
101
- -p, --port PORT the port number for the sensu client input socket
102
- -s, --source SOURCE set the source attribute on the sensu result
110
+ prompt% sensucronic --field 'team: blah' --field foo:bar --field output:blah --dry-run 'echo hi; exit 20'
111
+ {
112
+ "command": "echo\\ hi\\;\\ exit\\ 20",
113
+ "output": "hi\n",
114
+ "status": 3,
115
+ "exitcode": 20,
116
+ "agent": "sensucronic",
117
+ "team": "blah",
118
+ "foo": "bar"
119
+ }
103
120
  ```
104
121
 
122
+
105
123
  ## TODO
106
- - accept options to add extra fields to the output
107
124
  - accept options to configure the status in response to the exitcodes. (always warn, always crit )
125
+ - allow specifying alternate host, currently the sensu agent must be running on the local box.
126
+ - maybe submit via http to client http api on another host
108
127
 
109
128
  ## Development
110
129
 
@@ -15,6 +15,13 @@ class Sensucronic
15
15
  :default => false,
16
16
  :description => 'output result to stdout only'
17
17
 
18
+ option :field,
19
+ :short => '-f "key: value"',
20
+ :long => '--field "key: value"',
21
+ :default => [],
22
+ :proc => proc { |f,cur| cur << f },
23
+ :description => 'add a field to the json report'
24
+
18
25
  option :port,
19
26
  :short => '-p PORT',
20
27
  :long => '--port PORT',
@@ -115,16 +122,23 @@ class Sensucronic
115
122
  end
116
123
  end
117
124
 
125
+ def fields
126
+ config[:field]
127
+ .map { |f| f.split(/:\s*/,2) }
128
+ .each_with_object({}) { |(k,v), h| h[k.to_sym] = v }
129
+ end
130
+
118
131
  def report
119
132
  {
120
133
  command: Shellwords.shelljoin(cli_arguments),
121
134
  output: output,
122
135
  status: sensu_status,
123
136
  exitcode: exitcode,
124
- agent: self.class.to_s.downcase
137
+ agent: self.class.to_s.downcase,
125
138
  }.tap do |r|
126
139
  r[:exitsignal] = status.termsig if status.termsig
127
140
  r[:source] = config[:source] if config[:source]
141
+ r.update(fields) { |k,o,n| o }
128
142
  end
129
143
  end
130
144
 
@@ -1,3 +1,3 @@
1
1
  class Sensucronic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensucronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fess