def send_state_change_notification(self): """ Send an SaNtfStateChangeNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ # Create the notification notification = saNtf.SaNtfStateChangeNotificationT() rc = ntf.saNtfStateChangeNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), len(self.ntf_info.state_changes), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfStateChangeNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in the notification notification.sourceIndicator.contents.value = \ self.ntf_info.source_indicator for i, state_change in enumerate(self.ntf_info.state_changes): ptr = notification.changedStates[i] ptr.stateId = state_change.state_id ptr.newState = state_change.new_state if state_change.old_state_present: ptr.oldStatePresent = eSaBoolT.SA_TRUE ptr.oldState = state_change.old_state else: ptr.oldStatePresent = eSaBoolT.SA_FALSE # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: init_rc = self.init() # If the re-initialization of agent handle succeeds, we still need # to return BAD_HANDLE to the function decorator, so that it would # re-try the failed operation. Otherwise, the true error code is # returned to the user to decide further actions. if init_rc != eSaAisErrorT.SA_AIS_OK: rc = init_rc return rc
def send_object_create_delete_notification(self): """ Send an SaNtfObjectCreateDeleteNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ # Create the notification notification = saNtf.SaNtfObjectCreateDeleteNotificationT() rc = ntf.saNtfObjectCreateDeleteNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), len(self.ntf_info.object_attributes), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfObjectCreateDeleteNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in the notification notification.sourceIndicator.contents.value = \ self.ntf_info.source_indicator for i, attribute in enumerate(self.ntf_info.object_attributes): ptr = notification.objectAttributes[i] ptr.attributeId = attribute.attribute_id ptr.attributeType = attribute.attribute_type self._assign_ntf_value(notification.notificationHandle, ptr.attributeValue, attribute.attribute_value, attribute.attribute_type) # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: init_rc = self.init() # If the re-initialization of agent handle succeeds, we still need # to return BAD_HANDLE to the function decorator, so that it would # re-try the failed operation. Otherwise, the true error code is # returned to the user to decide further actions. if init_rc != eSaAisErrorT.SA_AIS_OK: rc = init_rc return rc
def send_security_alarm_notification(self): """ Send an SaNtfSecurityAlarmNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ notification = saNtf.SaNtfSecurityAlarmNotificationT() rc = ntf.saNtfSecurityAlarmNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfSecurityAlarmNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in security alarm-specific fields notification.probableCause.contents.value = \ self.ntf_info.probable_cause notification.severity.contents.value = self.ntf_info.severity if self.ntf_info.security_alarm_detector is not None: notification.securityAlarmDetector.contents.valueType = \ self.ntf_info.security_alarm_detector.value_type self._assign_ntf_value( notification.notificationHandle, notification.securityAlarmDetector.contents.value, self.ntf_info.security_alarm_detector.value, self.ntf_info.security_alarm_detector.value_type) if self.ntf_info.service_user is not None: notification.serviceUser.contents.valueType = \ self.ntf_info.service_user.value_type self._assign_ntf_value(notification.notificationHandle, notification.serviceUser.contents.value, self.ntf_info.service_user.value, self.ntf_info.service_user.value_type) if self.ntf_info.service_provider is not None: notification.serviceProvider.contents.valueType = \ self.ntf_info.service_provider.value_type self._assign_ntf_value( notification.notificationHandle, notification.serviceProvider.contents.value, self.ntf_info.service_provider.value, self.ntf_info.service_provider.value_type) # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: init_rc = self.init() # If the re-initialization of agent handle succeeds, we still need # to return BAD_HANDLE to the function decorator, so that it would # re-try the failed operation. Otherwise, the true error code is # returned to the user to decide further actions. if init_rc != eSaAisErrorT.SA_AIS_OK: rc = init_rc return rc
def send_alarm_notification(self): """ Send an SaNtfAlarmNotificationT notification Returns: SaAisErrorT: Return code of the corresponding NTF API call(s) """ # Create the notification notification = saNtf.SaNtfAlarmNotificationT() rc = ntf.saNtfAlarmNotificationAllocate( self.handle, notification, 0, len(self.ntf_info.additional_text) + 1, len(self.ntf_info.additional_info), len(self.ntf_info.specific_problems), len(self.ntf_info.monitored_attrs), len(self.ntf_info.proposed_repair_actions), saNtf.saNtf.SA_NTF_ALLOC_SYSTEM_LIMIT) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfAlarmNotificationAllocate FAILED, " "rc = %s" % eSaAisErrorT.whatis(rc)) else: # Fill in the header self._fill_in_header(notification.notificationHandle, notification.notificationHeader) # Fill in the notification notification.probableCause.contents.value = \ self.ntf_info.probable_cause notification.perceivedSeverity.contents.value = \ self.ntf_info.perceived_severity if self.ntf_info.trend is not None: notification.trend.contents.value = self.ntf_info.trend for i, problem in enumerate(self.ntf_info.specific_problems): ptr = notification.specificProblems[i] ptr.problemId = problem.problem_id if problem.problem_class_id is not None: prob_class_id = problem.problem_class_id ptr.problemClassId.vendorId = prob_class_id.vendorId ptr.problemClassId.majorId = prob_class_id.majorId ptr.problemClassId.minorId = prob_class_id.minorId ptr.problemType = problem.problem_type self._assign_ntf_value(notification.notificationHandle, ptr.problemValue, problem.problem_value, problem.problem_type) if self.ntf_info.threshold_information is not None: ptr = notification.thresholdInformation.contents ptr.thresholdId = \ self.ntf_info.threshold_information.threshold_id ptr.thresholdValueType = \ self.ntf_info.threshold_information.threshold_value_type self._assign_ntf_value( notification.notificationHandle, ptr.thresholdValue, self.ntf_info.threshold_information.threshold_value, ptr.thresholdValueType) self._assign_ntf_value( notification.notificationHandle, ptr.thresholdHysteresis, self.ntf_info.threshold_information.threshold_hysteresis, ptr.thresholdValueType) self._assign_ntf_value( notification.notificationHandle, ptr.observedValue, self.ntf_info.threshold_information.observed_value, ptr.thresholdValueType) ptr.armTime = self.ntf_info.threshold_information.arm_time for i, attribute in enumerate(self.ntf_info.monitored_attrs): ptr = notification.monitoredAttributes[i] ptr.attributeId = attribute.attribute_id ptr.attributeType = attribute.attribute_type self._assign_ntf_value(notification.notificationHandle, ptr.attributeValue, attribute.attribute_value, attribute.attribute_type) for i, action in enumerate(self.ntf_info.proposed_repair_actions): ptr = notification.proposedRepairActions[i] ptr.actionId = action.action_id ptr.actionValueType = action.action_value_type self._assign_ntf_value(notification.notificationHandle, ptr.actionValue, action.action_value, action.action_value_type) # Send the notification rc = ntf.saNtfNotificationSend(notification.notificationHandle) if rc != eSaAisErrorT.SA_AIS_OK: log_err("saNtfNotificationSend FAILED, rc = %s" % eSaAisErrorT.whatis(rc)) # Free the notification ntf.saNtfNotificationFree(notification.notificationHandle) if rc == eSaAisErrorT.SA_AIS_ERR_BAD_HANDLE: init_rc = self.init() # If the re-initialization of agent handle succeeds, we still need # to return BAD_HANDLE to the function decorator, so that it would # re-try the failed operation. Otherwise, the true error code is # returned to the user to decide further actions. if init_rc != eSaAisErrorT.SA_AIS_OK: rc = init_rc return rc
def _ntf_notif_callback(self, c_subscription_id, c_notif): """ This callback is invoked by NTF to deliver a notification to a subscriber of that notification type. Args: c_subscription_id (SaNtfSubscriptionIdT): The subscription id previously provided by the subscriber when subscribing for this type of notification c_notif (SaNtfNotificationsT): The notification delivered by this callback """ if not self.ntf_notif_function: return subscription_id = c_subscription_id notification_type = c_notif.contents.notificationType if notification_type == \ saNtf.eSaNtfNotificationTypeT.SA_NTF_TYPE_OBJECT_CREATE_DELETE: notification = \ c_notif.contents.notification.objectCreateDeleteNotification ntf_handle = notification.notificationHandle ntf_header = notification.notificationHeader ntf_info = self._parse_notification_header(ntf_handle, ntf_header) self._parse_object_create_delete_ntf(notification, ntf_info) elif notification_type == \ saNtf.eSaNtfNotificationTypeT.SA_NTF_TYPE_ATTRIBUTE_CHANGE: notification = \ c_notif.contents.notification.attributeChangeNotification ntf_handle = notification.notificationHandle ntf_header = notification.notificationHeader ntf_info = self._parse_notification_header(ntf_handle, ntf_header) self._parse_attribute_change_ntf(notification, ntf_info) elif notification_type == \ saNtf.eSaNtfNotificationTypeT.SA_NTF_TYPE_STATE_CHANGE: notification = \ c_notif.contents.notification.stateChangeNotification ntf_handle = notification.notificationHandle ntf_header = notification.notificationHeader ntf_info = self._parse_notification_header(ntf_handle, ntf_header) self._parse_state_change_ntf(notification, ntf_info) elif notification_type == \ saNtf.eSaNtfNotificationTypeT.SA_NTF_TYPE_ALARM: notification = c_notif.contents.notification.alarmNotification ntf_handle = notification.notificationHandle ntf_header = notification.notificationHeader ntf_info = self._parse_notification_header(ntf_handle, ntf_header) self._parse_alarm_ntf(notification, ntf_info) elif notification_type == \ saNtf.eSaNtfNotificationTypeT.SA_NTF_TYPE_SECURITY_ALARM: notification = \ c_notif.contents.notification.securityAlarmNotification ntf_handle = notification.notificationHandle ntf_header = notification.notificationHeader ntf_info = self._parse_notification_header(ntf_handle, ntf_header) self._parse_security_alarm_ntf(notification, ntf_info) else: return # Make a deep copy of the parsed notification for use after freeing it ntf_info_copy = deepcopy(ntf_info) # Send the ntf info to user's callback function self.ntf_notif_function(subscription_id, notification_type, ntf_info_copy) # Free the notification after parsing for needed information ntf.saNtfNotificationFree(notification.notificationHandle)