add snapshotslog Ok result

This commit is contained in:
Cayo Puigdefabregas 2022-05-18 18:02:08 +02:00
parent 3d73e1a368
commit b8c97780be
2 changed files with 15 additions and 2 deletions

View File

@ -66,6 +66,7 @@ class InventoryView(LoginMixin, SnapshotMixin):
severity=Severity.Info, severity=Severity.Info,
sid=snapshot.sid, sid=snapshot.sid,
version=snapshot.version, version=snapshot.version,
snapshot=snapshot,
) )
snap_log.save() snap_log.save()

View File

@ -236,10 +236,14 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
schema_lite = Snapshot_lite() schema_lite = Snapshot_lite()
devices = [] devices = []
self.tmp_snapshots = app.config['TMP_SNAPSHOTS'] self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
# import pdb; pdb.set_trace()
for filename, snapshot_json in self.snapshots: for filename, snapshot_json in self.snapshots:
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
snapshot_json.pop('debug', None) snapshot_json.pop('debug', None)
version = snapshot_json.get('schema_api') version = snapshot_json.get('schema_api')
uuid = snapshot_json.get('uuid')
sid = snapshot_json.get('sid')
software_version = snapshot_json.get('version')
if self.is_wb_lite_snapshot(version): if self.is_wb_lite_snapshot(version):
self.snapshot_json = schema_lite.load(snapshot_json) self.snapshot_json = schema_lite.load(snapshot_json)
snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json
@ -248,13 +252,12 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
snapshot_json = schema.load(snapshot_json) snapshot_json = schema.load(snapshot_json)
except ValidationError as err: except ValidationError as err:
txt = "{}".format(err) txt = "{}".format(err)
uuid = snapshot_json.get('uuid')
sid = snapshot_json.get('sid')
error = SnapshotsLog( error = SnapshotsLog(
description=txt, description=txt,
snapshot_uuid=uuid, snapshot_uuid=uuid,
severity=Severity.Error, severity=Severity.Error,
sid=sid, sid=sid,
version=software_version,
) )
error.save(commit=True) error.save(commit=True)
self.result[filename] = 'Error' self.result[filename] = 'Error'
@ -263,6 +266,15 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
response = self.build(snapshot_json) response = self.build(snapshot_json)
db.session.add(response) db.session.add(response)
devices.append(response.device) devices.append(response.device)
snap_log = SnapshotsLog(
description='Ok',
snapshot_uuid=uuid,
severity=Severity.Error,
sid=sid,
version=software_version,
snapshot=response,
)
snap_log.save()
if hasattr(response, 'type'): if hasattr(response, 'type'):
self.result[filename] = 'Ok' self.result[filename] = 'Ok'