add bundle:telegraf_airgradient

This commit is contained in:
Franzi 2024-01-23 09:30:13 +01:00
parent bb56f0fb9a
commit 5ffbe50b1e
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 80 additions and 0 deletions

View file

@ -0,0 +1,54 @@
#!/usr/bin/python3
from logging import basicConfig, getLogger
from sys import argv
from requests import get
basicConfig(level="INFO")
L = getLogger(__name__)
def out(keys, values):
print(
"airgradient,{} {}".format(
",".join([f"{k}={v}" for k, v in keys.items()]),
",".join([f"{k}={v}" for k, v in values.items()]),
),
flush=True,
)
try:
r = get(
f"https://api.airgradient.com/public/api/v1/locations/measures/current?token={argv[2]}"
)
L.debug(r.status_code)
L.info(r.text)
r.raise_for_status()
for location in r.json():
L.debug(location)
out(
{
"place": argv[1],
"location": location["locationName"],
},
{
k: location[k]
for k in (
"atmp",
"noxIndex",
"pm003Count",
"pm01",
"pm02",
"pm10",
"rco2",
"rhum",
"tvoc",
"tvocIndex",
"wifi",
)
},
)
except Exception:
L.exception("fail!")

View file

@ -0,0 +1,3 @@
files['/usr/local/bin/airgradient_telegraf'] = {
'mode': '0755',
}

View file

@ -0,0 +1,19 @@
@metadata_reactor.provides(
'telegraf/input_plugins/exec',
)
def telegraf(metadata):
result = {}
for location, api_key in metadata.get('telegraf_airgradient', {}).items():
result[f'airgradient_{location}'] = {
'commands': [f'/usr/local/bin/airgradient_telegraf {location} {api_key}'],
'data_format': 'influx',
'timeout': '10s',
}
return {
'telegraf': {
'input_plugins': {
'exec': result,
},
},
}

View file

@ -3,6 +3,7 @@ nodes['htz-cloud.influxdb'] = {
'bundles': {
'grafana',
'influxdb2',
'telegraf_airgradient',
'telegraf-monitors-mikrotik',
'zfs',
},
@ -66,6 +67,9 @@ nodes['htz-cloud.influxdb'] = {
},
},
},
'telegraf_airgradient': {
'Home': vault.decrypt('encrypt$gAAAAABlr3KvHLSHLFwVr5hvJ1j676Flm5fVLumqpBcffjYWXjPjSovDXCyEcVqhxfsX-GNut2dXsenFQoFShaAugLV_zVQYaLnNQipbZqI0cXfsMht1iZPyOxlSzy3YoZ3voSaeiLll'),
},
'telegraf': {
'input_plugins': {
'builtin': {