1 // : vi ts=4 sw=4 noet :
3 ==================================================================================
4 Copyright (c) 2021 Nokia
5 Copyright (c) 2021 AT&T Intellectual Property.
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 ==================================================================================
22 ------------------------------------------------------------------------------
24 Abstract: The RMR housekeeping thread (route table collection) is also responsible
25 for sending a small number of alarm messages to the alarm system.
26 To avoid extra overhead, the alarm library is NOT included; this
27 module provides the alarm generation support for the housekeeping
30 Date: 19 February 2021
32 Author: E. Scott Daniels
34 ------------------------------------------------------------------------------
37 #ifndef alarm_static_c
38 #define alarm_static_c
50 #include <RIC_message_types.h>
51 #include <rmr_logging.h>
54 extern const char* __progname; // runtime supplies (we have no acccess to argv[0]
57 Generate the endpoint for the arlarm system. We assume that it is defined
58 by two environment variables: ALARM_MGR_SERVICE_NAME and ALARM_MGR_SERVICE_PORT.
59 If the name is not given, we assume 127.0.0.1 (we don't use localhost for
60 to avoid the double meaning within some flavours' hosts files). If the port
61 is not given, we assume the default RMR port of 4560.
63 The string returned must be freed by the caller.
65 static char* uta_alarm_endpt( ) {
66 char wbuf[300]; // enough room for max name of 256 + :port
67 const char* et; // environment token
68 const char* addr = "service-ricplt-alarmmanager-rmr"; // defaults
69 const char* port = "4560";
71 if( (et = getenv( ENV_AM_NAME )) != NULL ) {
75 if( (et = getenv( ENV_AM_PORT )) != NULL ) {
79 wbuf[sizeof(wbuf)-1] = 0; // guarentee it is nil terminated if too long
80 snprintf( wbuf, sizeof( wbuf ) -1, "%s:%s", addr, port );
81 return strdup( wbuf );
85 Send the message as an alarm. We will create a wormhole as we cannot depend
86 on having a routing table that is valid. This send does NOT allocate a new
87 message to return to the caller.
89 static void uta_alarm_send( void* vctx, rmr_mbuf_t* msg ) {
91 static int ok2log = 0; // if we must log to stderr, do it seldomly; this is the next spot in time where logging is ok
96 ept = uta_alarm_endpt();
97 if( (whid = rmr_wh_open( vctx, ept )) < 0 ) {
98 if( (now = time( NULL )) > ok2log ) {
101 rmr_vlog( RMR_VL_WARN, "unable to open wormhole for alarms: %s\n", ept );
105 rmr_vlog( RMR_VL_INFO, "alarm wormhole opened to: %s\n", ept );
110 msg = rmr_wh_send_msg( vctx, whid, msg );
117 Builds an alarm message for the kind of action. Alarm message is palced in
118 the given buffer using the buffer length (blen) to truncate. A convenience
119 pointer to the buffer is returned and will be nil on error.
121 Kind is an ALARM_* constant ANDed with ALARM_RAISE or ALARM_CLEAR.
122 Problem ID (prob_id) is an integer assigned by the caller and should
123 match when calling to clear the alarm.
125 Info is the message text that is added to the alarm; nil terminated string.
127 static void uta_alarm( void* vctx, int kind, int prob_id, char* info ) {
130 char* maction = "CLEAR";
132 if( (msg = rmr_alloc_msg( vctx, 2048 )) == NULL ) {
136 if( kind & ALARM_RAISE ) {
141 info = "unspecific RMR issue";
144 used = snprintf( msg->payload, 2047,
146 "\"managedObjectId\": null, " // there is no object for rmr alarms
147 "\"applicationId\": \"%s\", "
148 "\"specificProblem\": %d, " // problem id
149 "\"perceivedSeverity\": \"WARNING\", " // all RMR messages are warnings
150 "\"identifyingInfo\": \"%s\", "
151 "\"additionalInfo\": null, "
152 "\"AlarmAction\": \"%s\", "
153 "\"AlarmTime\": %lld"
156 __progname, // see comment above
159 maction, // raise/clear
160 mstime() // use logging module's timestamp generator
163 msg->len = strlen( msg->payload );
166 msg->mtype = RIC_ALARM;
167 uta_alarm_send( vctx, msg );