Sensu plugin for application insights
This is a pugin for application insights it add capabilities for sensu to use the application insights api in order to create alerts.
Functionality
Files
- bin/query-check.rb
Usage
query-check.rb
query-check.rb
-a, --apiURL URL
-V, --apiVersion beta
-i, --appId GUID
-p, --appKey VALUE
-q, --query /file/with/query or https://fileUrl,
-r, --resultColumn COLUMN_NAME,
-w, --warning WARNING_EXPRESSION value > 20,
-c, --critical CRITICAL_EXPRESSION value > 20,
-m, --message MESSAGE,
-t, --timeout SECS
Parameters that should be used
- -a, --apiURL
- This is the base api url used to connect with application insights you should not change this unless you really know what you are doing. the default value for this is https://api.applicationinsights.io/beta
- -V, --apiVersion
- This is the api version that you are using on application insights as the url you should only change that if you really know what you are doing.
- -i, --appId required
- This is the application id of your application insights used to send the telemetry (also known as telemetry key) you can find instruction here
- -p, --appKey required
- This is the appKey that are going to be using to connect to your application insights you can get information on how to obtain this api key here
- -q, --query required
- Here it is where you should put the application insights query that you pretend to execute. there are 3 supported ways to include the query you can pass a path to a file that has the query
./file/name.ext
the file can have any extension but need to be composed only from the query. Another option it is to have a urlhttps://file.location.com/file.txt
a get request will be made for this url and the content will be executed as a query. The other option it is to use directly the query inlinerequests | limit 10
remembering that breaking lines are not allowed in case you are using the inline query.
- Here it is where you should put the application insights query that you pretend to execute. there are 3 supported ways to include the query you can pass a path to a file that has the query
- -r, --resultColumn
- This is one optional argument that specify the column that will have their value passed to the variable
value
when evaluating the rows. If this is not specified the value will be equal the value of the first numerical column on the result, if there is no numerical value it will be the value of the first column.
- This is one optional argument that specify the column that will have their value passed to the variable
- -w, --warning
- This is the expression that will be used to evaluate
Evaluatin Expressions
The warning and critical expressions are actually evaluated ruby expresions. so any ruby expression can be used here. it is interesting to notice however that there are come variables available for you to use on this that might help you on evaluating the query. this fields are value
and values
where value it is the result accoding to what it is specified on the resultColumn
parameter
Exemple:
I want to evaluate the following query. that get the amount of times that a product was viewed and the amount of times that a product was bought per each one of the customers and the percentage of sales per view.
customEvents
| where timestamp >= ago(7d)
| where name in (‘A’ , ‘B’)
| extend vendor = tostring(customDimensions.vendor)
| summarize productViewed = countif(name == ‘A’), productBought = countif(name==’B) by vendor, bin(timestamp, 1d)
| extend pct = productBought*100.0 / productViewed
My alert would be warning when there are less than 100 product being viewed or when the percentage of sales goes under 2% and critical if I have 0 sales in one day.
If I specify the resultColumn
beeing productViewed
with -r productViewed
on the command line.
Them I can specify the warning expression -w "value < 100 || values['pct'] < 2"
Installation Instructions
Gems
Installing via gem is the preferred method if one exists.
Standard Installation
gem install sensu-plugin-app-insights
Note: If the gem has an alpha tag then you will need to use the –prerelease flag or the gem will not be found.
Bundle
Add sensu-plugin-app-insights to your Gemfile and run bundle install
or bundle update
Chef
Using the Sensu sensu_gem LWRP
sensu_gem 'sensu-plugin-app-insights' do
version '0.2.0'
end
Using the Chef package resource
gem_package 'sensu-plugin-app-insights' do
version '0.2.0'
end
Puppet
Using the Puppet sensu_gem package provider
package { 'sensu-plugin-app-insights':
ensure => '0.2.0',
provider => sensu_gem,
}
Ansible
- gem: name=sensu-plugin-app-insights version=0.2.0 state=present executable=/opt/sensu/embedded/bin/gem