PyAutomationIO 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- automation/__init__.py +46 -0
- automation/alarms/__init__.py +563 -0
- automation/alarms/states.py +192 -0
- automation/alarms/trigger.py +64 -0
- automation/buffer.py +132 -0
- automation/core.py +1775 -0
- automation/dbmodels/__init__.py +23 -0
- automation/dbmodels/alarms.py +524 -0
- automation/dbmodels/core.py +86 -0
- automation/dbmodels/events.py +153 -0
- automation/dbmodels/logs.py +155 -0
- automation/dbmodels/machines.py +181 -0
- automation/dbmodels/opcua.py +81 -0
- automation/dbmodels/opcua_server.py +174 -0
- automation/dbmodels/tags.py +921 -0
- automation/dbmodels/users.py +259 -0
- automation/extensions/__init__.py +15 -0
- automation/extensions/api.py +149 -0
- automation/extensions/cors.py +18 -0
- automation/filter/__init__.py +19 -0
- automation/iad/__init__.py +3 -0
- automation/iad/frozen_data.py +54 -0
- automation/iad/out_of_range.py +51 -0
- automation/iad/outliers.py +51 -0
- automation/logger/__init__.py +0 -0
- automation/logger/alarms.py +426 -0
- automation/logger/core.py +265 -0
- automation/logger/datalogger.py +646 -0
- automation/logger/events.py +194 -0
- automation/logger/logdict.py +53 -0
- automation/logger/logs.py +203 -0
- automation/logger/machines.py +248 -0
- automation/logger/opcua_server.py +130 -0
- automation/logger/users.py +96 -0
- automation/managers/__init__.py +4 -0
- automation/managers/alarms.py +455 -0
- automation/managers/db.py +328 -0
- automation/managers/opcua_client.py +186 -0
- automation/managers/state_machine.py +183 -0
- automation/models.py +174 -0
- automation/modules/__init__.py +14 -0
- automation/modules/alarms/__init__.py +0 -0
- automation/modules/alarms/resources/__init__.py +10 -0
- automation/modules/alarms/resources/alarms.py +280 -0
- automation/modules/alarms/resources/summary.py +79 -0
- automation/modules/events/__init__.py +0 -0
- automation/modules/events/resources/__init__.py +10 -0
- automation/modules/events/resources/events.py +83 -0
- automation/modules/events/resources/logs.py +109 -0
- automation/modules/tags/__init__.py +0 -0
- automation/modules/tags/resources/__init__.py +8 -0
- automation/modules/tags/resources/tags.py +201 -0
- automation/modules/users/__init__.py +2 -0
- automation/modules/users/resources/__init__.py +10 -0
- automation/modules/users/resources/models/__init__.py +2 -0
- automation/modules/users/resources/models/roles.py +5 -0
- automation/modules/users/resources/models/users.py +14 -0
- automation/modules/users/resources/roles.py +38 -0
- automation/modules/users/resources/users.py +113 -0
- automation/modules/users/roles.py +121 -0
- automation/modules/users/users.py +335 -0
- automation/opcua/__init__.py +1 -0
- automation/opcua/models.py +541 -0
- automation/opcua/subscription.py +259 -0
- automation/pages/__init__.py +0 -0
- automation/pages/alarms.py +34 -0
- automation/pages/alarms_history.py +21 -0
- automation/pages/assets/styles.css +7 -0
- automation/pages/callbacks/__init__.py +28 -0
- automation/pages/callbacks/alarms.py +218 -0
- automation/pages/callbacks/alarms_summary.py +20 -0
- automation/pages/callbacks/db.py +222 -0
- automation/pages/callbacks/filter.py +238 -0
- automation/pages/callbacks/machines.py +29 -0
- automation/pages/callbacks/machines_detailed.py +581 -0
- automation/pages/callbacks/opcua.py +266 -0
- automation/pages/callbacks/opcua_server.py +244 -0
- automation/pages/callbacks/tags.py +495 -0
- automation/pages/callbacks/trends.py +119 -0
- automation/pages/communications.py +129 -0
- automation/pages/components/__init__.py +123 -0
- automation/pages/components/alarms.py +151 -0
- automation/pages/components/alarms_summary.py +45 -0
- automation/pages/components/database.py +128 -0
- automation/pages/components/gaussian_filter.py +69 -0
- automation/pages/components/machines.py +396 -0
- automation/pages/components/opcua.py +384 -0
- automation/pages/components/opcua_server.py +53 -0
- automation/pages/components/tags.py +253 -0
- automation/pages/components/trends.py +66 -0
- automation/pages/database.py +26 -0
- automation/pages/filter.py +55 -0
- automation/pages/machines.py +20 -0
- automation/pages/machines_detailed.py +41 -0
- automation/pages/main.py +63 -0
- automation/pages/opcua_server.py +28 -0
- automation/pages/tags.py +40 -0
- automation/pages/trends.py +35 -0
- automation/singleton.py +30 -0
- automation/state_machine.py +1672 -0
- automation/tags/__init__.py +2 -0
- automation/tags/cvt.py +1198 -0
- automation/tags/filter.py +55 -0
- automation/tags/tag.py +418 -0
- automation/tests/__init__.py +10 -0
- automation/tests/test_alarms.py +110 -0
- automation/tests/test_core.py +257 -0
- automation/tests/test_unit.py +21 -0
- automation/tests/test_user.py +155 -0
- automation/utils/__init__.py +164 -0
- automation/utils/decorators.py +222 -0
- automation/utils/npw.py +294 -0
- automation/utils/observer.py +21 -0
- automation/utils/units.py +118 -0
- automation/variables/__init__.py +55 -0
- automation/variables/adimentional.py +30 -0
- automation/variables/current.py +71 -0
- automation/variables/density.py +115 -0
- automation/variables/eng_time.py +68 -0
- automation/variables/force.py +90 -0
- automation/variables/length.py +104 -0
- automation/variables/mass.py +80 -0
- automation/variables/mass_flow.py +101 -0
- automation/variables/percentage.py +30 -0
- automation/variables/power.py +113 -0
- automation/variables/pressure.py +93 -0
- automation/variables/temperature.py +168 -0
- automation/variables/volume.py +70 -0
- automation/variables/volumetric_flow.py +100 -0
- automation/workers/__init__.py +2 -0
- automation/workers/logger.py +164 -0
- automation/workers/state_machine.py +207 -0
- automation/workers/worker.py +36 -0
- pyautomationio-0.0.0.dist-info/METADATA +198 -0
- pyautomationio-0.0.0.dist-info/RECORD +138 -0
- pyautomationio-0.0.0.dist-info/WHEEL +5 -0
- pyautomationio-0.0.0.dist-info/licenses/LICENSE +21 -0
- pyautomationio-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/events.py
|
|
3
|
+
"""
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from ..dbmodels.events import Events
|
|
6
|
+
from ..modules.users.users import User
|
|
7
|
+
from .core import BaseEngine, BaseLogger
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class EventsLogger(BaseLogger):
|
|
11
|
+
|
|
12
|
+
def __init__(self):
|
|
13
|
+
|
|
14
|
+
super(EventsLogger, self).__init__()
|
|
15
|
+
|
|
16
|
+
def create(
|
|
17
|
+
self,
|
|
18
|
+
message:str,
|
|
19
|
+
user:User,
|
|
20
|
+
description:str=None,
|
|
21
|
+
classification:str=None,
|
|
22
|
+
priority:int=None,
|
|
23
|
+
criticity:int=None,
|
|
24
|
+
timestamp:datetime=None
|
|
25
|
+
):
|
|
26
|
+
r"""
|
|
27
|
+
Documentation here
|
|
28
|
+
"""
|
|
29
|
+
if not self.is_history_logged:
|
|
30
|
+
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
if not self.check_connectivity():
|
|
34
|
+
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
return Events.create(
|
|
38
|
+
message=message,
|
|
39
|
+
user=user,
|
|
40
|
+
description=description,
|
|
41
|
+
classification=classification,
|
|
42
|
+
priority=priority,
|
|
43
|
+
criticity=criticity,
|
|
44
|
+
timestamp=timestamp
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def get_lasts(self, lasts:int=1):
|
|
48
|
+
r"""
|
|
49
|
+
Documentation here
|
|
50
|
+
"""
|
|
51
|
+
if not self.is_history_logged:
|
|
52
|
+
|
|
53
|
+
return list()
|
|
54
|
+
|
|
55
|
+
if not self.check_connectivity():
|
|
56
|
+
|
|
57
|
+
return list()
|
|
58
|
+
|
|
59
|
+
return Events.read_lasts(lasts=lasts)
|
|
60
|
+
|
|
61
|
+
def filter_by(
|
|
62
|
+
self,
|
|
63
|
+
usernames:list[str]=None,
|
|
64
|
+
priorities:list[int]=None,
|
|
65
|
+
criticities:list[int]=None,
|
|
66
|
+
message:str="",
|
|
67
|
+
description:str="",
|
|
68
|
+
classification:str="",
|
|
69
|
+
greater_than_timestamp:datetime=None,
|
|
70
|
+
less_than_timestamp:datetime=None,
|
|
71
|
+
timezone:str="UTC"
|
|
72
|
+
):
|
|
73
|
+
r"""
|
|
74
|
+
Documentation here
|
|
75
|
+
"""
|
|
76
|
+
if not self.is_history_logged:
|
|
77
|
+
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
if not self.check_connectivity():
|
|
81
|
+
|
|
82
|
+
return list()
|
|
83
|
+
|
|
84
|
+
return Events.filter_by(
|
|
85
|
+
usernames=usernames,
|
|
86
|
+
priorities=priorities,
|
|
87
|
+
criticities=criticities,
|
|
88
|
+
message=message,
|
|
89
|
+
classification=classification,
|
|
90
|
+
description=description,
|
|
91
|
+
greater_than_timestamp=greater_than_timestamp,
|
|
92
|
+
less_than_timestamp=less_than_timestamp,
|
|
93
|
+
timezone=timezone
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def get_summary(self)->tuple[list, str]:
|
|
97
|
+
r"""
|
|
98
|
+
Documentation here
|
|
99
|
+
"""
|
|
100
|
+
if not self.is_history_logged:
|
|
101
|
+
|
|
102
|
+
return None
|
|
103
|
+
|
|
104
|
+
if not self.check_connectivity():
|
|
105
|
+
|
|
106
|
+
return list()
|
|
107
|
+
|
|
108
|
+
return Events.serialize()
|
|
109
|
+
|
|
110
|
+
class EventsLoggerEngine(BaseEngine):
|
|
111
|
+
r"""
|
|
112
|
+
Data logger Engine class for Tag thread-safe database logging.
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def __init__(self):
|
|
117
|
+
|
|
118
|
+
super(EventsLoggerEngine, self).__init__()
|
|
119
|
+
self.logger = EventsLogger()
|
|
120
|
+
|
|
121
|
+
def create(
|
|
122
|
+
self,
|
|
123
|
+
message:str,
|
|
124
|
+
user:User,
|
|
125
|
+
description:str=None,
|
|
126
|
+
classification:str=None,
|
|
127
|
+
priority:int=None,
|
|
128
|
+
criticity:int=None,
|
|
129
|
+
timestamp:datetime=None
|
|
130
|
+
):
|
|
131
|
+
|
|
132
|
+
_query = dict()
|
|
133
|
+
_query["action"] = "create"
|
|
134
|
+
_query["parameters"] = dict()
|
|
135
|
+
_query["parameters"]["message"] = message
|
|
136
|
+
_query["parameters"]["user"] = user
|
|
137
|
+
_query["parameters"]["description"] = description
|
|
138
|
+
_query["parameters"]["classification"] = classification
|
|
139
|
+
_query["parameters"]["priority"] = priority
|
|
140
|
+
_query["parameters"]["criticity"] = criticity
|
|
141
|
+
_query["parameters"]["timestamp"] = timestamp
|
|
142
|
+
|
|
143
|
+
return self.query(_query)
|
|
144
|
+
|
|
145
|
+
def get_lasts(
|
|
146
|
+
self,
|
|
147
|
+
lasts:int=1
|
|
148
|
+
):
|
|
149
|
+
|
|
150
|
+
_query = dict()
|
|
151
|
+
_query["action"] = "get_lasts"
|
|
152
|
+
_query["parameters"] = dict()
|
|
153
|
+
_query["parameters"]["lasts"] = lasts
|
|
154
|
+
|
|
155
|
+
return self.query(_query)
|
|
156
|
+
|
|
157
|
+
def filter_by(
|
|
158
|
+
self,
|
|
159
|
+
usernames:list[str]=None,
|
|
160
|
+
priorities:list[int]=None,
|
|
161
|
+
criticities:list[int]=None,
|
|
162
|
+
message:str="",
|
|
163
|
+
classification:str="",
|
|
164
|
+
description:str="",
|
|
165
|
+
greater_than_timestamp:datetime=None,
|
|
166
|
+
less_than_timestamp:datetime=None,
|
|
167
|
+
timezone:str='UTC'
|
|
168
|
+
):
|
|
169
|
+
|
|
170
|
+
_query = dict()
|
|
171
|
+
_query["action"] = "filter_by"
|
|
172
|
+
_query["parameters"] = dict()
|
|
173
|
+
_query["parameters"]["usernames"] = usernames
|
|
174
|
+
_query["parameters"]["priorities"] = priorities
|
|
175
|
+
_query["parameters"]["criticities"] = criticities
|
|
176
|
+
_query["parameters"]["message"] = message
|
|
177
|
+
_query["parameters"]["classification"] = classification
|
|
178
|
+
_query["parameters"]["description"] = description
|
|
179
|
+
_query["parameters"]["greater_than_timestamp"] = greater_than_timestamp
|
|
180
|
+
_query["parameters"]["less_than_timestamp"] = less_than_timestamp
|
|
181
|
+
_query["parameters"]["timezone"] = timezone
|
|
182
|
+
|
|
183
|
+
return self.query(_query)
|
|
184
|
+
|
|
185
|
+
def get_summary(self):
|
|
186
|
+
r"""
|
|
187
|
+
Documentation here
|
|
188
|
+
"""
|
|
189
|
+
_query = dict()
|
|
190
|
+
_query["action"] = "get_summary"
|
|
191
|
+
_query["parameters"] = dict()
|
|
192
|
+
|
|
193
|
+
return self.query(_query)
|
|
194
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/logdict.py
|
|
3
|
+
|
|
4
|
+
This module implements a dictionary based Class to hold
|
|
5
|
+
the tags to be logged.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LogTable(dict):
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
def validate(self, period, tag):
|
|
16
|
+
|
|
17
|
+
if not type(period) in [int, float]:
|
|
18
|
+
return False
|
|
19
|
+
|
|
20
|
+
if type(tag) != str:
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
return True
|
|
24
|
+
|
|
25
|
+
def get_groups(self):
|
|
26
|
+
|
|
27
|
+
return list(self.keys())
|
|
28
|
+
|
|
29
|
+
def get_tags(self, group):
|
|
30
|
+
|
|
31
|
+
return self[group]
|
|
32
|
+
|
|
33
|
+
def get_all_tags(self):
|
|
34
|
+
|
|
35
|
+
result = list()
|
|
36
|
+
|
|
37
|
+
for group in self.get_groups():
|
|
38
|
+
|
|
39
|
+
result += self.get_tags(group)
|
|
40
|
+
|
|
41
|
+
return result
|
|
42
|
+
|
|
43
|
+
def get_period(self, tag):
|
|
44
|
+
|
|
45
|
+
for key, value in self.items():
|
|
46
|
+
|
|
47
|
+
if tag in value:
|
|
48
|
+
return key
|
|
49
|
+
|
|
50
|
+
def serialize(self):
|
|
51
|
+
|
|
52
|
+
return self
|
|
53
|
+
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/events.py
|
|
3
|
+
"""
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from ..dbmodels.logs import Logs
|
|
6
|
+
from ..modules.users.users import User
|
|
7
|
+
from .core import BaseEngine, BaseLogger
|
|
8
|
+
from ..utils.decorators import db_rollback
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LogsLogger(BaseLogger):
|
|
12
|
+
|
|
13
|
+
def __init__(self):
|
|
14
|
+
|
|
15
|
+
super(LogsLogger, self).__init__()
|
|
16
|
+
|
|
17
|
+
@db_rollback
|
|
18
|
+
def create(
|
|
19
|
+
self,
|
|
20
|
+
message:str,
|
|
21
|
+
user:User,
|
|
22
|
+
description:str=None,
|
|
23
|
+
classification:str=None,
|
|
24
|
+
alarm_summary_id:int=None,
|
|
25
|
+
event_id:int=None,
|
|
26
|
+
timestamp:datetime=None
|
|
27
|
+
):
|
|
28
|
+
r"""
|
|
29
|
+
Documentation here
|
|
30
|
+
"""
|
|
31
|
+
if not self.is_history_logged:
|
|
32
|
+
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
if not self.check_connectivity():
|
|
36
|
+
|
|
37
|
+
return list()
|
|
38
|
+
|
|
39
|
+
query, message = Logs.create(
|
|
40
|
+
message=message,
|
|
41
|
+
user=user,
|
|
42
|
+
description=description,
|
|
43
|
+
classification=classification,
|
|
44
|
+
alarm_summary_id=alarm_summary_id,
|
|
45
|
+
event_id=event_id,
|
|
46
|
+
timestamp=timestamp
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return query, message
|
|
50
|
+
|
|
51
|
+
@db_rollback
|
|
52
|
+
def get_lasts(self, lasts:int=1):
|
|
53
|
+
r"""
|
|
54
|
+
Documentation here
|
|
55
|
+
"""
|
|
56
|
+
if not self.is_history_logged:
|
|
57
|
+
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
if not self.check_connectivity():
|
|
61
|
+
|
|
62
|
+
return list()
|
|
63
|
+
|
|
64
|
+
return Logs.read_lasts(lasts=lasts)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@db_rollback
|
|
68
|
+
def filter_by(
|
|
69
|
+
self,
|
|
70
|
+
usernames:list[str]=None,
|
|
71
|
+
alarm_names:list[str]=None,
|
|
72
|
+
event_ids:list[int]=None,
|
|
73
|
+
classification:str="",
|
|
74
|
+
message:str="",
|
|
75
|
+
description:str="",
|
|
76
|
+
greater_than_timestamp:datetime=None,
|
|
77
|
+
less_than_timestamp:datetime=None,
|
|
78
|
+
timezone:str='UTC'
|
|
79
|
+
):
|
|
80
|
+
r"""
|
|
81
|
+
Documentation here
|
|
82
|
+
"""
|
|
83
|
+
if not self.is_history_logged:
|
|
84
|
+
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
if not self.check_connectivity():
|
|
88
|
+
|
|
89
|
+
return list()
|
|
90
|
+
|
|
91
|
+
return Logs.filter_by(
|
|
92
|
+
usernames=usernames,
|
|
93
|
+
alarm_names=alarm_names,
|
|
94
|
+
event_ids=event_ids,
|
|
95
|
+
message=message,
|
|
96
|
+
description=description,
|
|
97
|
+
classification=classification,
|
|
98
|
+
greater_than_timestamp=greater_than_timestamp,
|
|
99
|
+
less_than_timestamp=less_than_timestamp,
|
|
100
|
+
timezone=timezone
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
@db_rollback
|
|
104
|
+
def get_summary(self)->tuple[list, str]:
|
|
105
|
+
r"""
|
|
106
|
+
Documentation here
|
|
107
|
+
"""
|
|
108
|
+
if not self.is_history_logged:
|
|
109
|
+
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
if not self.check_connectivity():
|
|
113
|
+
|
|
114
|
+
return list()
|
|
115
|
+
|
|
116
|
+
return Logs.serialize()
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class LogsLoggerEngine(BaseEngine):
|
|
120
|
+
r"""
|
|
121
|
+
Operation Logs logger Engine class for Tag thread-safe database logging.
|
|
122
|
+
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
def __init__(self):
|
|
126
|
+
|
|
127
|
+
super(LogsLoggerEngine, self).__init__()
|
|
128
|
+
self.logger = LogsLogger()
|
|
129
|
+
|
|
130
|
+
def create(
|
|
131
|
+
self,
|
|
132
|
+
message:str,
|
|
133
|
+
user:User,
|
|
134
|
+
description:str=None,
|
|
135
|
+
classification:str=None,
|
|
136
|
+
alarm_summary_id:int=None,
|
|
137
|
+
event_id:int=None,
|
|
138
|
+
timestamp:datetime=None
|
|
139
|
+
):
|
|
140
|
+
|
|
141
|
+
_query = dict()
|
|
142
|
+
_query["action"] = "create"
|
|
143
|
+
_query["parameters"] = dict()
|
|
144
|
+
_query["parameters"]["message"] = message
|
|
145
|
+
_query["parameters"]["user"] = user
|
|
146
|
+
_query["parameters"]["description"] = description
|
|
147
|
+
_query["parameters"]["classification"] = classification
|
|
148
|
+
_query["parameters"]["alarm_summary_id"] = alarm_summary_id
|
|
149
|
+
_query["parameters"]["event_id"] = event_id
|
|
150
|
+
_query["parameters"]["timestamp"] = timestamp
|
|
151
|
+
|
|
152
|
+
return self.query(_query)
|
|
153
|
+
|
|
154
|
+
def get_lasts(
|
|
155
|
+
self,
|
|
156
|
+
lasts:int=1
|
|
157
|
+
):
|
|
158
|
+
|
|
159
|
+
_query = dict()
|
|
160
|
+
_query["action"] = "get_lasts"
|
|
161
|
+
_query["parameters"] = dict()
|
|
162
|
+
_query["parameters"]["lasts"] = lasts
|
|
163
|
+
|
|
164
|
+
return self.query(_query)
|
|
165
|
+
|
|
166
|
+
def filter_by(
|
|
167
|
+
self,
|
|
168
|
+
usernames:list[str]=None,
|
|
169
|
+
alarm_names:list[str]=None,
|
|
170
|
+
event_ids:list[int]=None,
|
|
171
|
+
classification:str="",
|
|
172
|
+
message:str="",
|
|
173
|
+
description:str="",
|
|
174
|
+
greater_than_timestamp:datetime=None,
|
|
175
|
+
less_than_timestamp:datetime=None,
|
|
176
|
+
timezone:str='UTC'
|
|
177
|
+
):
|
|
178
|
+
|
|
179
|
+
_query = dict()
|
|
180
|
+
_query["action"] = "filter_by"
|
|
181
|
+
_query["parameters"] = dict()
|
|
182
|
+
_query["parameters"]["usernames"] = usernames
|
|
183
|
+
_query["parameters"]["alarm_names"] = alarm_names
|
|
184
|
+
_query["parameters"]["event_ids"] = event_ids
|
|
185
|
+
_query["parameters"]["classification"] = classification
|
|
186
|
+
_query["parameters"]["message"] = message
|
|
187
|
+
_query["parameters"]["description"] = description
|
|
188
|
+
_query["parameters"]["greater_than_timestamp"] = greater_than_timestamp
|
|
189
|
+
_query["parameters"]["less_than_timestamp"] = less_than_timestamp
|
|
190
|
+
_query["parameters"]["timezone"] = timezone
|
|
191
|
+
|
|
192
|
+
return self.query(_query)
|
|
193
|
+
|
|
194
|
+
def get_summary(self):
|
|
195
|
+
r"""
|
|
196
|
+
Documentation here
|
|
197
|
+
"""
|
|
198
|
+
_query = dict()
|
|
199
|
+
_query["action"] = "get_summary"
|
|
200
|
+
_query["parameters"] = dict()
|
|
201
|
+
|
|
202
|
+
return self.query(_query)
|
|
203
|
+
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""pyhades/logger/machines.py
|
|
3
|
+
"""
|
|
4
|
+
from ..dbmodels import Machines, TagsMachines, Tags
|
|
5
|
+
from .core import BaseEngine, BaseLogger
|
|
6
|
+
from ..utils.decorators import db_rollback
|
|
7
|
+
from ..models import IntegerType, StringType, FloatType
|
|
8
|
+
from ..tags.tag import Tag
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class MachinesLogger(BaseLogger):
|
|
12
|
+
|
|
13
|
+
def __init__(self):
|
|
14
|
+
|
|
15
|
+
super(MachinesLogger, self).__init__()
|
|
16
|
+
|
|
17
|
+
@db_rollback
|
|
18
|
+
def create(
|
|
19
|
+
self,
|
|
20
|
+
identifier:str,
|
|
21
|
+
name:str,
|
|
22
|
+
interval:int,
|
|
23
|
+
description:str,
|
|
24
|
+
classification:str,
|
|
25
|
+
buffer_size:int,
|
|
26
|
+
buffer_roll_type:str,
|
|
27
|
+
criticity:int,
|
|
28
|
+
priority:int,
|
|
29
|
+
on_delay:int=None,
|
|
30
|
+
threshold:float=None
|
|
31
|
+
):
|
|
32
|
+
r"""
|
|
33
|
+
Documentation here
|
|
34
|
+
"""
|
|
35
|
+
if not self.check_connectivity():
|
|
36
|
+
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
if hasattr(threshold, "value"):
|
|
40
|
+
|
|
41
|
+
threshold = threshold.value
|
|
42
|
+
|
|
43
|
+
Machines.create(
|
|
44
|
+
identifier=identifier,
|
|
45
|
+
name=name,
|
|
46
|
+
interval=interval,
|
|
47
|
+
description=description,
|
|
48
|
+
classification=classification,
|
|
49
|
+
buffer_size=buffer_size,
|
|
50
|
+
buffer_roll_type=buffer_roll_type,
|
|
51
|
+
criticity=criticity,
|
|
52
|
+
priority=priority,
|
|
53
|
+
on_delay=on_delay,
|
|
54
|
+
threshold=threshold
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
@db_rollback
|
|
58
|
+
def put(
|
|
59
|
+
self,
|
|
60
|
+
name:StringType,
|
|
61
|
+
machine_interval:IntegerType=None,
|
|
62
|
+
description:StringType=None,
|
|
63
|
+
classification:StringType=None,
|
|
64
|
+
buffer_size:IntegerType=None,
|
|
65
|
+
buffer_roll_type:StringType=None,
|
|
66
|
+
criticity:IntegerType=None,
|
|
67
|
+
priority:IntegerType=None,
|
|
68
|
+
on_delay:IntegerType=None,
|
|
69
|
+
threshold:FloatType=None
|
|
70
|
+
):
|
|
71
|
+
|
|
72
|
+
if not self.check_connectivity():
|
|
73
|
+
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
fields = dict()
|
|
77
|
+
machine = Machines.read_by_name(name=name.value)
|
|
78
|
+
if machine_interval:
|
|
79
|
+
|
|
80
|
+
fields["interval"] = machine_interval.value
|
|
81
|
+
if description:
|
|
82
|
+
fields["description"] = description.value
|
|
83
|
+
if classification:
|
|
84
|
+
fields["classification"] = classification.value
|
|
85
|
+
if buffer_size:
|
|
86
|
+
fields["buffer_size"] = buffer_size.value
|
|
87
|
+
if buffer_roll_type:
|
|
88
|
+
fields["buffer_roll_type"] = buffer_roll_type.value
|
|
89
|
+
if criticity:
|
|
90
|
+
fields["criticity"] = criticity.value
|
|
91
|
+
if priority:
|
|
92
|
+
fields["priority"] = priority.value
|
|
93
|
+
if on_delay:
|
|
94
|
+
fields["on_delay"] = on_delay.value
|
|
95
|
+
if threshold:
|
|
96
|
+
if hasattr(threshold.value, "value"):
|
|
97
|
+
threshold.value = threshold.value.value
|
|
98
|
+
fields["threshold"] = threshold.value
|
|
99
|
+
|
|
100
|
+
query = Machines.put(
|
|
101
|
+
id=machine.id,
|
|
102
|
+
**fields
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
return query
|
|
106
|
+
|
|
107
|
+
@db_rollback
|
|
108
|
+
def read_all(self):
|
|
109
|
+
if not self.check_connectivity():
|
|
110
|
+
|
|
111
|
+
return list()
|
|
112
|
+
|
|
113
|
+
return Machines.read_all()
|
|
114
|
+
|
|
115
|
+
@db_rollback
|
|
116
|
+
def read_config(self):
|
|
117
|
+
if not self.check_connectivity():
|
|
118
|
+
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
return Machines.read_config()
|
|
122
|
+
|
|
123
|
+
@db_rollback
|
|
124
|
+
def bind_tag(self, tag:Tag, machine, default_tag_name:str=None):
|
|
125
|
+
if not self.check_connectivity():
|
|
126
|
+
|
|
127
|
+
return None
|
|
128
|
+
|
|
129
|
+
TagsMachines.create(tag_name=tag.name, machine_name=machine.name.value, default_tag_name=default_tag_name)
|
|
130
|
+
|
|
131
|
+
@db_rollback
|
|
132
|
+
def unbind_tag(self, tag:Tag, machine):
|
|
133
|
+
if not self.check_connectivity():
|
|
134
|
+
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
tag_from_db = Tags.get_or_none(name=tag.name)
|
|
138
|
+
machine_from_db= Machines.get_or_none(name=machine.name.value)
|
|
139
|
+
tags_machine = TagsMachines.get((TagsMachines.tag == tag_from_db) & (TagsMachines.machine == machine_from_db))
|
|
140
|
+
tags_machine.delete_instance()
|
|
141
|
+
|
|
142
|
+
class MachinesLoggerEngine(BaseEngine):
|
|
143
|
+
r"""
|
|
144
|
+
Alarms logger Engine class for Tag thread-safe database logging.
|
|
145
|
+
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
def __init__(self):
|
|
149
|
+
|
|
150
|
+
super(MachinesLoggerEngine, self).__init__()
|
|
151
|
+
self.logger = MachinesLogger()
|
|
152
|
+
|
|
153
|
+
def create(
|
|
154
|
+
self,
|
|
155
|
+
identifier:str,
|
|
156
|
+
name:str,
|
|
157
|
+
interval:int,
|
|
158
|
+
description:str,
|
|
159
|
+
classification:str,
|
|
160
|
+
buffer_size:int,
|
|
161
|
+
buffer_roll_type:str,
|
|
162
|
+
criticity:int,
|
|
163
|
+
priority:int,
|
|
164
|
+
on_delay:int=None,
|
|
165
|
+
threshold:float=None
|
|
166
|
+
):
|
|
167
|
+
|
|
168
|
+
_query = dict()
|
|
169
|
+
_query["action"] = "create"
|
|
170
|
+
_query["parameters"] = dict()
|
|
171
|
+
_query["parameters"]["identifier"] = identifier
|
|
172
|
+
_query["parameters"]["name"] = name
|
|
173
|
+
_query["parameters"]["interval"] = interval
|
|
174
|
+
_query["parameters"]["classification"] = classification
|
|
175
|
+
_query["parameters"]["description"] = description
|
|
176
|
+
_query["parameters"]["buffer_size"] = buffer_size
|
|
177
|
+
_query["parameters"]["buffer_roll_type"] = buffer_roll_type
|
|
178
|
+
_query["parameters"]["criticity"] = criticity
|
|
179
|
+
_query["parameters"]["priority"] = priority
|
|
180
|
+
_query["parameters"]["on_delay"] = on_delay
|
|
181
|
+
_query["parameters"]["threshold"] = threshold
|
|
182
|
+
|
|
183
|
+
return self.query(_query)
|
|
184
|
+
|
|
185
|
+
def put(
|
|
186
|
+
self,
|
|
187
|
+
name:StringType,
|
|
188
|
+
machine_interval:IntegerType=None,
|
|
189
|
+
description:StringType=None,
|
|
190
|
+
classification:StringType=None,
|
|
191
|
+
buffer_size:IntegerType=None,
|
|
192
|
+
buffer_roll_type:StringType=None,
|
|
193
|
+
criticity:IntegerType=None,
|
|
194
|
+
priority:IntegerType=None,
|
|
195
|
+
on_delay:IntegerType=None,
|
|
196
|
+
threshold:FloatType=None
|
|
197
|
+
):
|
|
198
|
+
|
|
199
|
+
_query = dict()
|
|
200
|
+
_query["action"] = "put"
|
|
201
|
+
_query["parameters"] = dict()
|
|
202
|
+
_query["parameters"]["name"] = name
|
|
203
|
+
_query["parameters"]["machine_interval"] = machine_interval
|
|
204
|
+
_query["parameters"]["classification"] = classification
|
|
205
|
+
_query["parameters"]["description"] = description
|
|
206
|
+
_query["parameters"]["buffer_size"] = buffer_size
|
|
207
|
+
_query["parameters"]["buffer_roll_type"] = buffer_roll_type
|
|
208
|
+
_query["parameters"]["criticity"] = criticity
|
|
209
|
+
_query["parameters"]["priority"] = priority
|
|
210
|
+
_query["parameters"]["on_delay"] = on_delay
|
|
211
|
+
_query["parameters"]["threshold"] = threshold
|
|
212
|
+
|
|
213
|
+
return self.query(_query)
|
|
214
|
+
|
|
215
|
+
def read_all(self):
|
|
216
|
+
|
|
217
|
+
_query = dict()
|
|
218
|
+
_query["action"] = "read_all"
|
|
219
|
+
_query["parameters"] = dict()
|
|
220
|
+
return self.query(_query)
|
|
221
|
+
|
|
222
|
+
def read_config(self):
|
|
223
|
+
|
|
224
|
+
_query = dict()
|
|
225
|
+
_query["action"] = "read_config"
|
|
226
|
+
_query["parameters"] = dict()
|
|
227
|
+
return self.query(_query)
|
|
228
|
+
|
|
229
|
+
def bind_tag(self, tag:Tag, machine, default_tag_name:str=None):
|
|
230
|
+
|
|
231
|
+
_query = dict()
|
|
232
|
+
_query["action"] = "bind_tag"
|
|
233
|
+
_query["parameters"] = dict()
|
|
234
|
+
_query["parameters"]["tag"] = tag
|
|
235
|
+
_query["parameters"]["machine"] = machine
|
|
236
|
+
_query["parameters"]["default_tag_name"] = default_tag_name
|
|
237
|
+
return self.query(_query)
|
|
238
|
+
|
|
239
|
+
def unbind_tag(self, tag:Tag, machine):
|
|
240
|
+
|
|
241
|
+
_query = dict()
|
|
242
|
+
_query["action"] = "unbind_tag"
|
|
243
|
+
_query["parameters"] = dict()
|
|
244
|
+
_query["parameters"]["tag"] = tag
|
|
245
|
+
_query["parameters"]["machine"] = machine
|
|
246
|
+
return self.query(_query)
|
|
247
|
+
|
|
248
|
+
|