Skip to content

Commit

Permalink
Fixing report db (#82)
Browse files Browse the repository at this point in the history
* fixed agent parameter handling, fixes to UI for rule gen

* updated to latest commit

* adding back service to wants

---------

Co-authored-by: linkodm1 <[email protected]>
  • Loading branch information
d-linko and linkodm1 authored Jun 20, 2024
1 parent 6de48c4 commit 082b43e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 14 deletions.
20 changes: 17 additions & 3 deletions anms-core/anms/routes/ARIs/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sqlalchemy import select, and_
from sqlalchemy.engine import Result
import re
from datetime import datetime

from anms.components.schemas import ARIs
from anms.models.relational import get_async_session, get_session
Expand Down Expand Up @@ -132,7 +133,7 @@ async def report_ac(agent_id: str, adm: str, report_name: str):
ac_id = result.one_or_none()

# get AC
ac_names = []
ac_names = ["time"]
ac_types_and_id = []
ac_stmt = select(ARICollection).where(ARICollection.ac_id == ac_id).order_by(ARICollection.order_num)
async with get_async_session() as session:
Expand All @@ -147,7 +148,10 @@ async def report_ac(agent_id: str, adm: str, report_name: str):

ac_names.append(curr_name)
ac_types_and_id.append((entry.data_type_id, entry.obj_metadata_id))

# unknown template
if ac_names == []:
ac_names = ["time","string_values", "uint_values", "int_values", "real32_values", "real64_values", "uvast_values","vast_values"]

stmt = select(Report).where(Report.agent_id == agent_id , Report.ADM == adm_name
, Report.report_name == report_name)
# find the type of ari
Expand All @@ -160,6 +164,8 @@ async def report_ac(agent_id: str, adm: str, report_name: str):

for entry in entries:
curr_values = []
time = datetime.fromtimestamp(int(entry.time)).strftime('%Y-%m-%d %H:%M:%S')

string_values = list(filter(None, re.split(r",|'(.*?)'", entry.string_values))) if entry.string_values else []
uint_values = entry.uint_values.split(',') if entry.uint_values else []
int_values = entry.int_values.split(',') if entry.int_values else []
Expand All @@ -169,14 +175,22 @@ async def report_ac(agent_id: str, adm: str, report_name: str):
vast_values = entry.vast_values.split(',') if entry.vast_values else []
value_matchup = {18: string_values, 19: int_values, 20: uint_values, 21: vast_values, 22: uvast_values,
23: real32_values, 24: real64_values}

curr_values.append(time)
for type_id, obj_id in ac_types_and_id:
if type_id in type_matchup:
curr_type = await type_matchup[type_id](obj_id)
else:
curr_type = type_id
if value_matchup[curr_type]:
curr_values.append(value_matchup[curr_type].pop(0))
if ac_types_and_id is []:
curr_values.append(','.join(string_values))
curr_values.append(','.join(uint_values))
curr_values.append(','.join(int_values))
curr_values.append(','.join(real32_values))
curr_values.append(','.join(real64_values))
curr_values.append(','.join(uvast_values))
curr_values.append(','.join(vast_values))

final_values.append(curr_values)

Expand Down
33 changes: 33 additions & 0 deletions anms-core/anms/shared/ace_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,37 @@ def get_adms():
if not hasattr(LOCALDATA, 'adms'):
LOCALDATA.adms = ace.AdmSet(cache_dir=False)
LOCALDATA.adms.load_default_dirs()
_adm_reload(None)
return LOCALDATA.adms


def _adm_reload(adm_name):
with get_session() as db_conn:
if adm_name:
LOGGER.info('Reloading one ADM: %s', adm_name)
curs = db_conn.execute('''\
SELECT adm.adm_name, adm_data.updated_at, adm_data.data
FROM adm_data
INNER JOIN adm ON adm_data.adm_enum = adm.adm_enum
WHERE adm_name = ?
''', [adm_name])
for row in curs.all():
_handle_adm(*row)

else:
LOGGER.info('Reloading all ADMS...')

curs = db_conn.execute('''\
SELECT adm.adm_name, adm_data.updated_at, adm_data.data
FROM adm_data
INNER JOIN adm ON adm_data.adm_enum = adm.adm_enum
''')
for row in curs.all():
_handle_adm(*row)

LOGGER.info('ADMS present for: %s', LOCALDATA.adms.names())

def _handle_adm(adm_name, timestamp, data):
LOGGER.info('Handling ADM: %s', adm_name)
LOCALDATA.adms.load_from_data(io.BytesIO(data))
LOGGER.info('Handling finished')
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
props: ["listComponents", "name", "parms", "type", "index"],
data() {
return {
expressionReturnTypes: ["BYTE", "INT", "UINT", "VAST", "UVAST", "REAL32", "REAL64", "STRING", "BOOLEAN"],
expressionReturnTypes: ["BYTE", "INT", "UINT", "VAST", "UVAST", "REAL32", "REAL64", "STRING", "BOOL"],
selectedExpressionReturnType: undefined,
expressionList: [],
ariKey: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default {
currValue.push(ari.replaceAll('"', "'"));
});
testResult.push(JSON.stringify(currValue).replaceAll('"', ""));
testResult.push(JSON.stringify(currValue).replaceAll('"', "").replaceAll("'",'"'));
break;
Expand Down Expand Up @@ -224,4 +224,4 @@ export default {
.card.border-grey {
border-color: grey;
}
</style>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
@click="addNewTnvc"><i class="fas fa-plus"></i></b-button>
</b-col>
</b-row>

<b-list-group class="my-2">
<b-list-group-item v-for="(TNVC, index) in TNVCs"
:key="index">
Expand All @@ -57,11 +56,12 @@ export default {
props: ["name", "type", "types", "index"],
data() {
return {
TNVCType: undefined,
TNVCName: undefined,
TNVCValue: undefined,
TNVCType: "",
TNVCName: "",
TNVCValue: "",
final: { "index": this.index, "type": "TNVC", "value": [] },
TNVCs: [],
test: {},
}
},
methods: {
Expand All @@ -77,9 +77,9 @@ export default {
this.$emit("updateResult", this.final);
},
clearInputs() {
this.TNVCType = undefined;
this.TNVCName = undefined;
this.TNVCValue = undefined;
this.TNVCType = "";
this.TNVCName = "";
this.TNVCValue = "";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ion/src
Submodule src updated from 416130 to 7905cc

0 comments on commit 082b43e

Please sign in to comment.