Révision 90d214cd
Plugin feinstaubsensor: omit graphs for missing API fieldnames
Some sensor data fields may not be available, if the specific component
is missing.
| plugins/luftdaten/feinstaubsensor | ||
|---|---|---|
| 176 | 176 |
|
| 177 | 177 |
|
| 178 | 178 |
def print_graph_section(graph_description, hosts, include_config, include_values): |
| 179 |
print("multigraph {}".format(graph_description["name"]))
|
|
| 180 |
if include_config: |
|
| 181 |
# graph configuration |
|
| 182 |
print("graph_category sensors")
|
|
| 183 |
for key in ("graph_title", "graph_vlabel", "graph_args", "graph_info"):
|
|
| 184 |
if key in graph_description: |
|
| 185 |
print("{} {}".format(key, graph_description[key]))
|
|
| 186 |
for host_info in hosts: |
|
| 187 |
print("{}.label {}".format(host_info.fieldname, host_info.label))
|
|
| 188 |
print("{}.type {}".format(host_info.fieldname, graph_description["value_type"]))
|
|
| 189 |
if include_values: |
|
| 190 |
for host_info in hosts: |
|
| 191 |
# We cannot distinguish between fields that are not supported by the sensor (most are |
|
| 192 |
# optional) and missing data. Thus we cannot handle online/offline sensor data fields, |
|
| 193 |
# too. |
|
| 194 |
data = get_sensor_data(host_info.host) |
|
| 195 |
if data is not None: |
|
| 196 |
value = data.get(graph_description["api_value_name"]) |
|
| 197 |
if value is not None: |
|
| 198 |
print("{}.value {}".format(host_info.fieldname, value))
|
|
| 199 |
print() |
|
| 179 |
# retrieve the data and omit ony output, if the relevant key is missing |
|
| 180 |
results = [] |
|
| 181 |
for host_info in hosts: |
|
| 182 |
data = get_sensor_data(host_info.host) |
|
| 183 |
if data: |
|
| 184 |
for dataset in data["sensordatavalues"]: |
|
| 185 |
if dataset["value_type"] == graph_description["api_value_name"]: |
|
| 186 |
results.append((host_info, dataset["value"])) |
|
| 187 |
break |
|
| 188 |
else: |
|
| 189 |
# We cannot distinguish between fields that are not supported by the sensor (most |
|
| 190 |
# are optional) and missing data. Thus we cannot handle online/offline sensor data |
|
| 191 |
# fields, too. |
|
| 192 |
pass |
|
| 193 |
# skip this multigraph, if no host contained this data field |
|
| 194 |
if results: |
|
| 195 |
print("multigraph {}".format(graph_description["name"]))
|
|
| 196 |
if include_config: |
|
| 197 |
# graph configuration |
|
| 198 |
print("graph_category sensors")
|
|
| 199 |
for key in ("graph_title", "graph_vlabel", "graph_args", "graph_info"):
|
|
| 200 |
if key in graph_description: |
|
| 201 |
print("{} {}".format(key, graph_description[key]))
|
|
| 202 |
for host_info, value in results: |
|
| 203 |
print("{}.label {}".format(host_info.fieldname, host_info.label))
|
|
| 204 |
print("{}.type {}".format(host_info.fieldname, graph_description["value_type"]))
|
|
| 205 |
if include_values: |
|
| 206 |
for host_info, value in results: |
|
| 207 |
print("{}.value {}".format(host_info.fieldname, value))
|
|
| 208 |
print() |
|
| 200 | 209 |
|
| 201 | 210 |
|
| 202 | 211 |
action = sys.argv[1] if (len(sys.argv) > 1) else "" |
Formats disponibles : Unified diff