# limitations under the License.
# import json
+
import redis
import json
from o2app import bootstrap
from o2common.config import config
-# from o2common.domain import commands
from o2dms.domain import commands
from o2ims.domain import commands as imscmd
+from o2ims.domain.subscription_obj import Message2SMO, RegistrationMessage
+from o2ims.domain.alarm_obj import AlarmEvent2SMO
from o2common.helper import o2logging
-from o2ims.domain.subscription_obj import Message2SMO, NotificationEventEnum, RegistrationMessage
logger = o2logging.get_logger(__name__)
r = redis.Redis(**config.get_redis_host_and_port())
apibase = config.get_o2ims_api_base()
+api_monitoring_base = config.get_o2ims_monitoring_api_base()
def main():
pubsub = r.pubsub(ignore_subscribe_messages=True)
pubsub.subscribe("NfDeploymentStateChanged")
pubsub.subscribe('ResourceChanged')
- pubsub.subscribe('RegistrationChanged')
pubsub.subscribe('OcloudChanged')
+ pubsub.subscribe('AlarmEventChanged')
for m in pubsub.listen():
try:
- handle_dms_changed(m, bus)
+ handle_changed(m, bus)
except Exception as ex:
logger.warning("{}".format(str(ex)))
continue
-def handle_dms_changed(m, bus):
+def handle_changed(m, bus):
logger.info("handling %s", m)
channel = m['channel'].decode("UTF-8")
if channel == "NfDeploymentStateChanged":
eventtype=data['notificationEventType'],
updatetime=data['updatetime']))
bus.handle(cmd)
- elif channel == 'RegistrationChanged':
+ elif channel == 'OcloudChanged':
datastr = m['data']
data = json.loads(datastr)
- logger.info('RegistrationChanged with cmd:{}'.format(data))
- cmd = imscmd.Register2SMO(data=RegistrationMessage(id=data['id']))
+ logger.info('OcloudChanged with cmd:{}'.format(data))
+ cmd = imscmd.Register2SMO(data=RegistrationMessage(
+ data['notificationEventType'],
+ id=data['id']))
bus.handle(cmd)
- elif channel == 'OcloudChanged':
+ elif channel == 'AlarmEventChanged':
datastr = m['data']
data = json.loads(datastr)
- logger.info('OcloudChanged with cmd:{}'.format(data))
- if data['notificationEventType'] == NotificationEventEnum.CREATE:
- cmd = imscmd.Register2SMO(data=RegistrationMessage(is_all=True))
- bus.handle(cmd)
+ logger.info('AlarmEventChanged with cmd:{}'.format(data))
+ ref = api_monitoring_base + '/alarms/' + data['id']
+ cmd = imscmd.PubAlarm2SMO(data=AlarmEvent2SMO(
+ id=data['id'], ref=ref,
+ eventtype=data['notificationEventType'],
+ updatetime=data['updatetime']))
+ bus.handle(cmd)
else:
logger.info("unhandled:{}".format(channel))