Decouple Fault Management from stx-config
Create fault management REST API service Create fault management client and CLI shell Add a python extension for fault management application APIs Update fault management python APIs to use the python extension Update fault manager to retrieve the SNMP configuration from the config file Story: 2002828 Task: 22747 Depends-On: https://review.openstack.org/#/c/592176/ Change-Id: I888d8d23edf75d05d51594ccca55570ae366c848 Signed-off-by: Tao Liu <tao.liu@windriver.com>
This commit is contained in:
parent
7bdf6fd47c
commit
c8159ea6cb
@ -2,5 +2,7 @@ fm-api
|
||||
fm-common
|
||||
fm-mgr
|
||||
fm-doc
|
||||
fm-rest-api
|
||||
python-fmclient
|
||||
snmp-ext
|
||||
snmp-audittrail
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2013-2014 Wind River Systems, Inc.
|
||||
# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
@ -11,9 +11,9 @@
|
||||
#
|
||||
|
||||
import copy
|
||||
import subprocess
|
||||
from . import constants
|
||||
import six
|
||||
import fm_core
|
||||
|
||||
|
||||
class ClientException(Exception):
|
||||
@ -31,8 +31,8 @@ class ClientException(Exception):
|
||||
# on the alarm. Optional.
|
||||
# alarm_type: see ALARM_TYPE
|
||||
# probable_cause: see ALARM_PROBABLE_CAUSE
|
||||
# proposed_repair_action:free-format string providing additional details on how to
|
||||
# clear the alarm. Optional.
|
||||
# proposed_repair_action:free-format string providing additional details on
|
||||
# how to clear the alarm. Optional.
|
||||
# service_affecting: true/false, default to false
|
||||
# suppression: true/false (allowed/not-allowed), default to false
|
||||
# uuid: unique identifier of an active alarm instance, filled by FM system
|
||||
@ -76,67 +76,59 @@ class FaultAPIs(object):
|
||||
self._check_required_attributes(data)
|
||||
self._validate_attributes(data)
|
||||
buff = self._alarm_to_str(data)
|
||||
cmd = constants.FM_CLIENT_SET_FAULT + '"' + buff + '"'
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
if (resp[0] == "Ok") and (len(resp) > 1):
|
||||
return resp[1]
|
||||
else:
|
||||
try:
|
||||
return fm_core.set(buff)
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
return None
|
||||
|
||||
def clear_fault(self, alarm_id, entity_instance_id):
|
||||
sep = constants.FM_CLIENT_STR_SEP
|
||||
buff = (sep + self._check_val(alarm_id) + sep +
|
||||
self._check_val(entity_instance_id) + sep)
|
||||
cmd = constants.FM_CLIENT_CLEAR_FAULT + '"' + buff + '"'
|
||||
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
if resp[0] == "Ok":
|
||||
return True
|
||||
else:
|
||||
try:
|
||||
return fm_core.clear(buff)
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
return False
|
||||
|
||||
def get_fault(self, alarm_id, entity_instance_id):
|
||||
sep = constants.FM_CLIENT_STR_SEP
|
||||
buff = (sep + self._check_val(alarm_id) + sep +
|
||||
self._check_val(entity_instance_id) + sep)
|
||||
cmd = constants.FM_CLIENT_GET_FAULT + '"' + buff + '"'
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
if (resp[0] == "Ok") and (len(resp) > 1):
|
||||
return self._str_to_alarm(resp[1])
|
||||
else:
|
||||
try:
|
||||
resp = fm_core.get(buff)
|
||||
return self._str_to_alarm(resp) if resp else None
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
return None
|
||||
|
||||
def clear_all(self, entity_instance_id):
|
||||
cmd = constants.FM_CLIENT_CLEAR_ALL + '"' + entity_instance_id + '"'
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
if resp[0] == "Ok":
|
||||
return True
|
||||
else:
|
||||
try:
|
||||
return fm_core.clear_all(entity_instance_id)
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
return False
|
||||
|
||||
def get_faults(self, entity_instance_id):
|
||||
cmd = constants.FM_CLIENT_GET_FAULTS + '"' + entity_instance_id + '"'
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
data = []
|
||||
if resp[0] == "Ok":
|
||||
for i in range(1, len(resp)):
|
||||
alarm = self._str_to_alarm(resp[i])
|
||||
data.append(alarm)
|
||||
return data
|
||||
else:
|
||||
return None
|
||||
try:
|
||||
resp = fm_core.get_by_eid(entity_instance_id)
|
||||
if resp is not None:
|
||||
data = []
|
||||
for i in resp:
|
||||
data.append(self._str_to_alarm(i))
|
||||
return data
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
pass
|
||||
return None
|
||||
|
||||
def get_faults_by_id(self, alarm_id):
|
||||
cmd = constants.FM_CLIENT_GET_FAULTS_BY_ID + '"' + alarm_id + '"'
|
||||
resp = self._run_cmd_and_get_resp(cmd)
|
||||
data = []
|
||||
if resp[0] == "Ok":
|
||||
for i in range(1, len(resp)):
|
||||
alarm = self._str_to_alarm(resp[i])
|
||||
data.append(alarm)
|
||||
return data
|
||||
else:
|
||||
return None
|
||||
try:
|
||||
resp = fm_core.get_by_aid(alarm_id)
|
||||
if resp is not None:
|
||||
data = []
|
||||
for i in resp:
|
||||
data.append(self._str_to_alarm(i))
|
||||
return data
|
||||
except (RuntimeError, SystemError, TypeError):
|
||||
pass
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _check_val(data):
|
||||
@ -177,21 +169,6 @@ class FaultAPIs(object):
|
||||
line[constants.FM_TIMESTAMP_INDEX])
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _run_cmd_and_get_resp(cmd):
|
||||
resp = []
|
||||
cmd = cmd.encode('utf-8')
|
||||
pro = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||
output = pro.communicate()[0]
|
||||
lines = output.split('\n')
|
||||
for line in lines:
|
||||
if line != '':
|
||||
resp.append(line)
|
||||
if len(resp) == 0:
|
||||
resp.append("Unknown")
|
||||
|
||||
return resp
|
||||
|
||||
@staticmethod
|
||||
def _check_required_attributes(data):
|
||||
if data.alarm_id is None:
|
||||
|
@ -1,6 +1,7 @@
|
||||
%define local_dir /usr/local
|
||||
%define local_bindir %{local_dir}/bin
|
||||
%define cgcs_doc_deploy_dir /opt/deploy/cgcs_doc
|
||||
%define pythonroot /usr/lib64/python2.7/site-packages
|
||||
|
||||
Summary: CGTS Platform Fault Management Common Package
|
||||
Name: fm-common
|
||||
@ -15,6 +16,7 @@ BuildRequires: util-linux
|
||||
BuildRequires: postgresql-devel
|
||||
BuildRequires: libuuid-devel
|
||||
BuildRequires: python-devel
|
||||
BuildRequires: python-setuptools
|
||||
|
||||
%package -n fm-common-dev
|
||||
Summary: CGTS Platform Fault Management Common Package - Development files
|
||||
@ -47,6 +49,7 @@ VER=%{version}
|
||||
MAJOR=`echo $VER | awk -F . '{print $1}'`
|
||||
MINOR=`echo $VER | awk -F . '{print $2}'`
|
||||
make MAJOR=$MAJOR MINOR=$MINOR %{?_smp_mflags}
|
||||
%{__python} setup.py build
|
||||
|
||||
%install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
@ -55,9 +58,18 @@ MAJOR=`echo $VER | awk -F . '{print $1}'`
|
||||
MINOR=`echo $VER | awk -F . '{print $2}'`
|
||||
make DEST_DIR=$RPM_BUILD_ROOT BIN_DIR=%{local_bindir} LIB_DIR=%{_libdir} INC_DIR=%{_includedir} MAJOR=$MAJOR MINOR=$MINOR install_non_bb
|
||||
|
||||
%{__python} setup.py install --root=%{buildroot} \
|
||||
--install-lib=%{pythonroot} \
|
||||
--prefix=/usr \
|
||||
--install-data=/usr/share
|
||||
|
||||
install -d $RPM_BUILD_ROOT/usr/bin
|
||||
install -m 755 fm_db_sync_event_suppression.py $RPM_BUILD_ROOT/usr/bin/fm_db_sync_event_suppression.py
|
||||
|
||||
# install the headers that used by fm-mgr package
|
||||
install -m 644 -p -D fmConfig.h %{buildroot}%{_includedir}/fmConfig.h
|
||||
install -m 644 -p -D fmLog.h %{buildroot}%{_includedir}/fmLog.h
|
||||
|
||||
CGCS_DOC_DEPLOY=$RPM_BUILD_ROOT/%{cgcs_doc_deploy_dir}
|
||||
install -d $CGCS_DOC_DEPLOY
|
||||
# install fmAlarm.h in CGCS_DOC_DEPLOY_DIR
|
||||
@ -75,6 +87,9 @@ rm -rf $RPM_BUILD_ROOT
|
||||
%{_libdir}/*.so.*
|
||||
/usr/bin/fm_db_sync_event_suppression.py
|
||||
|
||||
%{pythonroot}/fm_core.so
|
||||
%{pythonroot}/fm_core-*.egg-info
|
||||
|
||||
%files -n fm-common-dev
|
||||
%defattr(-,root,root,-)
|
||||
%{_includedir}/*
|
||||
|
@ -1,6 +1,6 @@
|
||||
SRCS = fmAPI.cpp fmFile.cpp fmLog.cpp fmMsgServer.cpp fmMutex.cpp fmSocket.cpp fmThread.cpp fmTime.cpp \
|
||||
fmAlarmUtils.cpp fmDb.cpp fmDbUtils.cpp fmDbAlarm.cpp fmSnmpUtils.cpp \
|
||||
fmDbEventLog.cpp fmEventSuppression.cpp
|
||||
fmDbEventLog.cpp fmEventSuppression.cpp fmConfig.cpp
|
||||
CLI_SRCS = fm_cli.cpp
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
CLI_OBJS = fm_cli.o
|
||||
@ -9,7 +9,7 @@ INCLUDES = -I./
|
||||
CCFLAGS = -g -O2 -Wall -Werror -fPIC
|
||||
|
||||
LIBFMCOMMON_SO := libfmcommon.so
|
||||
build: lib fmClientCli
|
||||
build: lib fmClientCli
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) $(CCFLAGS) $(INCLUDES) $(EXTRACCFLAGS) -c $< -o $@
|
||||
|
@ -472,7 +472,7 @@ bool fm_alarm_to_string(const SFmAlarmDataT *alarm, std::string &str) {
|
||||
return str.size()>0;
|
||||
}
|
||||
|
||||
bool fm_alarm_from_string(const std::string &alstr,SFmAlarmDataT *a) {
|
||||
bool fm_alarm_from_string(const std::string &alstr, SFmAlarmDataT *a) {
|
||||
strvect_t s;
|
||||
str_to_vector(alstr, s);
|
||||
|
||||
|
92
fm-common/sources/fmConfig.cpp
Normal file
92
fm-common/sources/fmConfig.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "fmAPI.h"
|
||||
#include "fmLog.h"
|
||||
#include "fmFile.h"
|
||||
#include "fmConfig.h"
|
||||
#include "fmMutex.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmSnmpConstants.h"
|
||||
#include "fmSnmpUtils.h"
|
||||
|
||||
typedef std::map<std::string,std::string> configParams;
|
||||
|
||||
static const char *conf = NULL;
|
||||
static int config_loaded = false;
|
||||
|
||||
CFmMutex & getConfMutex(){
|
||||
static CFmMutex *m = new CFmMutex;
|
||||
return *m;
|
||||
}
|
||||
|
||||
configParams &getConfigMap(){
|
||||
static configParams conf;
|
||||
return conf;
|
||||
}
|
||||
|
||||
void fm_conf_set_file(const char *fn){
|
||||
conf = fn;
|
||||
}
|
||||
|
||||
void fm_get_config_paramters(){
|
||||
CfmFile f;
|
||||
std::string delimiter = "=";
|
||||
std::string line, key, value;
|
||||
size_t pos = 0;
|
||||
|
||||
if (conf == NULL){
|
||||
FM_ERROR_LOG("The config file is not set\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!f.open(conf, CfmFile::READ, false)){
|
||||
FM_ERROR_LOG("Failed to open config file: %s\n", conf);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while (true){
|
||||
if (!f.read_line(line)) break;
|
||||
|
||||
if (line.size() == 0) continue;
|
||||
|
||||
if (line[0] == '#') continue;
|
||||
|
||||
pos = line.find(delimiter);
|
||||
key = line.substr(0, pos);
|
||||
value = line.erase(0, pos + delimiter.length());
|
||||
getConfigMap()[key] = value;
|
||||
if (key.compare(FM_SNMP_TRAPDEST) == 0){
|
||||
set_trap_dest_list(value);
|
||||
}
|
||||
if (key.compare(FM_SQL_CONNECTION) != 0){
|
||||
// Don't log sql_connection, as it has a password
|
||||
FM_INFO_LOG("Config key (%s), value (%s)",
|
||||
key.c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool fm_get_config_key(std::string &key, std::string &val){
|
||||
configParams::iterator it;
|
||||
CFmMutexGuard m(getConfMutex());
|
||||
|
||||
if (!config_loaded){
|
||||
fm_get_config_paramters();
|
||||
config_loaded = true;
|
||||
}
|
||||
|
||||
it = getConfigMap().find(key);
|
||||
if (it != getConfigMap().end()){
|
||||
val = it->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
18
fm-common/sources/fmConfig.h
Normal file
18
fm-common/sources/fmConfig.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Copyright (c) 2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#ifndef FMCONFIG_H_
|
||||
#define FMCONFIG_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
void fm_conf_set_file(const char *fn);
|
||||
|
||||
void fm_get_config_paramters();
|
||||
|
||||
bool fm_get_config_key(std::string &key, std::string &val);
|
||||
|
||||
#endif /* FMCONFIG_H_ */
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -16,10 +16,10 @@
|
||||
#define FM_DB_TABLE_COUNT_COLUMN "count"
|
||||
|
||||
/* Alarm table name */
|
||||
#define FM_ALARM_TABLE_NAME "i_alarm"
|
||||
#define FM_ALARM_TABLE_NAME "alarm"
|
||||
|
||||
/* Event log table name */
|
||||
#define FM_EVENT_LOG_TABLE_NAME "i_event_log"
|
||||
#define FM_EVENT_LOG_TABLE_NAME "event_log"
|
||||
|
||||
/* Event suppression table name */
|
||||
#define FM_EVENT_SUPPRESSION_TABLE_NAME "event_suppression"
|
||||
@ -81,11 +81,6 @@
|
||||
#define FM_EVENT_SUPPRESSION_UNSUPPRESSED "unsuppressed"
|
||||
#define FM_EVENT_SUPPRESSION_NONE "None"
|
||||
|
||||
/* System table name */
|
||||
#define FM_SYSTEM_TABLE_NAME "i_system"
|
||||
|
||||
#define FM_SYSTEM_NAME_COLUMN "name"
|
||||
#define FM_SYSTEM_REGION_COLUMN "region_name"
|
||||
|
||||
#define FM_ENTITY_ROOT_KEY "system="
|
||||
#define FM_ENTITY_REGION_KEY "region="
|
||||
@ -93,6 +88,10 @@
|
||||
/* config keys */
|
||||
#define FM_SQL_CONNECTION "sql_connection"
|
||||
#define FM_EVENT_LOG_MAX_SIZE "event_log_max_size"
|
||||
#define FM_SYSTEM_NAME "system_name"
|
||||
#define FM_REGION_NAME "region_name"
|
||||
#define FM_DEBUG_FLAG "debug"
|
||||
#define FM_STRING_TRUE "True"
|
||||
|
||||
#define CLEAR_ALL_REASON_TEXT "System initiated hierarchical alarm clear"
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2016 Wind River Systems, Inc.
|
||||
// Copyright (c) 2016-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -16,7 +16,7 @@
|
||||
#include "fmAlarmUtils.h"
|
||||
#include "fmDbUtils.h"
|
||||
#include "fmDb.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmThread.h"
|
||||
|
||||
|
||||
@ -62,11 +62,7 @@ bool CFmDBSession::connect(const char *uri){
|
||||
m_conn.uri = uri;
|
||||
|
||||
val = get_parameter_status("standard_conforming_strings");
|
||||
//FM_INFO_LOG("connect: server standard_conforming_strings parameter: %s",
|
||||
// val ? val : "unavailable");
|
||||
m_conn.equote = (val && (0 == strcmp("off", val)));
|
||||
//FM_INFO_LOG("connect: server requires E'' quotes: %s", m_conn.equote ? "YES" : "NO");
|
||||
|
||||
m_conn.server_version = PQserverVersion(m_conn.pgconn);
|
||||
m_conn.protocol = PQprotocolVersion(m_conn.pgconn);
|
||||
m_conn.encoding = get_parameter_status("client_encoding");
|
||||
@ -132,7 +128,7 @@ bool CFmDBSession::query(const char *db_cmd,fm_db_result_t & result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFmDBSession::cmd(const char *db_cmd){
|
||||
bool CFmDBSession::cmd(const char *db_cmd, bool check_row){
|
||||
PGresult *res;
|
||||
bool rc = true;
|
||||
|
||||
@ -147,7 +143,7 @@ bool CFmDBSession::cmd(const char *db_cmd){
|
||||
FM_ERROR_LOG("Failed to execute (%s) (%s)", db_cmd, PQresultErrorMessage(res));
|
||||
rc = false;
|
||||
}
|
||||
if (rc){
|
||||
if (rc && check_row){
|
||||
int row = atoi(PQcmdTuples(res));
|
||||
FM_DEBUG_LOG("SQL command returned successful: %d rows affected.\n", row);
|
||||
if (row < 1) rc = false;
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -53,7 +53,7 @@ public:
|
||||
bool reconnect();
|
||||
|
||||
bool query(const char *db_cmd,fm_db_result_t & result);
|
||||
bool cmd(const char *db_cmd);
|
||||
bool cmd(const char *db_cmd, bool check_row=true);
|
||||
bool params_cmd(fm_db_util_sql_params & sql_params);
|
||||
|
||||
PGconn* get_pgconn(){
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -11,7 +11,7 @@
|
||||
#include "fmLog.h"
|
||||
#include "fmDbAlarm.h"
|
||||
#include "fmAlarmUtils.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmDbUtils.h"
|
||||
|
||||
typedef std::map<int,std::string> itos_t;
|
||||
@ -319,7 +319,7 @@ bool CFmDbAlarmOperation::get_all_alarms(CFmDBSession &sess, SFmAlarmDataT **ala
|
||||
if (!get_alarms(sess, NULL, res))
|
||||
return false;
|
||||
|
||||
std::string sname = fm_db_util_get_system_name(sess);
|
||||
std::string sname = fm_db_util_get_system_name();
|
||||
|
||||
unsigned int found_num_alarms = res.size();
|
||||
|
||||
@ -436,7 +436,7 @@ bool CFmDbAlarmOperation::get_all_history_alarms(CFmDBSession &sess, SFmAlarmDat
|
||||
*alarms = NULL;
|
||||
if (!get_history(sess,res)) return false;
|
||||
|
||||
std::string sname = fm_db_util_get_system_name(sess);
|
||||
std::string sname = fm_db_util_get_system_name();
|
||||
|
||||
unsigned int found_num_alarms = res.size();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -13,7 +13,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "fmAPI.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmDb.h"
|
||||
|
||||
class CFmDbAlarm {
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "fmDbAlarm.h"
|
||||
#include "fmDbEventLog.h"
|
||||
#include "fmAlarmUtils.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmDbUtils.h"
|
||||
|
||||
typedef std::map<int,std::string> itos_t;
|
||||
@ -291,7 +291,7 @@ bool CFmDbEventLogOperation::get_all_event_logs(CFmDBSession &sess, SFmAlarmData
|
||||
|
||||
if (!get_event_logs(sess, res)) return false;
|
||||
|
||||
std::string sname = fm_db_util_get_system_name(sess);
|
||||
std::string sname = fm_db_util_get_system_name();
|
||||
|
||||
unsigned int found_num_logs = res.size();
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2016 Wind River Systems, Inc.
|
||||
// Copyright (c) 2016-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -13,7 +13,7 @@
|
||||
#include <map>
|
||||
|
||||
#include "fmAPI.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmDb.h"
|
||||
|
||||
typedef std::map<int,std::string> itos_t;
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -25,29 +25,18 @@
|
||||
#include "fmDb.h"
|
||||
#include "fmDbUtils.h"
|
||||
#include "fmDbAPI.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmAlarmUtils.h"
|
||||
#include "fmConfig.h"
|
||||
|
||||
|
||||
typedef std::map<std::string,std::string> configParams;
|
||||
|
||||
static const char *conf = NULL;
|
||||
|
||||
static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
CFmMutex & getConfMutex(){
|
||||
static CFmMutex *m = new CFmMutex;
|
||||
return *m;
|
||||
}
|
||||
|
||||
configParams &getConfigMap(){
|
||||
static configParams conf;
|
||||
return conf;
|
||||
}
|
||||
|
||||
void FM_DB_UT_NAME_VAL(
|
||||
std::string &result,
|
||||
const std::string &lhs, const std::string &rhs) {
|
||||
std::string &result,
|
||||
const std::string &lhs, const std::string &rhs) {
|
||||
result+= lhs;
|
||||
result+= " = '";
|
||||
result+=rhs;
|
||||
@ -55,8 +44,8 @@ void FM_DB_UT_NAME_VAL(
|
||||
}
|
||||
|
||||
void FM_DB_UT_NAME_PARAM(
|
||||
std::string &result,
|
||||
const std::string &lhs, const std::string &rhs) {
|
||||
std::string &result,
|
||||
const std::string &lhs, const std::string &rhs) {
|
||||
result+= lhs;
|
||||
result+= "=";
|
||||
result+=rhs;
|
||||
@ -90,40 +79,6 @@ static int get_oldest_id(CFmDBSession &sess, const char* db_table){
|
||||
return id;
|
||||
}
|
||||
|
||||
static void get_config_parameters(){
|
||||
CfmFile f;
|
||||
std::string delimiter = "=";
|
||||
std::string line, key, value;
|
||||
size_t pos = 0;
|
||||
|
||||
if (conf == NULL){
|
||||
FM_ERROR_LOG("The config file is not set\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (!f.open(conf, CfmFile::READ, false)){
|
||||
FM_ERROR_LOG("Failed to open config file: %s\n", conf);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while (true){
|
||||
if (!f.read_line(line)) break;
|
||||
|
||||
if (line.size() == 0) continue;
|
||||
|
||||
if (line[0] == '#') continue;
|
||||
|
||||
pos = line.find(delimiter);
|
||||
key = line.substr(0, pos);
|
||||
value = line.erase(0, pos + delimiter.length());
|
||||
getConfigMap()[key] = value;
|
||||
if (key.compare("sql_connection") != 0){
|
||||
// Don't log sql_connection, as it has a password
|
||||
FM_INFO_LOG("Config key (%s), value (%s)",
|
||||
key.c_str(), value.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline CFmDBSession & FmDbSessionFromHandle(TFmAlarmSessionT *p){
|
||||
return *((CFmDBSession*)p);
|
||||
@ -189,7 +144,7 @@ int fm_db_util_string_to_int(std::string val){
|
||||
}
|
||||
|
||||
void fm_db_util_make_timestamp_string(std::string &tstr, FMTimeT tm,
|
||||
bool snmp){
|
||||
bool snmp){
|
||||
struct timespec ts;
|
||||
if (tm != 0){
|
||||
ts.tv_sec = tm / 1000000;
|
||||
@ -517,28 +472,6 @@ bool fm_db_util_build_sql_delete_all(const char* db_table, const char *id,
|
||||
return true;
|
||||
}
|
||||
|
||||
void fm_db_util_set_conf_file(const char *fn){
|
||||
conf = fn;
|
||||
}
|
||||
|
||||
bool fm_db_util_get_config(std::string &key, std::string &val){
|
||||
|
||||
configParams::iterator it;
|
||||
static int loaded = false;
|
||||
CFmMutexGuard m(getConfMutex());
|
||||
|
||||
if (!loaded){
|
||||
get_config_parameters();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
it = getConfigMap().find(key);
|
||||
if (it != getConfigMap().end()){
|
||||
val = it->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int & fm_get_alarm_history_max_size(){
|
||||
static int max_size = 0;
|
||||
@ -546,7 +479,7 @@ int & fm_get_alarm_history_max_size(){
|
||||
if (max_size == 0){
|
||||
std::string val;
|
||||
std::string key = FM_EVENT_LOG_MAX_SIZE;
|
||||
if (fm_db_util_get_config(key, val)){
|
||||
if (fm_get_config_key(key, val)){
|
||||
max_size = fm_db_util_string_to_int(val);
|
||||
}else{
|
||||
FM_ERROR_LOG("Fail to get config value for (%s)\n", key.c_str());
|
||||
@ -561,7 +494,7 @@ int & fm_get_log_max_size(){
|
||||
if (max_size == 0){
|
||||
std::string val;
|
||||
std::string key = FM_EVENT_LOG_MAX_SIZE;
|
||||
if (fm_db_util_get_config(key, val)){
|
||||
if (fm_get_config_key(key, val)){
|
||||
max_size = fm_db_util_string_to_int(val);
|
||||
}else{
|
||||
FM_ERROR_LOG("Fail to get config value for (%s)\n", key.c_str());
|
||||
@ -570,34 +503,21 @@ int & fm_get_log_max_size(){
|
||||
return max_size;
|
||||
}
|
||||
|
||||
std::string fm_db_util_get_system_name(CFmDBSession &sess){
|
||||
fm_db_result_t res;
|
||||
std::string cmd;
|
||||
std::string fm_db_util_get_system_info(const std::string prefix, std::string key){
|
||||
std::string val;
|
||||
std::string name = "";
|
||||
|
||||
fm_db_util_build_sql_query(FM_SYSTEM_TABLE_NAME, NULL, cmd);
|
||||
if (sess.query(cmd.c_str(), res)){
|
||||
if (res.size() > 0){
|
||||
std::map<std::string,std::string> entry = res[0];
|
||||
name = FM_ENTITY_ROOT_KEY + entry[FM_SYSTEM_NAME_COLUMN];
|
||||
}
|
||||
if (fm_get_config_key(key, val)){
|
||||
name = prefix + val;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string fm_db_util_get_region_name(CFmDBSession &sess){
|
||||
fm_db_result_t res;
|
||||
std::string cmd;
|
||||
std::string name = "";
|
||||
std::string fm_db_util_get_system_name(){
|
||||
return fm_db_util_get_system_info(FM_ENTITY_ROOT_KEY, FM_SYSTEM_NAME);
|
||||
}
|
||||
|
||||
fm_db_util_build_sql_query(FM_SYSTEM_TABLE_NAME, NULL, cmd);
|
||||
if (sess.query(cmd.c_str(), res)){
|
||||
if (res.size() > 0){
|
||||
std::map<std::string,std::string> entry = res[0];
|
||||
name = FM_ENTITY_REGION_KEY + entry[FM_SYSTEM_REGION_COLUMN];
|
||||
}
|
||||
}
|
||||
return name;
|
||||
std::string fm_db_util_get_region_name(){
|
||||
return fm_db_util_get_system_info(FM_ENTITY_REGION_KEY, FM_REGION_NAME);
|
||||
}
|
||||
|
||||
bool fm_db_util_get_row_counts(CFmDBSession &sess,
|
||||
@ -656,13 +576,12 @@ bool fm_db_util_get_next_log_id(CFmDBSession &sess, int &id){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fm_db_util_create_session(CFmDBSession **sess){
|
||||
bool fm_db_util_create_session(CFmDBSession **sess, std::string key){
|
||||
TFmAlarmSessionT handle;
|
||||
const char *db_conn = NULL;
|
||||
std::string val;
|
||||
std::string key = FM_SQL_CONNECTION;
|
||||
|
||||
if (fm_db_util_get_config(key, val) != true){
|
||||
if (fm_get_config_key(key, val) != true){
|
||||
FM_ERROR_LOG("Failed to get config for key: (%s)\n", key.c_str());
|
||||
return false;
|
||||
}
|
||||
@ -682,34 +601,34 @@ bool fm_db_util_sync_event_suppression(void){
|
||||
std::string val;
|
||||
std::string key = FM_SQL_CONNECTION;
|
||||
|
||||
if (fm_db_util_get_config(key, val) != true){
|
||||
FM_ERROR_LOG("Failed to get config for key: (%s)\n", key.c_str());
|
||||
if (fm_get_config_key(key, val) != true){
|
||||
FM_ERROR_LOG("NEW Failed to get config for key: (%s)\n", key.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
db_conn = val.c_str();
|
||||
|
||||
FILE* file;
|
||||
int argc;
|
||||
char * argv[2];
|
||||
FILE* file;
|
||||
int argc;
|
||||
char * argv[2];
|
||||
|
||||
FM_INFO_LOG("Starting event suppression synchronization...\n");
|
||||
FM_INFO_LOG("Starting event suppression synchronization...\n");
|
||||
|
||||
argc = 2;
|
||||
argv[0] = (char*)FM_DB_SYNC_EVENT_SUPPRESSION;
|
||||
argv[1] = (char*)db_conn;
|
||||
argc = 2;
|
||||
argv[0] = (char*)FM_DB_SYNC_EVENT_SUPPRESSION;
|
||||
argv[1] = (char*)db_conn;
|
||||
|
||||
Py_SetProgramName(argv[0]);
|
||||
Py_Initialize();
|
||||
PySys_SetArgv(argc, argv);
|
||||
file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r");
|
||||
PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION);
|
||||
fclose(file);
|
||||
Py_Finalize();
|
||||
Py_SetProgramName(argv[0]);
|
||||
Py_Initialize();
|
||||
PySys_SetArgv(argc, argv);
|
||||
file = fopen(FM_DB_SYNC_EVENT_SUPPRESSION,"r");
|
||||
PyRun_SimpleFile(file, FM_DB_SYNC_EVENT_SUPPRESSION);
|
||||
fclose(file);
|
||||
Py_Finalize();
|
||||
|
||||
FM_INFO_LOG("Completed event suppression synchronization.\n");
|
||||
FM_INFO_LOG("Completed event suppression synchronization.\n");
|
||||
|
||||
return return_value;
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -73,16 +73,15 @@ bool fm_db_util_build_sql_delete_all(const char* db_table,
|
||||
bool fm_db_util_get_row_counts(CFmDBSession &sess, const char* db_table,
|
||||
int &counts);
|
||||
|
||||
bool fm_db_util_create_session(CFmDBSession **sess);
|
||||
bool fm_db_util_create_session(CFmDBSession **sess,
|
||||
std::string key=FM_SQL_CONNECTION);
|
||||
|
||||
std::string fm_db_util_get_system_name(CFmDBSession &sess);
|
||||
std::string fm_db_util_get_system_name();
|
||||
|
||||
std::string fm_db_util_get_region_name(CFmDBSession &sess);
|
||||
std::string fm_db_util_get_region_name();
|
||||
|
||||
void fm_db_util_set_conf_file(const char *fn);
|
||||
|
||||
bool fm_db_util_get_config(std::string &key, std::string &val);
|
||||
|
||||
bool fm_db_util_get_next_log_id(CFmDBSession &sess, int &id);
|
||||
|
||||
std::string fm_db_util_int_to_string(int val);
|
||||
|
@ -1,13 +1,12 @@
|
||||
//
|
||||
// Copyright (c) 2016 Wind River Systems, Inc.
|
||||
// Copyright (c) 2016-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmLog.h"
|
||||
#include "fmDbAlarm.h"
|
||||
#include "fmEventSuppression.h"
|
||||
@ -73,6 +72,7 @@ bool CFmEventSuppressionOperation::set_table_notify_listen(CFmDBSession &sess){
|
||||
sql = "SELECT rulename FROM pg_rules WHERE rulename='watch_event_supression'";
|
||||
|
||||
if ((sess.query(sql.c_str(), rule_name)) != true){
|
||||
FM_DEBUG_LOG("Failed to query the existing rule");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -84,7 +84,8 @@ bool CFmEventSuppressionOperation::set_table_notify_listen(CFmDBSession &sess){
|
||||
sql += FM_EVENT_SUPPRESSION_TABLE_NAME;
|
||||
sql += ")";
|
||||
|
||||
if (sess.cmd(sql.c_str()) != true){
|
||||
if (sess.cmd(sql.c_str(), false) != true){
|
||||
FM_INFO_LOG("Failed to set rule CMD: (%s)", sql.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -95,10 +96,6 @@ bool CFmEventSuppressionOperation::set_table_notify_listen(CFmDBSession &sess){
|
||||
sql += FM_EVENT_SUPPRESSION_TABLE_NAME;
|
||||
|
||||
FM_DEBUG_LOG("CMD:(%s)\n", sql.c_str());
|
||||
sess.cmd(sql.c_str()); // TODO: sess.cmd() returns false since no row affected by LISTEN command
|
||||
/* if (sess.cmd(sql.c_str()) != true){
|
||||
return false;
|
||||
} */
|
||||
|
||||
return true;
|
||||
// no row affected by LISTEN command
|
||||
return sess.cmd(sql.c_str(), false);
|
||||
}
|
||||
|
@ -9,15 +9,6 @@
|
||||
#define FMEVENTSUPPRESSION_H_
|
||||
|
||||
|
||||
/*
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stddef.h>
|
||||
#include <map>
|
||||
|
||||
#include "fmAPI.h"
|
||||
#include "fmDbConstants.h"
|
||||
*/
|
||||
#include "fmDb.h"
|
||||
|
||||
class CFmEventSuppressionOperation {
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -7,12 +7,14 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "fmLog.h"
|
||||
#include "fmDbAlarm.h"
|
||||
#include "fmDbEventLog.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
#include "fmConfig.h"
|
||||
#include "fmConstants.h"
|
||||
|
||||
static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
@ -24,6 +26,13 @@ void fmLoggingInit() {
|
||||
openlog(NULL,LOG_CONS | LOG_NDELAY,LOG_LOCAL1);
|
||||
setlogmask(LOG_UPTO (LOG_INFO));
|
||||
}
|
||||
std::string val;
|
||||
std::string key = FM_DEBUG_FLAG;
|
||||
if ((fm_get_config_key(key, val)) && (val.compare("True") == 0)){
|
||||
setlogmask(LOG_UPTO (LOG_DEBUG));
|
||||
} else {
|
||||
setlogmask(LOG_UPTO (LOG_INFO));
|
||||
}
|
||||
has_inited=true;
|
||||
}
|
||||
|
||||
@ -36,11 +45,6 @@ void fmLogMsg(int level, const char *data,...){
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
bool fmLogFileInit(){
|
||||
fmLoggingInit();
|
||||
return true;
|
||||
}
|
||||
|
||||
// formats event into json form for logging
|
||||
static char * formattedEvent(CFmDbEventLog::data_type event_map, char * output, int outputSize) {
|
||||
int bufLen = 1024;
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -68,9 +68,6 @@ bool fmLogFileInit();
|
||||
|
||||
void fmLogAddEventLog(SFmAlarmDataT * data, bool is_event_suppressed);
|
||||
|
||||
//void fmLogAddEventLog(SFmAlarmDataT * data);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2017 Wind River Systems, Inc.
|
||||
// Copyright (c) 2017-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -40,8 +40,9 @@
|
||||
#include "fmSnmpUtils.h"
|
||||
#include "fmDbUtils.h"
|
||||
#include "fmDbEventLog.h"
|
||||
#include "fmDbConstants.h"
|
||||
#include "fmConstants.h"
|
||||
#include "fmEventSuppression.h"
|
||||
#include "fmConfig.h"
|
||||
|
||||
#define FM_UUID_LENGTH 36
|
||||
|
||||
@ -125,7 +126,7 @@ static bool dequeue_get(sFmGetReq &req){
|
||||
return true;
|
||||
}
|
||||
|
||||
void create_db_log(CFmDBSession &sess, sFmJobReq &req){
|
||||
void create_db_log(sFmJobReq &req){
|
||||
SFmAlarmDataT alarm = req.data;
|
||||
|
||||
if (alarm.alarm_state != FM_ALARM_STATE_MSG){
|
||||
@ -135,7 +136,7 @@ void create_db_log(CFmDBSession &sess, sFmJobReq &req){
|
||||
}
|
||||
|
||||
fmLogAddEventLog(&alarm, false);
|
||||
fm_snmp_util_gen_trap(sess, FM_ALARM_MESSAGE, alarm);
|
||||
fm_snmp_util_gen_trap(FM_ALARM_MESSAGE, alarm);
|
||||
}
|
||||
|
||||
void get_db_alarm(CFmDBSession &sess, sFmGetReq &req, void *context){
|
||||
@ -293,7 +294,7 @@ void fm_handle_job_request(CFmDBSession &sess, sFmJobReq &req){
|
||||
|
||||
//check if it is a customer log request
|
||||
if (req.type == FM_CUSTOMER_LOG) {
|
||||
return create_db_log(sess,req);
|
||||
return create_db_log(req);
|
||||
}
|
||||
|
||||
// check to see if there are any alarms need to be masked/unmasked
|
||||
@ -317,7 +318,7 @@ void fm_handle_job_request(CFmDBSession &sess, sFmJobReq &req){
|
||||
req.data.alarm_id);
|
||||
} else {
|
||||
if (!is_event_suppressed)
|
||||
fm_snmp_util_gen_trap(sess, req.type, req.data);
|
||||
fm_snmp_util_gen_trap(req.type, req.data);
|
||||
}
|
||||
|
||||
fmLogAddEventLog(&req.data, is_event_suppressed);
|
||||
@ -572,14 +573,10 @@ EFmErrorT fm_server_create(const char *fn) {
|
||||
hints.ai_addr = NULL;
|
||||
hints.ai_next = NULL;
|
||||
|
||||
fm_conf_set_file(fn);
|
||||
|
||||
fmLoggingInit();
|
||||
|
||||
if (!fmLogFileInit()){
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fm_db_util_set_conf_file(fn);
|
||||
|
||||
if (!fm_db_util_sync_event_suppression()){
|
||||
exit(-1);
|
||||
}
|
||||
@ -704,7 +701,7 @@ bool fm_handle_event_suppress_changes(CFmDBSession &sess){
|
||||
}
|
||||
|
||||
SFmAlarmDataT *alarm = NULL;
|
||||
fm_snmp_util_gen_trap(sess, FM_WARM_START, *alarm);
|
||||
fm_snmp_util_gen_trap(FM_WARM_START, *alarm);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2017-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -14,12 +14,13 @@
|
||||
|
||||
#define FM_CUSTOMER_LOG 10
|
||||
|
||||
/* Trap Destination table name */
|
||||
#define FM_TRAPDEST_TABLE_NAME "i_trap_destination"
|
||||
/* Trap Destination definitions */
|
||||
|
||||
#define FM_TRAPDEST_IP_COLUMN "ip_address"
|
||||
#define FM_SNMP_TRAPDEST "trap_destinations"
|
||||
|
||||
#define FM_TRAPDEST_COMM_COLUMN "community"
|
||||
#define FM_TRAPDEST_IP "ip_address"
|
||||
|
||||
#define FM_TRAPDEST_COMM "community"
|
||||
|
||||
/* MIB Trap definitions */
|
||||
const std::string WRS_ALARM_MIB = "WRS-ALARM-MIB";
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2014 Wind River Systems, Inc.
|
||||
// Copyright (c) 2014-2018 Wind River Systems, Inc.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
@ -11,6 +11,7 @@
|
||||
#include <map>
|
||||
#include <assert.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "fmDbAPI.h"
|
||||
#include "fmFile.h"
|
||||
@ -21,6 +22,7 @@
|
||||
#include "fmDbUtils.h"
|
||||
#include "fmSnmpConstants.h"
|
||||
#include "fmSnmpUtils.h"
|
||||
#include "fmConfig.h"
|
||||
|
||||
typedef std::map<int,std::string> int_to_objtype;
|
||||
|
||||
@ -28,6 +30,11 @@ static int_to_objtype objtype_map;
|
||||
static pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
|
||||
|
||||
fm_db_result_t &getTrapDestList(){
|
||||
static fm_db_result_t trap_dest_list;
|
||||
return trap_dest_list;
|
||||
}
|
||||
|
||||
static void add_to_table(int t, std::string objtype, int_to_objtype &tbl) {
|
||||
tbl[t]=objtype;
|
||||
}
|
||||
@ -72,14 +79,38 @@ static std::string get_trap_objtype(int type){
|
||||
init_objtype_table();
|
||||
return objtype_map[type];
|
||||
}
|
||||
static bool get_trap_dest_list(CFmDBSession &sess,fm_db_result_t & res){
|
||||
std::string cmd;
|
||||
|
||||
fm_db_util_build_sql_query(FM_TRAPDEST_TABLE_NAME, NULL, cmd);
|
||||
return sess.query(cmd.c_str(), res);
|
||||
static void add_to_list(std::vector<std::string> &trap_strings) {
|
||||
std::string delimiter = " ";
|
||||
|
||||
std::vector<std::string>::iterator it = trap_strings.begin();
|
||||
std::vector<std::string>::iterator end = trap_strings.end();
|
||||
getTrapDestList().clear();
|
||||
for (; it != end; ++it){
|
||||
size_t pos = 0;
|
||||
fm_db_single_result_t entry;
|
||||
pos = (*it).find(delimiter);
|
||||
entry[FM_TRAPDEST_IP] = (*it).substr(0, pos);
|
||||
entry[FM_TRAPDEST_COMM] = (*it).erase(0, pos + delimiter.length());
|
||||
getTrapDestList().push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
static std::string format_trap_cmd(CFmDBSession &sess, int type, SFmAlarmDataT &data,
|
||||
void set_trap_dest_list(std::string value){
|
||||
|
||||
std::vector<std::string> entries;
|
||||
std::istringstream f(value);
|
||||
std::string s;
|
||||
while (getline(f, s, ',')) {
|
||||
std::cout << s << std::endl;
|
||||
FM_INFO_LOG("Add entry: (%s)", s.c_str());
|
||||
entries.push_back(s);
|
||||
}
|
||||
add_to_list(entries);
|
||||
FM_INFO_LOG("Set trap entries: (%d)", getTrapDestList().size());
|
||||
}
|
||||
|
||||
static std::string format_trap_cmd(int type, SFmAlarmDataT &data,
|
||||
std::string &ip, std::string &comm){
|
||||
std::string cmd;
|
||||
std::string objtype;
|
||||
@ -140,28 +171,29 @@ static std::string format_trap_cmd(CFmDBSession &sess, int type, SFmAlarmDataT &
|
||||
return cmd;
|
||||
}
|
||||
|
||||
bool fm_snmp_util_gen_trap(CFmDBSession &sess, int type, SFmAlarmDataT &data) {
|
||||
|
||||
bool fm_snmp_util_gen_trap(int type, SFmAlarmDataT &data) {
|
||||
|
||||
bool rc = true;
|
||||
fm_buff_t cmdbuff;
|
||||
fm_db_result_t res;
|
||||
std::string cmd, eid;
|
||||
|
||||
if (!get_trap_dest_list(sess,res)) return false;
|
||||
res = getTrapDestList();
|
||||
|
||||
if (&data != NULL) {
|
||||
eid.assign(data.entity_instance_id);
|
||||
std::string region_name = fm_db_util_get_region_name(sess);
|
||||
std::string sys_name = fm_db_util_get_system_name(sess);
|
||||
if (sys_name.length() != 0){
|
||||
eid = sys_name + "."+ eid;
|
||||
}
|
||||
if (region_name.length() != 0){
|
||||
eid = region_name + "."+ eid;
|
||||
}
|
||||
strncpy(data.entity_instance_id, eid.c_str(),
|
||||
sizeof(data.entity_instance_id)-1);
|
||||
}
|
||||
if (&data != NULL) {
|
||||
eid.assign(data.entity_instance_id);
|
||||
std::string region_name = fm_db_util_get_region_name();
|
||||
std::string sys_name = fm_db_util_get_system_name();
|
||||
if (sys_name.length() != 0){
|
||||
eid = sys_name + "."+ eid;
|
||||
}
|
||||
if (region_name.length() != 0){
|
||||
eid = region_name + "."+ eid;
|
||||
}
|
||||
strncpy(data.entity_instance_id, eid.c_str(),
|
||||
sizeof(data.entity_instance_id)-1);
|
||||
}
|
||||
|
||||
fm_db_result_t::iterator it = res.begin();
|
||||
fm_db_result_t::iterator end = res.end();
|
||||
@ -169,9 +201,9 @@ bool fm_snmp_util_gen_trap(CFmDBSession &sess, int type, SFmAlarmDataT &data) {
|
||||
for (; it != end; ++it){
|
||||
memset(&(cmdbuff[0]), 0, cmdbuff.size());
|
||||
cmd.clear();
|
||||
std::string ip = (*it)[FM_TRAPDEST_IP_COLUMN];
|
||||
std::string comm = (*it)[FM_TRAPDEST_COMM_COLUMN];
|
||||
cmd = format_trap_cmd(sess,type, data, ip, comm);
|
||||
std::string ip = (*it)[FM_TRAPDEST_IP];
|
||||
std::string comm = (*it)[FM_TRAPDEST_COMM];
|
||||
cmd = format_trap_cmd(type, data, ip, comm);
|
||||
|
||||
//FM_INFO_LOG("run cmd: %s\n", cmd.c_str());
|
||||
char *pline = &(cmdbuff[0]);
|
||||
@ -190,42 +222,17 @@ bool fm_snmp_util_gen_trap(CFmDBSession &sess, int type, SFmAlarmDataT &data) {
|
||||
}
|
||||
|
||||
static bool fm_snmp_get_db_connection(std::string &connection){
|
||||
CfmFile f;
|
||||
const char *fn = "/etc/fm.conf";
|
||||
std::string sql_key = FM_SQL_CONNECTION;
|
||||
std::string delimiter = "=";
|
||||
std::string line, key, value;
|
||||
size_t pos = 0;
|
||||
const char *fn = "/etc/fm/fm.conf";
|
||||
std::string key = FM_SQL_CONNECTION;
|
||||
|
||||
if (!f.open(fn, CfmFile::READ, false)){
|
||||
FM_ERROR_LOG("Failed to open config file: %s\n", fn);
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
while (true){
|
||||
if (!f.read_line(line)) break;
|
||||
|
||||
if (line.size() == 0) continue;
|
||||
|
||||
pos = line.find(delimiter);
|
||||
key = line.substr(0, pos);
|
||||
if (key == sql_key){
|
||||