Skip to content

Commit

Permalink
added events, added portainer for container management
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmas committed Jun 6, 2022
1 parent d526ee9 commit 33494c1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 20 deletions.
47 changes: 30 additions & 17 deletions client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def remove_listener(point):


###############################################
### Schema ###

@socketio.on('schema_addItems', namespace='')
def add_to_schema_database(data):
Expand Down Expand Up @@ -220,6 +221,8 @@ def remove_from_gis_database(uuid):

db = mongoclient.scada
db.gis_objects.delete_one({'_id':ObjectId(uuid[1:])})

#TEST! TODO remove
new_alarm_check("iec60870-5-104://127.0.0.1:2404/MeasuredValueScaled/101",
alert_id = 1, # alert id within this datapoint
logic = ">", # logic to apply to value
Expand Down Expand Up @@ -610,7 +613,7 @@ def influxdb_get_value(point):
###############################################################
###############################################################
###############################################################

### Alarm logic ###

def update_alarms(key, value):
global alarm_list
Expand Down Expand Up @@ -713,20 +716,6 @@ def trigger_alarm(key, alarm, value):
return


def publish_event(element,msg,value):
# IFS: rtu connect/discoonect (with additional values for substsation/bay info if available)
# main: db's up/down, client connect/disconnect(not page refresh, but new session cookie)
# operate/select/cancel command and result (of action, and actual process)
# alarms trigger
el = json.dumps(element)
print("element: %s, message: %s, value: %s" % (el, msg, str(value)))
# add event item @ influxdb
global influxdb_write_api
p = Point("event").tag("element", el).field("message", msg).field("value", str(value))
influxdb_write_api.write(bucket="bucket_2", record=p)
socketio.emit('add_event_to_table', {'element':element, 'message':msg, 'value':value})


def new_alarm_check(datapoint,
alert_id = 1, # alert id within this datapoint
logic = ">", # logic to apply to value
Expand Down Expand Up @@ -837,6 +826,10 @@ def lower_alarm(datapoint, alert_id):
def get_alarm_table(data):
global alarm_list
global mongoclient

# event test
#publish_event("element_1","alarm set closed","jaja") # test

if mongoclient == None:
logger.error("no mongodb connection")
return {}
Expand Down Expand Up @@ -898,20 +891,40 @@ def get_alarm_logic(clear=True):
alarm_list[datapoint]['alarm_logic_list'].append(alarm)


### Event logic ###
def publish_event(element,msg,value):
# IFS: rtu connect/discoonect (with additional values for substsation/bay info if available)
# main: db's up/down, client connect/disconnect(not page refresh, but new session cookie)
# operate/select/cancel command and result (of action, and actual process)
# alarms trigger
el = json.dumps(element)
print("element: %s, message: %s, value: %s" % (el, msg, str(value)))
# add event item @ influxdb
global influxdb_write_api
p = Point("event").tag("element", el).field("message", msg).field("value", str(value))
influxdb_write_api.write(bucket="bucket_2", record=p)
socketio.emit('add_event_to_table', {'element':element, 'message':msg, 'value':value})


@socketio.on('get_event_table', namespace='')
def get_event_table(param):
# retrieve events from influxdb
global influxdb_query_api
# query influxdb for possible update
query = ' from(bucket:"bucket_2")\
|> range(start: 0) '
|> range(start: 0)\
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") '

data = []
result = influxdb_query_api.query(org="scada", query=query)
if result and len(result) > 0:
for table in result:
for record in table.records:
data.append(record.get_value())
timestmp = str(record.values["_time"])
elem = str(record.values["element"])
msg = str(record.values["message"]) #str(record.values["_field"])
val = str(record.values["value"]) #str(record.values["_value"])
data.append({"time":timestmp, "element":elem, "msg": msg, "value": val})

socketio.emit('update_event_table', data)

Expand Down
25 changes: 22 additions & 3 deletions client/static/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function init_alarm(){
//data:tabledata, //load row data from array
layout:"fitColumns", //fit columns to width of table
responsiveLayout:"hide", //hide columns that dont fit on the table
tooltips:true, //show tool tips on cells
//tooltips:true, //show tool tips on cells
addRowPos:"top", //when adding a new row, add it to the top of the table
history:true, //allow undo and redo actions on the table
pagination:"local", //paginate the data
Expand All @@ -82,7 +82,7 @@ function init_alarm(){
movableColumns:true, //allow column order to be changed
resizableRows:true, //allow row order to be changed
initialSort:[ //set the initial sort order of the data
{column:"Time", dir:"asc"},
{column:"time", dir:"asc"},
],
columns:[ //define the table columns
{title:"Time", field:"time",hozAlign:"center", formatter:"plaintext"},
Expand All @@ -100,7 +100,7 @@ function init_alarm(){

//table.setFilter("open", "=", "true");
table.on("rowClick", function(e, row){
//alert("Row " + row.getIndex() + " Clicked!!!!")
alert("Row " + row.getIndex() + " Clicked!!!!") //test
let row_element = row.getElement();
//acknowledge alarm/close alarm
table.refreshFilter();
Expand Down Expand Up @@ -131,6 +131,25 @@ function init_events(){

var table = new Tabulator("#mmi_svg", {
autoColumns:true, //create columns from data field names
//data:tabledata, //load row data from array
layout:"fitColumns", //fit columns to width of table
responsiveLayout:"hide", //hide columns that dont fit on the table
//tooltips:true, //show tool tips on cells
addRowPos:"top", //when adding a new row, add it to the top of the table
pagination:"local", //paginate the data
paginationSize:7, //allow 7 rows per page of data
paginationCounter:"rows", //display count of paginated rows in footer
movableColumns:true, //allow column order to be changed
resizableRows:true, //allow row order to be changed
initialSort:[ //set the initial sort order of the data
{column:"time", dir:"asc"},
],
columns:[ //define the table columns
{title:"Time", field:"time",hozAlign:"center", formatter:"plaintext"},
{title:"Element", field:"element", hozAlign:"left", formatter:"plaintext"},
{title:"Message", field:"msg", hozAlign:"left", formatter:"textarea"},
{title:"Value", field:"value", hozAlign:"left", formatter:"plaintext"},
],
});

refresh_event_table();
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ services:
# Data persistency
# sudo mkdir -p /srv/docker/influxdb/data
- /srv/docker/influxdb/data:/var/lib/influxdb
#USER = admin, PASSWORD = administrator

# timeseries dashboard
grafana:
Expand All @@ -117,3 +118,17 @@ services:
# sudo mkdir -p /srv/docker/grafana/data; chown 472:472 /srv/docker/grafana/data
- /srv/docker/grafana/data:/var/lib/grafana

# manage containers, password is Administrator
portainer:
image: portainer/portainer-ce
container_name: portainer
ports:
- "8000:8000"
- "9443:9443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- portainer_data:/data

volumes:
portainer_data:

4 changes: 4 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ top-bar location indication

event/alarm schermen:
> alarm/ack/close op datapoint, click to go to location, from alarm-window
script fire on alarm logic
> event van acties op alarm/ack/close event van IFS(connectie/disconnect, add/remove datapoint)
scaling values in IFS (before storage)
scaling values in GUI (only on display)


grafana dashboard voor trending datapunten?

Expand Down

0 comments on commit 33494c1

Please sign in to comment.