From 9e906798ba0f7203c5bd0987990f4ad7f1334aee Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Sat, 9 May 2020 12:11:22 +0200 Subject: [PATCH 1/7] Update to python3, not python2 compatible --- influxdbnagiosplugin/resources.py | 2 +- influxdbnagiosplugin/summaries.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdbnagiosplugin/resources.py b/influxdbnagiosplugin/resources.py index 593af9b..3e2babc 100644 --- a/influxdbnagiosplugin/resources.py +++ b/influxdbnagiosplugin/resources.py @@ -43,7 +43,7 @@ def probe(self): Query InfluxDB; yield the count and mean of the measurements. """ def get_value(result): - for key, value in result.iteritems(): + for key, value in result.items(): if key != "time": return value diff --git a/influxdbnagiosplugin/summaries.py b/influxdbnagiosplugin/summaries.py index 3d19ca9..dc10f8e 100644 --- a/influxdbnagiosplugin/summaries.py +++ b/influxdbnagiosplugin/summaries.py @@ -18,7 +18,7 @@ def __init__(self, query): self.query = query def ok(self, results): - result = filter(is_values, results)[0] + result = next(filter(is_values, results)) return "{} is {}".format( self.query.measurements[0] if self.query.measurements else "result", result.metric.value, From a0071458fff22112e9fb57f04a940d57e5516e3f Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Sat, 9 May 2020 12:31:58 +0200 Subject: [PATCH 2/7] Minor additions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf29c99..58a7edc 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,12 @@ Use pip: Command line entry point. Defines common arguments. Options: - -v, --verbose + -v, --verbose Can be specified multiple times for increasing verbosity --hostname TEXT InfluxDB hostname --port INTEGER InfluxDB port --username TEXT InfluxDB usernanme --password TEXT InfluxDB password - --database TEXT InfluxDB database name + --database TEXT InfluxDB database name, default 'telegraf' --count-error-range TEXT Range of measurement counts that are NOT considered an error --count-warning-range TEXT Range of measurement counts that are NOT From 676681e0811fc671596cd94800f530e1bc344a30 Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Sat, 9 May 2020 21:36:01 +0200 Subject: [PATCH 3/7] Updated version number and setup.py is now python3 --- influxdbnagiosplugin/main.py | 4 ++-- setup.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/influxdbnagiosplugin/main.py b/influxdbnagiosplugin/main.py index 78bbabb..3904439 100644 --- a/influxdbnagiosplugin/main.py +++ b/influxdbnagiosplugin/main.py @@ -15,12 +15,12 @@ @group(chain=True) -@option("-v", "--verbose", count=True) +@option("-v", "--verbose", count=True, help="Can be specified multiple times for increasing verbosity") @option("--hostname", default="localhost", help="InfluxDB hostname") @option("--port", default=8086, help="InfluxDB port") @option("--username", default="influxdb", help="InfluxDB usernanme") @option("--password", default="secret", help="InfluxDB password") -@option("--database", default="telegraf", help="InfluxDB database name") +@option("--database", default="telegraf", help="InfluxDB database name, default \'telegraf\'") @option("--count-error-range", default="1:", help="Range of measurement counts that are NOT considered an error") # noqa @option("--count-warning-range", default="2:", help="Range of measurement counts that are NOT considered a warning") # noqa @option("--mean-error-range", default="", help="Range of measurement means that are NOT considered an error") # noqa diff --git a/setup.py b/setup.py index d24d483..a5f8a3e 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup, find_packages -__version__ = "1.4" +__version__ = "1.5" setup( name="influxdbnagiosplugin", From 55fb6d039346503b624c1754847ebad880414c33 Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Sun, 10 May 2020 22:35:15 +0200 Subject: [PATCH 4/7] Fix typo in arguments description --- README.md | 2 +- influxdbnagiosplugin/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58a7edc..a0036b7 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Use pip: considered a warning --mean-error-range TEXT Range of measurement means that are NOT considered an error - --mean-warning-range TEXT Range of measurement counts that are NOT + --mean-warning-range TEXT Range of measurement means that are NOT considered a warning --timeout INTEGER Timeout in seconds for connecting to InfluxDB --help Show this message and exit. diff --git a/influxdbnagiosplugin/main.py b/influxdbnagiosplugin/main.py index 3904439..a1264aa 100644 --- a/influxdbnagiosplugin/main.py +++ b/influxdbnagiosplugin/main.py @@ -24,7 +24,7 @@ @option("--count-error-range", default="1:", help="Range of measurement counts that are NOT considered an error") # noqa @option("--count-warning-range", default="2:", help="Range of measurement counts that are NOT considered a warning") # noqa @option("--mean-error-range", default="", help="Range of measurement means that are NOT considered an error") # noqa -@option("--mean-warning-range", default="", help="Range of measurement counts that are NOT considered a warning") # noqa +@option("--mean-warning-range", default="", help="Range of measurement means that are NOT considered a warning") # noqa @option("--timeout", default=5, help="Timeout in seconds for connecting to InfluxDB") def main(**kwargs): """ From 966cad0f48c8b5688f54cd13c66a8eb6b377ec80 Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Sun, 10 May 2020 23:28:23 +0200 Subject: [PATCH 5/7] Explicit option setting order --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0036b7..7217cbf 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Use pip: Command line entry point. Defines common arguments. - Options: + Options 1: -v, --verbose Can be specified multiple times for increasing verbosity --hostname TEXT InfluxDB hostname --port INTEGER InfluxDB port @@ -63,20 +63,20 @@ Use pip: query Run an explicit query. single Run a query for a single measurement. - check-measurement [OPTIONS] single [OPTIONS] MEASUREMENT HOSTNAME + check-measurement [OPTIONS1] single [OPTIONS2] MEASUREMENT HOSTNAME Run a query for a single measurement. - Options: + Options 2: --age TEXT --where TEXT Extra where conditions to include. --field TEXT --help Show this message and exit. - Usage: check-measurement query [OPTIONS] QUERY + Usage: check-measurement [OPTIONS1] query [OPTIONS3] QUERY Run an explicit query. - Options: + Options 3: --help Show this message and exit. From 894577fb0708e906fb9613f58a3a74be3e8ba9b9 Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Thu, 14 May 2020 21:50:08 +0200 Subject: [PATCH 6/7] Added examples to README --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7217cbf..c2ad8d6 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ Use pip: ## Usage - Usage: check-measurement [OPTIONS] COMMAND1 [ARGS]... - + Usage: check-measurement [OPTIONS1] COMMAND [OPTIONS2|OPTIONS3]... + Command line entry point. Defines common arguments. - + Options 1: -v, --verbose Can be specified multiple times for increasing verbosity --hostname TEXT InfluxDB hostname @@ -58,25 +58,55 @@ Use pip: considered a warning --timeout INTEGER Timeout in seconds for connecting to InfluxDB --help Show this message and exit. - + Commands: query Run an explicit query. single Run a query for a single measurement. - - check-measurement [OPTIONS1] single [OPTIONS2] MEASUREMENT HOSTNAME - + + Usage1: check-measurement [OPTIONS1] single [OPTIONS2] MEASUREMENT HOSTNAME + Run a query for a single measurement. - + Options 2: --age TEXT --where TEXT Extra where conditions to include. --field TEXT --help Show this message and exit. + + Usage2 : check-measurement [OPTIONS1] query [OPTIONS3] QUERY + + Run an explicit query. + + Options 3: + --help Show this message and exit. +## Examples - Usage: check-measurement [OPTIONS1] query [OPTIONS3] QUERY +### Run a query for a single measurement - Run an explicit query. +Run a query for a `cpu` measurement `cpu-total` the field value `usage_iowait` filtered for host `yourhost`.The options used before the `single` command and after the `single` command can not be switched. + +```shell +$./check-measurement --mean-error-range 10 --mean-warning-range 5 single --field usage_iowait --where cpu='cpu-total' --age 2m cpu yourhost +``` + +Output: + +```shell +MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 +``` + +### Run an explicit query + +Run an explicit query `SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'mo4' AND cpu = 'cpu-total'` + +```shell +$./check-measurement --mean-error-range 10 --mean-warning-range 5 query "SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'yourhost' AND cpu = 'cpu-total'" +``` + +Output: + +```shell +MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 +``` - Options 3: - --help Show this message and exit. From 945eeb518d22863a7878b3726b24d8a2e9e485bb Mon Sep 17 00:00:00 2001 From: Paul Boot Date: Thu, 14 May 2020 21:56:21 +0200 Subject: [PATCH 7/7] Formatting --- README.md | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c2ad8d6..f6d0ffb 100644 --- a/README.md +++ b/README.md @@ -83,30 +83,22 @@ Use pip: ## Examples ### Run a query for a single measurement - Run a query for a `cpu` measurement `cpu-total` the field value `usage_iowait` filtered for host `yourhost`.The options used before the `single` command and after the `single` command can not be switched. -```shell -$./check-measurement --mean-error-range 10 --mean-warning-range 5 single --field usage_iowait --where cpu='cpu-total' --age 2m cpu yourhost -``` + $./check-measurement --mean-error-range 10 --mean-warning-range 5 single \ + --field usage_iowait --where cpu='cpu-total' --age 2m cpu yourhost Output: -```shell -MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 -``` + MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 ### Run an explicit query - Run an explicit query `SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'mo4' AND cpu = 'cpu-total'` -```shell -$./check-measurement --mean-error-range 10 --mean-warning-range 5 query "SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'yourhost' AND cpu = 'cpu-total'" -``` + $./check-measurement --mean-error-range 10 --mean-warning-range 5 query \ + "SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'yourhost' AND cpu = 'cpu-total'" Output: -```shell -MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 -``` + MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10