Skip to content

Commit 19ace35

Browse files
committed
FEAT: add audit system
Audit mechanism is simple the globals holding the runtime date each time when elements are called
1 parent 3564bd0 commit 19ace35

File tree

1 file changed

+139
-4
lines changed

1 file changed

+139
-4
lines changed

MDX2JSON/Utils.cls

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ ClassMethod WriteJSONfromMDX(MDX As %String, Timeout As %Integer = 0) As %Status
6060
Set tSC = $$$OK
6161
#dim RS As MDX2JSON.ResultSet
6262

63+
set start = $PIECE($NOW(),",",2)
64+
6365
set RS = ..GetResultSet(MDX, .tSC)
6466
set cube = ##class(%DeepSee.Utils).%IsCubeCompound(RS.%Cube) // check if cube is compound type
6567
return:$$$ISERR(tSC) tSC
@@ -87,6 +89,14 @@ ClassMethod WriteJSONfromMDX(MDX As %String, Timeout As %Integer = 0) As %Status
8789
return:$$$ISERR(tSC) tSC
8890
$$$DynObjToJSON(obj)
8991
}
92+
93+
set stop = $PIECE($NOW(),",",2)
94+
95+
set executionTime = stop - start
96+
set query = RS.%GetQuery()
97+
98+
set audit = ..WriteAudit(MDX, "query", executionTime)
99+
90100
return $$$OK
91101
}
92102

@@ -108,7 +118,6 @@ ClassMethod WriteJSONfromQuery(CubeKey As %String, QueryKey As %String, Timeout
108118
return $$$OK
109119
}
110120

111-
112121
/// Execute SQL query taken from KPI and extract column values by name of column
113122
/// Output array with list of values like so pValue(n) = $LB(sNameList(i)...)
114123
ClassMethod GetSQLValues(pSQL, Output pValues As %String, Output tResultSet As %SQL.Statement) As %Status
@@ -133,7 +142,6 @@ ClassMethod GetSQLValues(pSQL, Output pValues As %String, Output tResultSet As %
133142
return st
134143
}
135144

136-
137145
/// This method provides listing execution for KPI.
138146
/// <b>tKPI<b> as a name of KPI class. <b>pFilters<b> not yet implemented
139147
/// as a <b>pSelection<b>. Thats for future use.
@@ -309,7 +317,8 @@ ClassMethod GetDataSource(pDataSource As %String)
309317

310318
set st = $$$OK
311319
try {
312-
320+
set start = $PIECE($NOW(),",",2)
321+
313322
if ($FIND(pDataSource, ".pivot") = ($LENGTH(pDataSource) + 1) && pDataSource '="") {
314323
set st = ..OpenPivotByName(pDataSource, .dataSource)
315324
return:($$$ISERR(st)) st
@@ -320,8 +329,16 @@ ClassMethod GetDataSource(pDataSource As %String)
320329
set dataSource.mdx = mdx
321330
}
322331
set st = ##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(dataSource, .out)
332+
333+
set stop = $PIECE($NOW(),",",2)
334+
335+
set executionTime = stop - start
336+
337+
set audit = ..WriteAudit(pDataSource, "pivot", executionTime)
338+
323339

324340
}
341+
325342

