From e7c046159ca9180bce4effc36320de8e0628802f Mon Sep 17 00:00:00 2001 From: olivierHa Date: Wed, 18 Sep 2013 12:07:45 +0200 Subject: [PATCH 01/11] Add multi lines support --- check_graphite | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/check_graphite b/check_graphite index d36ca16..e2b79a8 100755 --- a/check_graphite +++ b/check_graphite @@ -52,6 +52,7 @@ graphite.add_option("U", "username", "User for authentication") graphite.add_option("P", "password", "Password for authentication") graphite.add_option("H", "hostname", "Host name to use in the URL") graphite.add_option("n", "none", "Ignore None values: 'yes' or 'no' (default no)") +graphite.add_option("s", "status_message", "Status Message (default function value of metric: value)",default=None) graphite.add_option("f", "function", "Function to run on retrieved values: avg/min/max/last/sum (default 'avg')", default="avg") @@ -79,25 +80,32 @@ usock.close() if graphite.options.function not in functionmap: graphite.unknown_error("Bad function name given to -f/--function option: '%s'" % graphite.options.function) -try: - pieces = data.split("|") - counter = pieces[0].split(",")[0] - values = pieces[1].split(",")[:-1] - if len(data.strip().split('\n')) > 1: - raise 'Graphite returned multiple lines' -except: - graphite.unknown_error("Graphite returned bad data") - -if graphite.options.none == 'yes': - values = map(lambda x: float(x), filter(lambda x: x != 'None', values)) +counter=None +values=None + +mdata = data.strip().split('\n') +for d in mdata: + try: + pieces = d.split("|") + counter = pieces[0].split(",")[0] + values = pieces[1].split(",")[:-1] + except: + graphite.unknown_error("Graphite returned bad data") + + if graphite.options.none == 'yes': + values = map(lambda x: float(x), filter(lambda x: x != 'None', values)) + else: + values = map(lambda x: 0.0 if x == 'None' else float(x), values) + if len(values) == 0: + graphite.unknown_error("Graphite returned an empty list of values") + else: + value = functionmap[graphite.options.function]["function"](values) + + graphite.set_value(counter, value) + +if graphite.options.status_message: + graphite.set_status_message(graphite.options.status_message) else: - values = map(lambda x: 0.0 if x == 'None' else float(x), values) -if len(values) == 0: - graphite.unknown_error("Graphite returned an empty list of values") -else: - value = functionmap[graphite.options.function]["function"](values) - -graphite.set_value(counter, value) -graphite.set_status_message("%s value of %s: %f" % (functionmap[graphite.options.function]["label"], counter, value)) + graphite.set_status_message("%s value of %s: %f" % (functionmap[graphite.options.function]["label"], counter, value)) graphite.finish() From 15dcad449e374ff7e9ff2019a6ed0968216b4c8a Mon Sep 17 00:00:00 2001 From: Joerg Date: Thu, 31 Oct 2013 11:12:35 +0100 Subject: [PATCH 02/11] use env for virtualenv to find python --- check_graphite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_graphite b/check_graphite index e2b79a8..4ae4699 100755 --- a/check_graphite +++ b/check_graphite @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright (c) 2011 Recoset # From 823571c36e1606561cc31ba1e351412478ec9cb8 Mon Sep 17 00:00:00 2001 From: Joerg Date: Thu, 31 Oct 2013 15:26:55 +0100 Subject: [PATCH 03/11] use all values after '|'. Throwed error with only one value returned from graphite --- check_graphite | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_graphite b/check_graphite index 4ae4699..505f9b8 100755 --- a/check_graphite +++ b/check_graphite @@ -88,7 +88,7 @@ for d in mdata: try: pieces = d.split("|") counter = pieces[0].split(",")[0] - values = pieces[1].split(",")[:-1] + values = pieces[1].split(",") except: graphite.unknown_error("Graphite returned bad data") From 518afd98c37025cd759e95b98f73db21c560a9c9 Mon Sep 17 00:00:00 2001 From: Nathan Haneysmith Date: Tue, 29 Jan 2013 00:23:18 +0000 Subject: [PATCH 04/11] update readme for new options --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90eec5e..f08eed3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,26 @@ Nagios plugin to poll Graphite What does it do? How does it work? How do I run it? --- -This is a Nagios plugin, so you install it and configure a service check in Nagios and it runs whenever Nagios calls it and reports back on the status of whatever it's monitoring. It takes one parameter (`-u`) which tells it the Graphite URL to monitor, for example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. When run, it will query that URL and treat the average of the values returned as the 'value' to be compared against the warning/critical thresholds, and return this value to Nagios as performance data. See Graphite's URL API documentation to generate the URL parameter. +This is a Nagios plugin, so you install it and configure a service check in Nagios and it runs whenever Nagios calls it and reports back on the status of whatever it's monitoring. It has one required parameter (`-u`) which tells it the Graphite URL to monitor, for example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. When run, it will query that URL and treat the average of the values returned as the 'value' to be compared against the warning/critical thresholds, and return this value to Nagios as performance data. See Graphite's URL API documentation to generate the URL parameter. + +Usage +--- +Usage: check_graphite -u URL [-U USERNAME] [-P PASSWORD] [-H HOSTNAME] [-n NONE] [-f FUNCTION] [-w WARNING] [-c CRITICAL] + +Plugin to retrieve data from graphite + +Options: +` -h, --help show this help message and exit + -V, --version show program's version number and exit + -v, --verbose Get more verbose status output. Can be specified up to three times + -u URL, --url=URL URL to query for data + -U USERNAME, --username=USERNAME User for authentication + -P PASSWORD, --password=PASSWORD Password for authentication + -H HOSTNAME, --hostname=HOSTNAME Host name to use in the URL + -n NONE, --none=NONE Ignore None values: 'yes' or 'no' (default no) + -f FUNCTION, --function=FUNCTION Function to run on retrieved values: avg/min/max/last/sum (default 'avg') + -w WARNING, --warning=WARNING Set the warning notification level. + -c CRITICAL, --critical=CRITICAL Set the critical notification level. ` Dependencies --- From b829fd5b403e8822c626e6b685702729ec865c5e Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:00:39 +0200 Subject: [PATCH 05/11] prettier formatting also remove trainling whitespaces --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f08eed3..29063a9 100644 --- a/README.md +++ b/README.md @@ -8,22 +8,24 @@ This is a Nagios plugin, so you install it and configure a service check in Nagi Usage --- +``` Usage: check_graphite -u URL [-U USERNAME] [-P PASSWORD] [-H HOSTNAME] [-n NONE] [-f FUNCTION] [-w WARNING] [-c CRITICAL] Plugin to retrieve data from graphite Options: -` -h, --help show this help message and exit - -V, --version show program's version number and exit - -v, --verbose Get more verbose status output. Can be specified up to three times - -u URL, --url=URL URL to query for data - -U USERNAME, --username=USERNAME User for authentication - -P PASSWORD, --password=PASSWORD Password for authentication - -H HOSTNAME, --hostname=HOSTNAME Host name to use in the URL - -n NONE, --none=NONE Ignore None values: 'yes' or 'no' (default no) - -f FUNCTION, --function=FUNCTION Function to run on retrieved values: avg/min/max/last/sum (default 'avg') - -w WARNING, --warning=WARNING Set the warning notification level. - -c CRITICAL, --critical=CRITICAL Set the critical notification level. ` + -h, --help show this help message and exit + -V, --version show program's version number and exit + -v, --verbose Get more verbose status output. Can be specified up to three times + -u URL, --url=URL URL to query for data + -U USERNAME, --username=USERNAME User for authentication + -P PASSWORD, --password=PASSWORD Password for authentication + -H HOSTNAME, --hostname=HOSTNAME Host name to use in the URL + -n NONE, --none=NONE Ignore None values: 'yes' or 'no' (default no) + -f FUNCTION, --function=FUNCTION Function to run on retrieved values: avg/min/max/last/sum (default 'avg') + -w WARNING, --warning=WARNING Set the warning notification level. + -c CRITICAL, --critical=CRITICAL Set the critical notification level. +``` Dependencies --- From 7ab3e940901614f02d349635ebda2a1b9de85706 Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:01:12 +0200 Subject: [PATCH 06/11] mention pip install ... which is an equally or even more popular way to install Python modules --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 29063a9..907e08a 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,4 @@ Dependencies Python 2.6+ -You'll need to have NagAconda installed (e.g. `easy_install nagaconda`) +You'll need to have NagAconda installed (e.g. `easy_install nagaconda` or `pip install nagaconda`) From 00558bf1b02f5f08e380f224e98f14f32f956091 Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:05:35 +0200 Subject: [PATCH 07/11] split lines it's easier to read in an editor with shorter lines --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 907e08a..96351c9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,16 @@ Nagios plugin to poll Graphite What does it do? How does it work? How do I run it? --- -This is a Nagios plugin, so you install it and configure a service check in Nagios and it runs whenever Nagios calls it and reports back on the status of whatever it's monitoring. It has one required parameter (`-u`) which tells it the Graphite URL to monitor, for example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. When run, it will query that URL and treat the average of the values returned as the 'value' to be compared against the warning/critical thresholds, and return this value to Nagios as performance data. See Graphite's URL API documentation to generate the URL parameter. +This is a Nagios plugin, so you install it and configure a service +check in Nagios and it runs whenever Nagios calls it and reports +back on the status of whatever it's monitoring. It has one required +parameter (`-u`) which tells it the Graphite URL to monitor, for +example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. +When run, it will query that URL and treat the average of the +values returned as the 'value' to be compared against the +warning/critical thresholds, and return this value to Nagios as +performance data. See Graphite's URL API documentation to generate +the URL parameter. Usage --- From fb8eacb2289c0aa7201ef03cc5b71497cb89b8bc Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:07:15 +0200 Subject: [PATCH 08/11] mark the required parameter --- README.md | 2 +- check_graphite | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96351c9..00ffbe4 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Options: -h, --help show this help message and exit -V, --version show program's version number and exit -v, --verbose Get more verbose status output. Can be specified up to three times - -u URL, --url=URL URL to query for data + -u URL, --url=URL URL to query for data (required) -U USERNAME, --username=USERNAME User for authentication -P PASSWORD, --password=PASSWORD Password for authentication -H HOSTNAME, --hostname=HOSTNAME Host name to use in the URL diff --git a/check_graphite b/check_graphite index 505f9b8..295f698 100755 --- a/check_graphite +++ b/check_graphite @@ -47,7 +47,7 @@ functionmap = { } graphite = Plugin("Plugin to retrieve data from graphite", "1.0") -graphite.add_option("u", "url", "URL to query for data", required=True) +graphite.add_option("u", "url", "URL to query for data (required)", required=True) graphite.add_option("U", "username", "User for authentication") graphite.add_option("P", "password", "Password for authentication") graphite.add_option("H", "hostname", "Host name to use in the URL") From ae683112fda44af714c3ef901a3126b0bfb00d82 Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:21:41 +0200 Subject: [PATCH 09/11] improve text --- README.md | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 00ffbe4..84430e0 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,29 @@ Nagios plugin to poll Graphite -=== +============================== What does it do? How does it work? How do I run it? ---- - -This is a Nagios plugin, so you install it and configure a service -check in Nagios and it runs whenever Nagios calls it and reports -back on the status of whatever it's monitoring. It has one required -parameter (`-u`) which tells it the Graphite URL to monitor, for -example `http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true`. -When run, it will query that URL and treat the average of the -values returned as the 'value' to be compared against the -warning/critical thresholds, and return this value to Nagios as -performance data. See Graphite's URL API documentation to generate +--------------------------------------------------- + +This is a Nagios plugin. Install it and configure a service +check in Nagios and it will run whenever Nagios calls it and +will report back on the status of whatever it's monitoring. + +It has one required parameter `-u` which tells it the Graphite +URL to monitor, for example: + + http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true` + +When run, it will query that URL, calculate the average (or +another function) of the recieved values, compare the average +to the warning/critical thresholds, and return the value to +Nagios as performance data. + +See Graphite's URL API documentation on how to generate the URL parameter. Usage ---- +----- + ``` Usage: check_graphite -u URL [-U USERNAME] [-P PASSWORD] [-H HOSTNAME] [-n NONE] [-f FUNCTION] [-w WARNING] [-c CRITICAL] @@ -37,7 +44,7 @@ Options: ``` Dependencies ---- +------------ Python 2.6+ From de12008c1534ad17049201666cdf94d3013198ab Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:22:16 +0200 Subject: [PATCH 10/11] threshold levels are required at least on my system, if not given, then NagAnaconda will error out --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84430e0..6307886 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Usage ----- ``` -Usage: check_graphite -u URL [-U USERNAME] [-P PASSWORD] [-H HOSTNAME] [-n NONE] [-f FUNCTION] [-w WARNING] [-c CRITICAL] +Usage: check_graphite -u URL [-U USERNAME] [-P PASSWORD] [-H HOSTNAME] [-n NONE] [-f FUNCTION] -w WARNING -c CRITICAL Plugin to retrieve data from graphite @@ -39,8 +39,8 @@ Options: -H HOSTNAME, --hostname=HOSTNAME Host name to use in the URL -n NONE, --none=NONE Ignore None values: 'yes' or 'no' (default no) -f FUNCTION, --function=FUNCTION Function to run on retrieved values: avg/min/max/last/sum (default 'avg') - -w WARNING, --warning=WARNING Set the warning notification level. - -c CRITICAL, --critical=CRITICAL Set the critical notification level. + -w WARNING, --warning=WARNING Set the warning notification level (required) + -c CRITICAL, --critical=CRITICAL Set the critical notification level (required) ``` Dependencies From 9780eaadf99f4e21fefccef1eec22fe06eabaaa8 Mon Sep 17 00:00:00 2001 From: Tomas Pospisek Date: Mon, 3 Oct 2022 16:23:18 +0200 Subject: [PATCH 11/11] add shell example --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6307886..c9bb68d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,11 @@ Options: -c CRITICAL, --critical=CRITICAL Set the critical notification level (required) ``` +Example +------- + + check_graphite -u http://server/render?target=stats.auctionStart&from=-1minutes&rawData=true -w 10,20 -c 20,30 + Dependencies ------------