I make a actions.json file in a zenpack to create the trigger and notification. But in the triggers I make the attributes(globalManage, globalRead and globalWrite to true). If the zenpack is the first time to install, the permissions(three down) is false. But if it updates the zenpack in the second time, they will be true. Is it a bug in the core coding?
The core coding is as following:
for conf in findFiles(pack, 'zep',lambda f: f == 'actions.json'):
import json
data = json.load(open(conf, "r"))
log.debug("DATA IS: %s" % data)
triggers = data.get('triggers', [])
notifications = data.get('notifications', [])
tf.synchronize()
all_names = set(t['name'] for t in tf.getTriggerList())
for trigger_conf in triggers:
existing_trigger = guidManager.getObject(trigger_conf['uuid'])
if existing_trigger:
trigger_data = tf.getTrigger(trigger_conf['uuid'])
trigger_conf['name'] = trigger_data['name']
log.info('Existing trigger found, updating: %s' % trigger_conf['name'])
tf.updateTrigger(**trigger_conf)
else:
test_name = trigger_conf['name']
for x in xrange(1,101):
if test_name in all_names:
test_name = '%s_%d' % (trigger_conf['name'], x)
else:
log.debug('Found unused trigger name: %s' % test_name)
break
else:
# if we didn't find a unique name
raise Exception('Could not find unique name for trigger: "%s".' % trigger_conf['name'])
log.info('Creating trigger: %s' % test_name)
tf.createTrigger(test_name, uuid=trigger_conf['uuid'], rule=trigger_conf['rule'])
for notification_conf in notifications:
existing_notification = guidManager.getObject(str(notification_conf['guid']))
if existing_notification:
log.info("Existing notification found, updating: %s" % existing_notification.id)
subscriptions = set(existing_notification.subscriptions + notification_conf['subscriptions'])
notification_conf['uid'] = '/zport/dmd/NotificationSubscriptions/%s' % existing_notification.id
notification_conf['subscriptions'] = list(subscriptions)
notification_conf['name'] = existing_notification.id
tf.updateNotification(**notification_conf)
else:
test_id = notification_conf['id']
for x in xrange(1,101):
test_uid = '/zport/dmd/NotificationSubscriptions/%s' % test_id
try:
tf.getNotification(test_uid)
except ObjectNotFoundException:
break
test_id = '%s_%d' % (notification_conf['id'], x)
else:
# if we didn't find a unique name
raise Exception('Could not find unique name for notification: "%s".' % notification_conf['id'])
log.info('Creating notification: %s' % test_id)
tf.createNotification(str(test_id), notification_conf['action'], notification_conf['guid'])
notification_conf['uid'] = '/zport/dmd/NotificationSubscriptions/%s' % test_id
tf.updateNotification(**notification_conf)
Is the trigger short of "updateTrigger" like the notification when the trigger is a new one.
Thank you!
-----
James