aboutsummaryrefslogtreecommitdiffstats
path: root/on_battery.py
diff options
context:
space:
mode:
Diffstat (limited to 'on_battery.py')
-rw-r--r--on_battery.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/on_battery.py b/on_battery.py
new file mode 100644
index 0000000..6ea5e09
--- /dev/null
+++ b/on_battery.py
@@ -0,0 +1,32 @@
+from influxdb_client import InfluxDBClient, Point, WritePrecision
+from influxdb_client.client.write_api import SYNCHRONOUS
+import dotenv
+import os
+
+def main():
+ influxc = InfluxDBClient(
+ url = "http://%s:8086" % INFLUXDB_HOST,
+ token = os.environ["DOCKER_INFLUXDB_INIT_ADMIN_TOKEN"],
+ org = os.environ["DOCKER_INFLUXDB_INIT_ORG"]
+ )
+ influxc.ping()
+
+ write_api = influxc.write_api(write_options = SYNCHRONOUS)
+ write_api.write(
+ os.environ["DOCKER_INFLUXDB_INIT_BUCKET"],
+ os.environ["DOCKER_INFLUXDB_INIT_ORG"],
+ [{
+ "measurement": "ups_status",
+ "fields": {"on_battery": 1}
+ }],
+ write_precision = WritePrecision.S
+ )
+
+if __name__ == "__main__":
+ env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.env")
+ if os.path.exists(env_path):
+ import dotenv
+ dotenv.load_dotenv(dotenv_path = env_path)
+ INFLUXDB_HOST = "192.168.69.5"
+
+ main()