326343
} catch ex {
327344
set st = ex.AsStatus()
@@ -409,12 +426,22 @@ ClassMethod GetWidgetsList(pDashName As %String) As %Status
409426
ClassMethod GetDashboard(pDashName As %String) As %Status
410427
{
411428
try {
429+
set start = $PIECE($NOW(),",",2)
430+
412431
set st = ##class(MDX2JSON.DashboardFilters).OpenDashboardByName(pDashName, .dash)
413432
return:($$$ISERR(st)) st
414433

415434
set st = ##class(MDX2JSON.DashboardFilters).WidgetsToProxyObject(dash, .widgetlist)
416435
return:($$$ISERR(st)) st
417436
w "" // weird hack required for 15.3
437+
438+
set stop = $PIECE($NOW(),",",2)
439+
440+
set executionTime = stop - start
441+
442+
set audit = ..WriteAudit(pDashName, "dashboard", executionTime)
443+
444+
418445
$$$DynObjToJSON(widgetlist)
419446
} catch ex {
420447
set st = ex.AsStatus()
@@ -557,6 +584,115 @@ ClassMethod CreateAddonClass(Class As %Dictionary.CacheClassname) As %Status
557584
quit classObj.%Save()
558585
}
559586

587+
ClassMethod WriteAudit(element, elementName, executionTime = 0) As %Status
588+
{
589+
set st = $$$OK
590+
591+
set ^CallAmount($INCREMENT(^CallAmount)) = 1
592+
593+
594+
if ^AuditState = "on"
595+
{
596+
if elementName = "dashboard"
597+
{
598+
set ^MyBIAuditLogDash($INCREMENT(^MyBIAuditLogDash)) = $lb($ZDT($H,3), $USERNAME, element, executionTime)
599+
}
600+
elseif elementName = "pivot"
601+
{
602+
set ^MyBIAuditLogPivot($INCREMENT(^MyBIAuditLogPivot)) = $lb($ZDT($H,3), $USERNAME, element, executionTime)
603+
}
604+
elseif elementName = "query"
605+
{
606+
set ^MyBIAuditLogQuery($INCREMENT(^MyBIAuditLogQuery)) = $lb($ZDT($H,3), $USERNAME, element, executionTime)
607+
}
608+
609+
610+
}else{
611+
612+
quit st
613+
}
614+
615+
616+
return st
617+
}
618+
619+
ClassMethod ReadAudit(metricName) As %Status
620+
{
621+
set st = $$$OK
622+
623+
if ^AuditState = "on"
624+
{
625+
if metricName = "query"
626+
{
627+
628+
set len = $order(^MyBIAuditLogQuery(""),-1)
629+
for n=1:1:len
630+
{
631+
set log = $Get(^MyBIAuditLogQuery(n))
632+
write !
633+
write "Element call time: ", $lg(log, 1), !
634+
write "User: ", $lg(log, 2), !
635+
write "Execution time in sec.: ", $lg(log, 4), !
636+
write "Query: ", $lg(log, 3), !
637+
}
638+
}
639+
elseif metricName = "pivot"
640+
{
641+
642+
set len = $order(^MyBIAuditLogPivot(""),-1)
643+
for n=1:1:len
644+
{
645+
set log = $Get(^MyBIAuditLogPivot(n))
646+
write !
647+
write "Element call time: ", $lg(log, 1), !
648+
write "User: ", $lg(log, 2), !
649+
write "Execution time in sec.: ", $lg(log, 4), !
650+
write "Pivot: ", $lg(log, 3), !
651+
}
652+
}
653+
elseif metricName = "dashboard"
654+
{
655+
set len = $order(^MyBIAuditLogDash(""),-1)
656+
for n=1:1:len
657+
{
658+
set log = $Get(^MyBIAuditLogDash(n))
659+
write !
660+
write "Element call time: ", $lg(log, 1), !
661+
write "User: ", $lg(log, 2), !
662+
write "Execution time in sec.: ", $lg(log, 4), !
663+
write "Dashboard: ", $lg(log, 3), !
664+
}
665+
}
666+
}
667+
668+
quit st
669+
}
670+
671+
ClassMethod AuditStateSwitch(auditstate = 0) As %Status
672+
{
673+
set st = $$$OK
674+
675+
if auditstate = 0
676+
{
677+
set ^AuditState = "off"
678+
679+
}else{
680+
681+
set ^AuditState = "on"
682+
}
683+
684+
write "Audit state: " _ ^AuditState
685+
}
686+
687+
ClassMethod AuditKill() As %Status
688+
{
689+
kill ^MyBIAuditLogDash
690+
kill ^MyBIAuditLogPivot
691+
kill ^MyBIAuditLogQuery
692+
693+
write "All globals are cleaned"
694+
}
695+
560696
/// Add new widgets and edit existing ones directly from DeepSeeWeb
561697
/// it takes widget name(key) as unique identifier as string, dashboard name as string
562698
/// and object with parameters as zen.proxyObject
@@ -672,7 +808,6 @@ ClassMethod DeleteWidget(wName As %String, sDashboard As %String) As %Status
672808
return st
673809
}
674810

675-
676811
/// the collection of necessary parameters for building widget
677812
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject) As %Status
678813
{

0 commit comments

Comments
 (0)