-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcloud_monitoring.py
44 lines (38 loc) · 1.27 KB
/
cloud_monitoring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# home_assistant.py
import requests
import json
# Define the Home Assistant API endpoint
HASS_API = "http://localhost:8123/api/states"
HASS_TOKEN = "your_home_assistant_token"
# Define the Pi-CryptoConnect sensor entity
SENSOR_NAME = "pi_crypto_connect"
def update_sensor_state(state):
# Make a request to the Home Assistant API to update the sensor state
headers = {
"Authorization": f"Bearer {HASS_TOKEN}",
"content-type": "application/json",
}
data = {
"entity_id": f"sensor.{SENSOR_NAME}",
"state": state,
}
response = requests.put(HASS_API, headers=headers, data=json.dumps(data))
response.raise_for_status()
# cloud_monitoring.py
import requests
import json
# Define the cloud monitoring API endpoint
MONITORING_API = "https://your_cloud_monitoring_service/api/metrics"
MONITORING_TOKEN = "your_cloud_monitoring_token"
def send_metric(metric_name, value):
# Make a request to the cloud monitoring API to send a metric
headers = {
"Authorization": f"Bearer {MONITORING_TOKEN}",
"content-type": "application/json",
}
data = {
"name": metric_name,
"value": value,
}
response = requests.post(MONITORING_API, headers=headers, data=json.dumps(data))
response.raise_for_status()