Code Examples.
Code Examples.
Alarm library life cycle functions
This section include two function which are used to initialize and finalize the alarm client library. These are as follows:
If the component is managing a resource having alarms, the IDE generated code takes care that alarm lib initialization is done via Execution object (EO) infrastructure. But if user wants to call them saperately he/she can call them as follows.
}
ClRcT clAlarmLibInitialize()
Initializes the Alarm Library.
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
Finalizes the alarm management library.
}
ClRcT clAlarmLibFinalize()
Cleans up the Alarm Library.
Alarm Reporting
The alarm client library implements a function which is used both to raise and clear the alarms. One of the element of the ClAlarmInfoT structure passed to this function decides whether that alarm is going to be raised or cleared. The function call that is used to raise/clear is:
The information about the alarm being asserted or cleared is filled in the instance of ClAlarmInfoT structure. The information includes the resource identifier (MOId), probable cause, category and severity of the alarm and the state of the alarm that is whether it is being asserted or cleared. After processing the appropriate value of the alarm, the handle is filled in the "pAlarmHandle" by the alarm client based on the alarm configuration.
This example also describes about attaching payload with the alarm and retrieving it in the event receive callback.
{
ClCharT usrBuffer [] = "This is just an example of string buffer";
ClUint32T size = 0;
return rc;
}
return rc;
}
return rc;
}
return rc;
}
size = strlen(usrBuffer) + 1;
if (NULL == pAlarmInfo) {
}
memcpy(pAlarmInfo->
buff, usrBuffer, size);
return rc;
}
}
ClUint32T ClAlarmHandleT
The type of the handle for identifying the raised alarm.
Definition: clAlarmDefinitions.h:131
ClRcT clAlarmRaise(CL_IN ClAlarmInfoT *pAlarmInfo, CL_OUT ClAlarmHandleT *pAlarmHandle)
Raises an alarm on a component.
@ CL_ALARM_PROB_CAUSE_LOSS_OF_SIGNAL
Probable cause for alarms which can occur due to communication related problems between two points.
Definition: clAlarmDefinitions.h:202
@ CL_ALARM_STATE_ASSERT
The alarm condition has occured.
Definition: clAlarmDefinitions.h:521
@ CL_ALARM_CATEGORY_COMMUNICATIONS
Category for alarms that are related to communication between to points.
Definition: clAlarmDefinitions.h:91
#define CL_ERR_NULL_POINTER
Input parameter is a NULL pointer.
Definition: clCommonErrors.h:83
ClRcT clCorMoIdInitialize(CL_INOUT ClCorMOIdPtrT pMoId)
Initializes a MOID or resets the content of an existing MOID.
ClRcT clCorMoIdAppend(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClCorClassTypeT type, CL_IN ClCorInstanceIdT instance)
Adds an entry to the MoId.
ClRcT clCorMoIdServiceSet(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClCorMOServiceIdT svc)
Sets the service ID.
@ CL_COR_SVC_ID_ALARM_MANAGEMENT
OpenClovis Alarm Agent.
Definition: clCorServiceId.h:74
ClRcT clCpmComponentNameGet(CL_IN ClCpmHandleT cpmHandle, CL_OUT ClNameT *pCompName)
Returns the component name.
ClHandleT ClCpmHandleT
The type of the handle supplied by the CPM to the process which calls the clCpmClientInitialize() API...
Definition: clCpmApi.h:124
void clHeapFree(CL_IN ClPtrT pAddress)
Frees a pre-allocated memory.
ClPtrT clHeapAllocate(CL_IN ClUint32T size)
Allocates memory of the requested size.
The ClAlarmInfoT data structure is used to store the entire list of alarm attributes that include pro...
Definition: clAlarmDefinitions.h:544
ClAlarmCategoryTypeT category
Category of the alarm.
Definition: clAlarmDefinitions.h:571
ClUint32T len
Length of the additional data about the alarm.
Definition: clAlarmDefinitions.h:592
ClAlarmSpecificProblemT specificProblem
Specific-Problem of the alarm.
Definition: clAlarmDefinitions.h:577
ClCorMOIdT moId
Resource on which the alarm occurred.
Definition: clAlarmDefinitions.h:558
ClUint8T buff[1]
Additional information about the alarm.
Definition: clAlarmDefinitions.h:597
ClAlarmStateT alarmState
Flag to indicate if the alarm was for assert or for clear.
Definition: clAlarmDefinitions.h:566
ClAlarmProbableCauseT probCause
Probable cause of the alarm.
Definition: clAlarmDefinitions.h:548
ClNameT compName
Component name of the resource on which the alarm occurred.
Definition: clAlarmDefinitions.h:553
The structure ClCorMOId contains MoId of the object, which is the address of the COR object.
Definition: clCorMetaData.h:918
Alarm Event Subscribe
The alarm server publishes event for every successfully reported alarm. The event is published on the global event channel, so component running on any other node can receive the event published on a node. For getting the event, the component has to subscribe for them. This can be done via calling the function:
The function takes a callback function as a parameter. The callback function takes pointer to the structure ClAlarmHandleInfoT as parameter. This structure contains information about the alarm which is being published. The callback function is called for every event published by the alarm server. The usage example is as follows:
{
clprintf(
CL_LOG_SEV_INFO,
"The alarm handle of the alarm which is published [%d]",
{
return rc;
}
{
}
else
{
}
}
ClRcT _clAlarmEventSubscribeTest() {
}
}
ClRcT clAlarmEventSubscribe(CL_IN const ClAlarmEventCallbackFuncPtrT pAlarmEvtCallbackFuncFP)
This function is used to subscribe for the events published by the alarm server.
ClRcT clCorMoIdToMoIdNameGet(CL_IN ClCorMOIdT *moId, CL_OUT ClNameT *moIdName)
Retrieves MoId in ClNameT format, when MoId is provided in ClCorMOIdT format.
@ CL_LOG_SEV_INFO
setting severity as INFORMATION.
Definition: clLogApi.h:280
A name.
Definition: clCommon.h:197
ClCharT value[CL_MAX_NAME_LENGTH]
Actual name represented as a null terminated ASCII string.
Definition: clCommon.h:201
ClAlarmSeverityTypeT severity
Severity of the alarm.
Definition: clAlarmDefinitions.h:582
The ClAlarmHandleInfoT data structure is used to store the handle and the information of the alarm.
Definition: clAlarmDefinitions.h:612
ClAlarmHandleT alarmHandle
Unique alarm handle identifying an alarm.
Definition: clAlarmDefinitions.h:616
ClAlarmInfoT alarmInfo
Alarm Information.
Definition: clAlarmDefinitions.h:620
Alarm Event Unsubscribe
The function is used to unsubscribe for the events published by the alarm server for which the subscription was done earlier using clAlarmEventSubscribe. After the event unsubscribe is done, the callback function registered using the alarm event subscribe function would not be called for any further event publish from the alarm server.
ClRcT _clAlarmEventUnsubscribeTest() {
}
return rc;
}
ClRcT clAlarmEventUnsubscribe()
This function is used to unsubscribe for the events published by the alarm server.
Packing payload information to be used by SNMP subagent
This example describes about attaching payload with the alarm which is used by the SNMP subagent for reporting the traps. The payload information that need to be given in the trap has to be given in the proper format as explained in the usage example. After providing the details, using clAlarmUtilPayloadFlatten() function, this can be converted into flat buffer and passed on to the alarm raise function. The alarm server will raise the event for this alarm and the payload information given with the alarm will be delivered to the alarm event-listener. For generating traps, the SNMP subagent listens for this event and extracts the payload information and sends the trap to the management station.
The usage example providing the payload information understood by the SNMP subagent and raising the alarm is as follows:
{
ClUint32T size = 0;
ClUint8T* pBuf = NULL;
ClCharT usrBuffer[] = "This is just an example of string buffer";
return rc;
}
return rc;
}
return rc;
}
return rc;
}
size = strlen(usrBuffer) + 1;
if (pAlarmPayload == NULL) {
}
}
usrBuffer, size);
return rc;
}
if (NULL == pAlarmInfo) {
}
memcpy(pAlarmInfo->
buff, pBuf, size);
return rc;
}
}
ClRcT clAlarmUtilPayloadFlatten(ClAlarmUtilPayLoadListPtrT pPayLoadList, ClUint32T *pSize, ClUint8T **ppBuf)
Function to convert the payload information into a flat buffer.
void clAlarmUtilPayloadBufFree(ClUint8T *pBuf)
The function to free the buffer obtained after flattening the payload information.
#define CL_ALARM_ERR_NO_MEMORY
There is no memory left with the application.
Definition: clAlarmErrors.h:159
#define CL_ALARM_RC(ERROR_CODE)
It appends the component ID with the error code.
Definition: clAlarmErrors.h:149
void clAlarmUtilPayloadListFree(ClAlarmUtilPayLoadListT *pPayloadList)
Function used to free the payload data-structure allocated during alarm reporting or receive.
ClRcT clCorMoIdClone(ClCorMOIdPtrT pMoId, ClCorMOIdPtrT *newH)
Clones a particular MOId.
@ CL_COR_UINT8
Unsigned character.
Definition: clCorMetaData.h:250
The structure is used to store the information about the variables to be used in the trap.
Definition: clAlarmUtils.h:62
ClUint32T length
Number of bytes the attribute would hold.
Definition: clAlarmUtils.h:74
ClCorTypeT type
Data type of the attribute.
Definition: clAlarmUtils.h:67
ClPtrT value
Value of the attribute.
Definition: clAlarmUtils.h:80
This structure holds the information about the attributes that need to be provided in the alarm paylo...
Definition: clAlarmUtils.h:124
ClUint32T numTlvs
Number of attribute information needed for the trap generation on resource.
Definition: clAlarmUtils.h:135
ClAlarmUtilTlvPtrT pTlv
Pointer to the structure containing attribute information.
Definition: clAlarmUtils.h:141
ClCorMOIdPtrT pMoId
The pointer to the MOID of the resource.
Definition: clAlarmUtils.h:130
The stucture is used to specify the alarm payload information.
Definition: clAlarmUtils.h:156
ClAlarmUtilPayLoadPtrT pPayload
Stores the information about the attributes corressponding to a particular resource.
Definition: clAlarmUtils.h:170
ClUint32T numPayLoadEnteries
The number of entries which need to be specified in the alarm payload.
Definition: clAlarmUtils.h:161
Event Delivery callback function which unpacks the payload information published with the alarm.
clprint(
CL_LOG_SEV_INFO,
"The alarm Handle of the alarm which is published [%d] \n",
return rc;
}
clprint(
CL_LOG_SEV_INFO,
"The String passed while raising the alarm : [%s] \n",
}
ClRcT clAlarmUtilPayLoadExtract(ClUint8T *pBuf, ClUint32T size, ClAlarmUtilPayLoadListT **ppPayloadList)
The function to extract the payload information sent at the time of alarm raise.
Alarm Version Verify
This function is used to verify the version of the alarm client library with the version that is supported. For that the user has to fill the version information available with the application. This will be verified against the supported version. In case of mismatch the highest version supported by the client library is updated in the version field.
ClRcT _clAlarmVersionVerifyTest() {
}
return rc;
}
ClRcT clAlarmVersionVerify(CL_INOUT ClVersionT *pVersion)
This function is used to verify if a version of the function is supported by AM.
Version Information for various services.
Definition: clCommon.h:250