Article Benjamin Thorne · Jul 24, 2018 1m read

Check audit settings programmatically

The following code allows a user to view the audit settings of their instance. Run the code by running the class method "test":


class objectscript.checkAudit Extends %RegisteredObject
{
	classmethod test() {
		w "Checking for Auditing...",!
		Set SYSOBJ = ##class(Security.System).%OpenId("SYSTEM")
		If +SYSOBJ = 0 Set SYSOBJ = ##class(Security.System).%New()
		i SYSOBJ.AuditEnabled {
			w "Security Auditing is enabled for the following services",!
			s rs=##class(%ResultSet).%New("Security.Events:ListAllSystem")
			s sc=rs.Execute()  If $$$ISERR(sc) Do DisplayError^%apiOBJ(sc) Quit
			while rs.%Next() {
                d:rs.Data("Enabled")="Yes" rs.%Print()
            }
            d rs.Close()
         
            s rs=##class(%ResultSet).%New("Security.Events:ListAllUser")
            s sc=rs.Execute()  If $$$ISERR(sc) Do DisplayError^%apiOBJ(sc) Quit
            while rs.%Next() {
                d:rs.Data("Enabled")="Yes" rs.%Print()
            }
            d rs.Close()
        }
    }
}	

Here's a link to the code on GitHub: https://github.com/intersystems-community/code-snippets/blob/master/src/cls/objectscript/checkAudit.cls

Comments

John Murray · Jul 24, 2018

It looks like this class is intended to be created in the %SYS namespace so it can use the Security.System class.

Also, be aware that classes you create in %SYS typically don't survive a Cache / Ensemble / HealthShare upgrade.

0