sensu-plugin-app-insights 0.1.0 → 0.2.0

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: e9ae59eb6ec9e60d91f7b8b623dd8647f8a2bedd
4
- data.tar.gz: 7167c835341c6fc1a4a7823c889b8e0d5a2ae97b
3
+ metadata.gz: 0b287dcda6555ade196e110e9505b94268091f52
4
+ data.tar.gz: 0053bdd0babc7c3ac50a15a06490fe9ef2344439
5
5
  SHA512:
6
- metadata.gz: 395834d9596d2d1d02652e181faa9b4bf1f1d011d12aec0a85432f99e2b930a8c9907be8d045b4024c79c1296358d9d9111bf1a23b713f73f1bb491326883783
7
- data.tar.gz: b95015d813074dde4624c1e0f8cca8ef16a431c3850cd83dc051f1472ffe9f52e67f0f9acb7baf41502aa860eb75d618a618b73613636ab5599e408c6f443ec3
6
+ metadata.gz: 2d6b65a7bb821e0ce867601c201f6f4c417de1e47e994ac62837e2db37ecb3e6d87ecbfbefe86dc713926172ca53a01043393416f8721a54e2f3c34db1695cb4
7
+ data.tar.gz: 4e96eb6cb9444f51081d2c620a02e5e79b857e1aaa326de49f646428a6ad0435347c8f4b7607f448ba75936cc9ee4ab05434621c37042bc41333384eeccc0d89
data/CHANGELOG.md CHANGED
@@ -0,0 +1,3 @@
1
+
2
+ # 0.2.0
3
+ Included support for inline queries.
data/README.md CHANGED
@@ -1,2 +1,50 @@
1
- # Sensu-App-Insights-Plugin
2
- sensu app insights plugin
1
+ [![Build Status](https://travis-ci.org/ve-interactive/sensu-plugin-app-insights.svg?branch=master)](https://travis-ci.org/ve-interactive/sensu-plugin-app-insights)
2
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugin-app-insights.svg)](https://badge.fury.io/rb/sensu-plugin-app-insights)
3
+
4
+ # Sensu plugin for application insights
5
+ This is a pugin for application insights it add capabilities for sensu to use the application insights api in order to create alerts.
6
+
7
+ # Installation Instructions
8
+ ## Gems
9
+
10
+ Installing via gem is the preferred method if one exists.
11
+
12
+ ### Standard Installation
13
+
14
+ `gem install sensu-plugin-app-insights`
15
+
16
+ Note: If the gem has an alpha tag then you will need to use the –prerelease flag or the gem will not be found.
17
+
18
+ ### Bundle
19
+
20
+ Add _sensu-plugin-app-insights_ to your Gemfile and run `bundle install` or `bundle update`
21
+
22
+ ### Chef
23
+
24
+ #### Using the Sensu sensu_gem LWRP
25
+ ```
26
+ sensu_gem 'sensu-plugin-app-insights' do
27
+ version '0.1.0'
28
+ end
29
+ ```
30
+ #### Using the Chef package resource
31
+ ```
32
+ gem_package 'sensu-plugin-app-insights' do
33
+ version '0.1.0'
34
+ end
35
+ ```
36
+ ### Puppet
37
+
38
+ #### Using the Puppet sensu_gem package provider
39
+ ```
40
+ package { 'sensu-plugin-app-insights':
41
+ ensure => '0.1.0',
42
+ provider => sensu_gem,
43
+ }
44
+ ```
45
+ ### Ansible
46
+
47
+ ```
48
+ - gem: name=sensu-plugin-app-insights version=0.1.0 state=present executable=/opt/sensu/embedded/bin/gem
49
+ ```
50
+
data/bin/query-check.rb CHANGED
@@ -58,12 +58,24 @@ class QueryCheck < Sensu::Plugin::Check::CLI
58
58
  option :query,
59
59
  short: '-q /file/with/query or https://fileUrl',
60
60
  long: '--query /file/with/query or https://fileUrl',
61
+ description: 'Query can be expressed as a path to a file a url that will return the raw query or directly inline.',
61
62
  required: true
62
- option :resultColumn, short: '-r COLUMN_NAME', long: '--resultColumn COLUMN_NAME'
63
- option :warningExpression, short: '-w WARNING_EXPRESSION value > 20', long: '--warning WARNING_EXPRESSION value > 20'
64
- option :criticalExpression, short: '-c CRITICAL_EXPRESSION value > 20', long: '--critical CRITICAL_EXPRESSION value > 20'
65
- option :message, short: '-m MESSAGE', long: '--message MESSAGE'
66
- option :timeout, short: '-t SECS', proc: proc(&:to_i), default: 15
63
+ option :resultColumn,
64
+ short: '-r COLUMN_NAME',
65
+ long: '--resultColumn COLUMN_NAME'
66
+ option :warningExpression,
67
+ short: '-w WARNING_EXPRESSION value > 20',
68
+ long: '--warning WARNING_EXPRESSION value > 20'
69
+ option :criticalExpression,
70
+ short: '-c CRITICAL_EXPRESSION value > 20',
71
+ long: '--critical CRITICAL_EXPRESSION value > 20'
72
+ option :message,
73
+ short: '-m MESSAGE',
74
+ long: '--message MESSAGE'
75
+ option :timeout,
76
+ short: '-t SECS',
77
+ proc: proc(&:to_i),
78
+ default: 60
67
79
 
68
80
  def run
69
81
  uri = URI.parse(config[:apiUrl])
@@ -116,7 +128,7 @@ class QueryCheck < Sensu::Plugin::Check::CLI
116
128
 
117
129
  def get_query(query)
118
130
  post_body = ''
119
- if query =~ /\A#{URI::regexp(['https', 'http'])}\z/
131
+ if query =~ /\A#{URI.regexp(%w(https http))}\z/
120
132
  uri = URI.parse(query)
121
133
  http_query = Net::HTTP.new(uri.host, uri.port)
122
134
  if uri.scheme == 'https'
@@ -131,10 +143,12 @@ class QueryCheck < Sensu::Plugin::Check::CLI
131
143
  critical "http code: #{res_query.code}: body: #{res_query.body}"
132
144
  end
133
145
  post_body = res_query.body
134
- else
146
+ elsif File.exist?(query)
135
147
  post_body = IO.readlines(query).join
148
+ else
149
+ post_body = query
136
150
  end
137
- encoded = URI.encode(post_body)
151
+ URI.encode(post_body)
138
152
  end
139
153
 
140
154
  def validate_result(json)
@@ -146,8 +160,12 @@ class QueryCheck < Sensu::Plugin::Check::CLI
146
160
  rows.each_with_index do |row, _index|
147
161
  values = extract_value(row, columns)
148
162
  value = row[column_index]
163
+ if values.nil? || value.nil?
164
+ critical 'unable to extract values'
165
+ end
166
+
149
167
  if config[:warningExpression]
150
- if instance_eval config[:warningExpression]
168
+ if instance_eval config[:warningExpression]
151
169
  if config[:message]
152
170
  warning_message.push instance_eval config[:message]
153
171
  else
@@ -1,7 +1,7 @@
1
1
  module SensuPluginAppInsights
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugin-app-insights
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
  - Ve Interactive and contributors