Custom alarm roster does not send

you probably saw this one coming...

if i use a pre-built roster with a Direct contact type, emails get sent on alarm as expected. we need to filter alarm emails on a per-asset basis, so i whipped up the following script, which generates the correct object for the email engine:

users = system.user.getUsers('TurboUsers') #<-- blank = default user source
currentAsset = str({displayPath})
alarmEmailList = []

for user in users:
  userRoles = user.getRoles()
  username = user.get('username')
  if ('spanky' in userRoles) and user.getContactInfo():
    userContactInfo = str(user.getContactInfo()[0])
    # gives 'email: floop@doop.ca'.  yes.  a string.
    if 'email' in userContactInfo:
      emailEntry = {}
      if userFunctions.singleUserFunctions.canUserDo(currentAsset, username, 'isNotified'):
        userEmail = userContactInfo.replace('email: ', '')
        emailEntry['username'] = username					
        emailEntry['email'] = [userEmail]
        alarmEmailList.append(emailEntry)

return alarmEmailList

so this will generate and return a list of dicts, as expected and required:

[
  { 'email': 'floop@doop.ca', 'username': 'floop' },
  { 'email': 'spang@glarn.io', 'username': 'spang' }
]

emails will not be sent.

so i tried modifying it based on an old working script:

      alarmEmailList.append(userEmail)
alarmRoster = { 'email': [alarmEmailList] }
return [alarmRoster]

emails do not get sent.

so, in a fit of pique, i hardcoded the damn thing:

return [{ 'email': ['floop@doop.ca', 'spang@glarn.io']}]

emails do not send.

can someone determine what i am missing? for all i can deduce, this builds the correct structure and returns it. several times. but it flat out does not send anything. the last one is the one that really stumped me: hardcoded = nothing. whut the :fork_and_knife:?

Anything in the logs ?

nothing. that's what's also got me banjaxxed. flailing in the dark... :stuck_out_tongue:

soooo, i threw out ALL my assumptions and just started commenting :poop: out. turns out, the culprit is the currentAsset = str({displayPath}). at this point the script is tanking. according to co-worker, this should yeild the asset's name. but i don't trust that (becuase is isn't working), so i'm trying to find out if [.] will work as a more accurate standin that actually works.

EDIT: by standin, i mean to capture the asset name that is generating the alarm.

EDIT2: i'm now trying to figure out how to get the asset name... trying this: system.tag.readBlocking('[.].name')... keep you posted. where the heck are the docs on this kind of thing? seems something that should be in the Notification docs somewhere...

I'm pretty confident you want event.displayPath (which should autocomplete...).

Curly braces would be the syntax to reference a local property in an expression. In scripts, you have to use dictionary style access to access arbitrary properties of the event object, but the core/builtin ones are exposed as getters and attributes.

1 Like

i absolutely did and absolutely do! thank you. i went digging through the event docs to find that gem. it would be nice if the docs for Alarms explained the event portion more thoroughly OR added a link to the Event doc page. trying to debug scripts from that alarm script window is a bear..

1 Like