-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtelemetry_config.py
More file actions
152 lines (147 loc) · 5.24 KB
/
telemetry_config.py
File metadata and controls
152 lines (147 loc) · 5.24 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from pathlib import Path
from sift_py.ingestion.channel import (
ChannelBitFieldElement,
ChannelConfig,
ChannelDataType,
ChannelEnumType,
)
from sift_py.ingestion.config.telemetry import FlowConfig, TelemetryConfig
from sift_py.ingestion.rule.config import (
RuleActionCreateDataReviewAnnotation,
RuleConfig,
)
RULE_NAMESPACES_DIR = Path().joinpath("rule_modules")
def nostromos_lv_426() -> TelemetryConfig:
log_channel = ChannelConfig(
name="log",
data_type=ChannelDataType.STRING,
description="asset logs",
)
velocity_channel = ChannelConfig(
name="velocity",
data_type=ChannelDataType.DOUBLE,
description="speed",
unit="Miles Per Hour",
component="mainmotor",
)
voltage_channel = ChannelConfig(
name="voltage",
data_type=ChannelDataType.INT_32,
description="voltage at source",
unit="Volts",
)
vehicle_state_channel = ChannelConfig(
name="vehicle_state",
data_type=ChannelDataType.ENUM,
description="vehicle state",
enum_types=[
ChannelEnumType(name="Accelerating", key=0),
ChannelEnumType(name="Decelerating", key=1),
ChannelEnumType(name="Stopped", key=2),
],
)
gpio_channel = ChannelConfig(
name="gpio",
data_type=ChannelDataType.BIT_FIELD,
description="on/off values for pins on gpio",
bit_field_elements=[
ChannelBitFieldElement(name="12v", index=0, bit_count=1),
ChannelBitFieldElement(name="charge", index=1, bit_count=2),
ChannelBitFieldElement(name="led", index=3, bit_count=4),
ChannelBitFieldElement(name="heater", index=7, bit_count=1),
],
)
raw_binary_channel = ChannelConfig(
name="raw_bin",
data_type=ChannelDataType.BYTES,
description="Example of binary encoded data (binary string encoding of time in seconds)",
)
return TelemetryConfig(
asset_name="NostromoLV426",
flows=[
FlowConfig(
name="readings",
channels=[
velocity_channel,
voltage_channel,
vehicle_state_channel,
gpio_channel,
raw_binary_channel,
],
),
FlowConfig(
name="voltage",
channels=[voltage_channel],
),
FlowConfig(
name="gpio_channel",
channels=[gpio_channel],
),
FlowConfig(name="logs", channels=[log_channel]),
],
rules=[
RuleConfig(
name="overheating",
description="Checks for vehicle overheating",
expression='$1 == "Accelerating" && $2 > 80',
rule_client_key="overheating-rule",
asset_names=["NostromoLV426"],
channel_references=[
# INFO: Can use either a channel idenfier string or a ChannelConfig
{
"channel_reference": "$1",
"channel_identifier": vehicle_state_channel.identifier,
},
{
"channel_reference": "$2",
"channel_config": voltage_channel,
},
],
action=RuleActionCreateDataReviewAnnotation(),
),
RuleConfig(
name="kinetic_energy",
description="Tracks high energy output while in motion",
expression="0.5 * $mass * $1 * $1 > $threshold",
rule_client_key="kinetic-energy-rule",
asset_names=["NostromoLV426"],
channel_references=[
{
"channel_reference": "$1",
"channel_config": voltage_channel,
},
],
sub_expressions={
"$mass": 10,
"$threshold": 470,
},
action=RuleActionCreateDataReviewAnnotation(
# User in your organization to notify
# assignee="ellen.ripley@weylandcorp.com",
tags=["nostromo"],
),
),
RuleConfig(
name="failure",
description="Checks for failures reported by logs",
expression="contains($1, $sub_string)",
rule_client_key="failure-rule",
asset_names=["NostromoLV426"],
contextual_channels=[vehicle_state_channel.name],
channel_references=[
{
"channel_reference": "$1",
"channel_config": log_channel,
},
],
sub_expressions={
"$sub_string": "failure",
},
action=RuleActionCreateDataReviewAnnotation(
# User in your organization to notify
# assignee="ellen.ripley@weylandcorp.com",
tags=["nostromo", "failure"],
),
),
],
)