diff --git a/mtce-common/src/common/logMacros.h b/mtce-common/src/common/logMacros.h index 6393a126..c347b462 100644 --- a/mtce-common/src/common/logMacros.h +++ b/mtce-common/src/common/logMacros.h @@ -72,9 +72,6 @@ typedef struct int sysinv_api_port ; /**< =6385 */ char* sysinv_api_bind_ip ; /**< = */ - char* ceilometer_url ; /**< ceilometer sensor sample database url */ - int ceilometer_port ; /**< ceilometer REST API port number */ - char* barbican_api_host ; /**< Barbican REST API host IP address */ int barbican_api_port ; /**< Barbican REST API port number */ diff --git a/mtce-common/src/common/pgdbClass.cpp.OBS b/mtce-common/src/common/pgdbClass.cpp.OBS deleted file mode 100644 index ee113aa2..00000000 --- a/mtce-common/src/common/pgdbClass.cpp.OBS +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2015 Wind River Systems, Inc. -* -* SPDX-License-Identifier: Apache-2.0 -* - */ - -/** - * @file - * Wind River CGTS Platform PostgreSQL Database Access module for maintenance. - * - * pqdmClass member primitive implementation. - * - * query - * - * - */ - -#include "pgdbClass.h" - -#define MAX_SQL_RESPONSE_MAX (4096) -#define SENSOR_SAMPLE_TABLE "sample" - -/* DB connection status */ -#define DB_DISCONNECTED 0 -#define DB_CONNECTED 1 - -pgdbClass::pgdbClass() -{ - pg.uri = NULL; - pg.conn = NULL; - pg.connected = false ; -} - -pgdbClass::~pgdbClass() -{ - if (pg.conn) - { - PQfinish(pg.conn); - } - pg.connected = false ; -} - -int pgdbClass::connect(const char *uri) -{ - const char *val = NULL; - - /* make a connection to the specified database */ - this->pg.conn = PQconnectdb(uri); - - /* verify the connection */ - if ((this->pg.conn == NULL) || (PQstatus(this->pg.conn) != CONNECTION_OK)) - { - elog ("failed to connected to DB: (%s)\n", uri); - PQfinish(this->pg.conn); - return FAIL; - } - - this->pg.connected = true ; - this->pg.uri = uri; - - val = get_parameter_status("standard_conforming_strings"); - ilog ("server standard_conforming_strings parameter: %s\n", val ? val : "unavailable"); - - this->pg.equote = (val && (0 == strcmp("off", val))); - ilog ("server requires E'' quotes: %s\n", this->pg.equote ? "YES" : "NO"); - - this->pg.server_version = PQserverVersion(this->pg.conn); - this->pg.protocol = PQprotocolVersion(this->pg.conn); - this->pg.encoding = get_parameter_status("client_encoding"); - - return PASS ; -} - -int pgdbClass::monitor( void ) -{ - if (PQstatus(this->pg.conn) != CONNECTION_OK) - { - elog ("failed connection audit to '%s' (%s)\n", this->pg.uri, PQerrorMessage(this->pg.conn)); - disconnect(); - - /* TODO: make this an FSM, otherwise this will bang away */ - // return connect(this->pg.uri); - return (FAIL); - } - return PASS ; -} - -void pgdbClass::disconnect() -{ - if (this->pg.conn != NULL) - { - PQfinish(this->pg.conn); - } - if (this->pg.connected == true ) - { - this->pg.connected = false ; - } -} - -const char * pgdbClass::get_parameter_status(const char *param) -{ - return PQparameterStatus(this->pg.conn, param); -} - -int pgdbClass::cmd(const char *db_cmd) -{ - PGresult *res; - int rc = PASS; - - if (monitor() != PASS ) - { - elog ("Failed to reconnect: %s", PQerrorMessage(this->pg.conn)); - return FAIL ; - } - res = PQexec(this->pg.conn, db_cmd); - if (PQresultStatus(res) != PGRES_COMMAND_OK) - { - elog ("Request Status: %s\n", PQresStatus(PQresultStatus(res))); - elog ("execute Status: %s (%s)\n", db_cmd, PQresultErrorMessage(res)); - rc = FAIL; - } - if (rc == PASS ) - { - int row = atoi(PQcmdTuples(res)); - ilog ("SQL command returned successful: %d rows affected.\n", row); /* dlog */ - if (row < 1) - { - rc = FAIL; - } - } - PQclear(res); - return rc; -} - - -int pgdbUtil_get_version ( void ) -{ - int ver = PQlibVersion(); - ilog ("libpq version: %d\n", ver); - return ver ; -} - -int pgdbClass::query (const char * db_cmd , mtc_query_type & result) -{ - PGresult *res; - int nfields, ntuples, i, j; - - if (monitor() != PASS) - { - elog ("Failed to reconnect: %s\n", PQerrorMessage(this->pg.conn)); - return (FAIL) ; - } - - res = PQexec( pg.conn, db_cmd); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - elog("request status: %s\n", PQresStatus(PQresultStatus(res))); - elog("execute status: %s (%s)\n", db_cmd, PQresultErrorMessage(res)); - PQclear(res); - return(FAIL); - } - - nfields = PQnfields(res); - ntuples = PQntuples(res); - ilog ("Cmd: (%s) OK, entries found: (%d)\n", db_cmd, ntuples); /* dlog */ - - for (i = 0; i < ntuples; ++i) - { - mtc_key_value_type key_value ; - - for (j =0; j < nfields; ++j) - { - char * key = PQfname(res, j); - char * value = PQgetvalue(res, i, j); - key_value[key] = value; - } - result.push_back ( key_value ); - } - PQclear(res); - return(PASS); -} diff --git a/mtce-common/src/common/pgdbClass.h.OBS b/mtce-common/src/common/pgdbClass.h.OBS deleted file mode 100644 index a7f6189d..00000000 --- a/mtce-common/src/common/pgdbClass.h.OBS +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef __INCLUDE_PGDBCLASS_H__ -#define __INCLUDE_PGDBCLASS_H__ - -/* - * Copyright (c) 2015 Wind River Systems, Inc. -* -* SPDX-License-Identifier: Apache-2.0 -* - */ - -/** - * @file - * Wind River CGTS Platform PostgreSQL Database Access module for maintenance. - * - * Class, support structs and enums. - * - * This module is based off the libpq - C Library - * - * Header File: libpg-fe.h - * Library File: libpq - * - * http://www.postgresql.org/docs/8.3/static/libpq-build.html - * - */ - -#include -#include -#include -#include -#include -#include -#include - -// #include -#include - -using namespace std; - -#include "nodeBase.h" /* for ... comnmon definitions, emums and structs */ -#include "nodeUtil.h" -#include "nodeTimers.h" /* */ -#include "daemon_common.h" -#include "daemon_option.h" -#include "daemon_ini.h" - - -typedef std::map mtc_key_value_type ; /* key-value pair array */ -typedef std::vector mtc_query_type ; /* dynamic sized array */ - -typedef struct -{ - PGconn *conn; /* the postgresql connection */ - bool connected; /* true = connected ; false = not connected */ - int equote; /* use E''-style quotes for escaped strings */ - int protocol; /* protocol version */ - int server_version; /* server version */ - const char *encoding; /* client encoding */ - const char *uri; /* Connection URI */ -} pgdb_conn_type ; // formerly SFmDBConn - -class pgdbClass -{ -protected: - const char * get_parameter_status(const char *param); - -public: - pgdbClass(); - ~pgdbClass(); - - pgdb_conn_type pg ; - - int connect (const char *uri); - void disconnect (); - int reconnect (); - int monitor (); - - int query (const char *db_cmd , mtc_query_type & result); - int cmd (const char *db_cmd); -}; - -int pgdbUtil_get_version ( void ); - -#endif /* __INCLUDE_PGDBCLASS_H__ */ diff --git a/mtce-common/src/common/pgdbUtil.cpp.OBS b/mtce-common/src/common/pgdbUtil.cpp.OBS deleted file mode 100644 index a5b9fd6a..00000000 --- a/mtce-common/src/common/pgdbUtil.cpp.OBS +++ /dev/null @@ -1,427 +0,0 @@ -/* - * Copyright (c) 2015 Wind River Systems, Inc. -* -* SPDX-License-Identifier: Apache-2.0 -* - */ - -/** - * @file - * Wind River CGTS Platform PostgreSQL Database Access Utility module. - **/ - -#include "pgdbClass.h" -#include "jsonUtil.h" - -#define CONF_FILE ((const char *)("/etc/ceilometer/ceilometer.conf")) - -/* Cleanup exit handler */ -void daemon_exit ( void ) -{ - exit (0); -} - -void daemon_sigchld_hdlr ( void ) -{ - dlog("Received SIGCHLD ...\n"); -} - - -static daemon_config_type _config ; -static opts_type * opts_ptr ; - - -/* Ceilometer config read */ -int _config_handler ( void * user, - const char * section, - const char * name, - const char * value) -{ - daemon_config_type* config_ptr = (daemon_config_type*)user; - if (MATCH("database", "connection")) - { - config_ptr->ceilometer_url = strdup(value); - if ( config_ptr->ceilometer_url ) - { - ilog ("Ceilometer URL: %s\n", config_ptr->ceilometer_url ); - } - } - return (PASS); -} - - - -daemon_config_type * daemon_get_cfg_ptr (void) -{ - return (&_config); -} - -int daemon_configure ( void ) -{ - int rc = PASS ; - opts_ptr = daemon_get_opts_ptr(); - - daemon_files_init (); - - ilog("Config File : %s\n", CONF_FILE ); - if (ini_parse ( CONF_FILE, _config_handler, &_config ) < 0) - { - elog("Failed to load '%s'\n", CONF_FILE ); - } - return (rc) ; -} - -int daemon_init ( string iface , string nodetype ) -{ - UNUSED(iface); - UNUSED(nodetype); - - daemon_configure (); - - // get_debug_options ( CONF_FILE, &_config ); - return (PASS); -} - -pgdbClass dbConn ; - -#define EXACT_MATCH (0) -#define POSITION_ZERO (0) - -/************************************************************************************ - * - * Ceilometer Database: Sensor Value Correlation - * - * 1. The METER table lists valid meter_ids - * - hardware.ipmi.* - * - * 2. The RESOURCE table lists all the sensors based on internal id - * - hostname-{sensor number-}_ - * ... nokia-2-temp_psu2_(0x94) - * ... controller-1-37-system_board_(0x33) - * - * 3. The SAMPLE table lists sample data as volume based on specified unit type - * - sensor resource lookup - * ... SAMPLE:resource_id == RESOURCE:internal_id - * - SAMPLE:meter_id is used to know it is a valid meter to monitor - * ... METER:id is valid if METER:name has hardware.ipmi in it - * ... hardware.ipmi.current - * - **************************************************************************************/ - -/* Valid meter ids */ -#define PQ_TABLE_INDEX__METER_ID (0) -#define PQ_TABLE_INDEX__METER_NAME (1) -#define PQ_TABLE_INDEX__METER_TYPE (2) -#define PQ_TABLE_INDEX__METER_UNIT (3) - -#define VALID_METER_PREFIX ((const char *)("hardware.ipmi.")) -typedef struct -{ - int id ; - string scope; /* ipmi - VALID_METER_PREFIX */ - string name ; - string unit ; - string type ; -} hwmon_meter_type ; -std::map global_meter_list ; - -#define PQ_TABLE_INDEX__RESOURCE__INTERNAL_ID (0) -#define PQ_TABLE_INDEX__RESOURCE__RESOURCE_ID (1) -#define PQ_TABLE_INDEX__RESOURCE__METADATA (2) -typedef struct -{ - int id ; - string hostname ; - string sensorname ; - string somevalue ; -} hwmon_resource_type ; -std::map global_sensor_list ; -std::map excluded_resource_list ; - -// mtc_key_value_type ipmi_sensor_group -void daemon_service_run ( void ) -{ - int rc = PASS ; - pgdbUtil_get_version (); - if ( ! _config.ceilometer_url ) - { - rc = FAIL_NULL_POINTER ; - } - else - { - PGresult * pqResult_ptr ; - string pqCommand_str; - - ilog ("URI:%s\n", _config.ceilometer_url ); - - // check_connection: - for ( ; ; ) - { - if ( dbConn.pg.connected == false ) - { - elog ("not connected\n"); - sleep (2); - dbConn.connect ( _config.ceilometer_url ); - continue ; - // goto check_connection ; - } - else if ( dbConn.monitor() != PASS ) - { - sleep (2); - continue ; - } - global_meter_list.clear(); - - // ilog ("max number of meters allowed: %zu\n", global_meter_list.max_size()); - - /* PARSE METER - hwmon_get_ipmi_sensor_meters () ; */ - pqCommand_str = "SELECT * FROM meter" ; - pqResult_ptr = PQexec ( dbConn.pg.conn, pqCommand_str.data()); - - // +----+-------------------------------------+------------+--------- - // | id | name | type | unit - // +----+-------------------------------------+------------+--------- - // | 1 | hardware.ipmi.current | gauge | W - // | 2 | hardware.ipmi.temperature | gauge | C - // | 3 | hardware.ipmi.fan | gauge | percent - - if ( PQresultStatus( pqResult_ptr ) == PGRES_TUPLES_OK) - { - hwmon_meter_type meter ; - meter.scope = VALID_METER_PREFIX ; - int rows = PQntuples(pqResult_ptr); - for(int i=0; i sizeof(int)) ) - { - meter.id = atoi(meter_id.data()); - global_meter_list.insert (std::make_pair(meter.id, meter )); - dlog3 ("ipmi sensor group %d '%s' (%s:%s)\n", - meter.id, meter.name.c_str(), - meter.type.c_str(), meter.unit.c_str()); - } - } - } - } /* end 'meters rows parse' for loop */ - - if ( global_meter_list.size() ) - { - // ************** Testing ********************* -#define WANT_QUERY_AUTO_ITERATOR_TEST - -#ifdef WANT_QUERY_DECLARED_ITERATOR_TEST - /* TEST: Query Meters using declared iterator */ - std::map::const_iterator global_meter_list_iter = global_meter_list.begin(); - while ( global_meter_list_iter != global_meter_list.end() ) - { - ilog ("ipmi sensor group %d '%s' (%s:%s)\n", - global_meter_list_iter->second.id, - global_meter_list_iter->second.name.c_str(), - global_meter_list_iter->second.type.c_str(), - global_meter_list_iter->second.unit.c_str()); - - ++global_meter_list_iter ; - } -#endif - -#ifdef WANT_QUERY_AUTO_ITERATOR_TEST - /* TEST: Loop Over meter List using C++11 auto iterator */ - for ( auto _iter = global_meter_list.begin() ; _iter != global_meter_list.end() ; _iter++ ) - { - dlog ("ipmi sensor group %d '%s' (%s:%s)\n", - _iter->second.id, - _iter->second.name.c_str(), - _iter->second.type.c_str(), - _iter->second.unit.c_str()); - } -#endif - -#ifdef WANT_FIND_TEST - /* TEST: Find meters test */ - for ( int i = 0 ; i < 1000 ; i++ ) - { - global_meter_list_iter = global_meter_list.find(i); - if ( global_meter_list_iter != global_meter_list.end() ) - { - ilog ("ipmi sensor group query test - %d:%d '%s' (%s:%s)\n", - i, - global_meter_list_iter->second.id, - global_meter_list_iter->second.name.c_str(), - global_meter_list_iter->second.type.c_str(), - global_meter_list_iter->second.unit.c_str()); - } - } -#endif - ilog ( "%zu sensor groups total\n", global_meter_list.size() ); - - - /* PARSE RESOURCE - hwmon_get_ipmi_sensor_list () ; */ - pqCommand_str = "SELECT internal_id,resource_id,resource_metadata FROM resource" ; - pqResult_ptr = PQexec ( dbConn.pg.conn, pqCommand_str.data()); - - // +-------------+--------------------------------------+-----------------------------+ - // | internal_id | resource_id | resource_metadata - // | 1 | controller-0-power_meter_(0x40) | {"node": "controller-0"} - // | 2 | controller-0-26-ilo_zone_(0x26) | {"node": "controller-0"} - // | 3 | controller-0-fan_2_(0x7) | {"node": "controller-0"} - - if ( PQresultStatus( pqResult_ptr ) == PGRES_TUPLES_OK) - { - hwmon_resource_type resource ; - - int rows = PQntuples(pqResult_ptr); - for(int i=0; i sizeof(int)) ) - { - resource.id = atoi(internal_id.data()); - } - else - { - elog ("failed to convert internal_id:%s to integer ; excluded '%s'\n", internal_id.c_str(), resource_id.c_str()); - continue ; - } - - /* Add those that have a valid hostname as metadata key:value pair { node: "" } */ - - if ( metadata.size() && ( jsonUtil_get_key_val ( (char*)metadata.data(), "node", hostname ) == PASS )) - { - resource.hostname = hostname ; - if ( resource_id.find (hostname, POSITION_ZERO ) == POSITION_ZERO ) - { - /* Get somevalue */ - resource.somevalue.clear(); - resource.sensorname = resource_id.substr ( hostname.length()); - size_t index = resource.sensorname.find ("_(0x"); - if ( index != std::string::npos ) - { - resource.somevalue = resource.sensorname.substr (index+1); - } - resource.sensorname = resource_id.substr ( hostname.length()+1, index-1 ); - global_sensor_list.insert (std::make_pair(resource.id, resource )); - added = true ; - dlog ("added - %s %s\n", hostname.c_str(), resource.sensorname.c_str()); - } - } - else - { - elog ("no valid metadata node:hostname key value pair (%s) ; excluded %s\n", metadata.c_str(), resource_id.c_str() ); - } - - if ( added == false ) - { - resource.hostname = "none" ; - resource.sensorname = resource_id ; - resource.somevalue = metadata ; - excluded_resource_list.insert(std::make_pair(resource.id, resource )); - } - } /* end 'resource rows parse' for loop */ - } - if ( global_sensor_list.size() ) - { - /* Loop over meter List using C++11 auto iterator */ - for ( auto _iter = global_sensor_list.begin() ; _iter != global_sensor_list.end() ; _iter++ ) - { - dlog ("%s %d sensor '%s' %s\n", - _iter->second.hostname.c_str(), - _iter->second.id, - _iter->second.sensorname.c_str(), - _iter->second.somevalue.c_str()); - } - } -#ifdef WANT_DISPLAY_EXCLUDED_METERS_LIST - if ( excluded_resource_list.size() ) - { - /* Loop over meter List using C++11 auto iterator */ - for ( auto _iter = excluded_resource_list.begin() ; _iter != excluded_resource_list.end() ; _iter++ ) - { - ilog ("excluded %d '%s' (%s)\n", - _iter->second.id, - _iter->second.sensorname.c_str(), - _iter->second.somevalue.c_str()); - } - } -#endif - ilog ("%zu sensors ; system wide and %zu meter resources excluded\n", - global_sensor_list.size(), - excluded_resource_list.size()); - - /* SELECT id,volume,timestamp,meter_id,resource_id FROM sample WHERE timestamp >= '2016-11-22 21:57:45' AND resource_id = 149; */ - /* PARSE RESOURCE - hwmon_get_ipmi_sensor_list () ; - pqCommand_str = "SELECT internal_id,resource_id,resource_metadata FROM resource" ; - pqResult_ptr = PQexec ( dbConn.pg.conn, pqCommand_str.data()); -*/ - // +-------------+--------------------------------------+-----------------------------+ - // | internal_id | resource_id | resource_metadata - // | 1 | controller-0-power_meter_(0x40) | {"node": "controller-0"} - // | 2 | controller-0-26-ilo_zone_(0x26) | {"node": "controller-0"} - // | 3 | controller-0-fan_2_(0x7) | {"node": "controller-0"} - - //if ( PQresultStatus( pqResult_ptr ) == PGRES_TUPLES_OK) - //{ - - // Query all samples based on the last - // - keep track of sample ID numbers to discard already managed samples - // for each host - // for each sensor - - } - else - { - elog ("no data retrieved for command '%s'\n", pqCommand_str.c_str()); - } - - PQclear (pqResult_ptr); - - /* TODO: Group these 2 commands into an _fini proc */ - //PQfinish(dbConn.pg.conn); - //dbConn.pg.conn = NULL ; - } - } - } - ilog ("RC:%d\n", rc ); -} - -/* STUBS */ - -/* Push daemon state to log file */ -void daemon_dump_info ( void ) -{ - daemon_dump_membuf_banner (); - daemon_dump_membuf(); -} - - -int daemon_run_testhead ( void ) -{ - return PASS ; -} - - -const char * dummy = "empty" ; -const char * daemon_stream_info ( void ) -{ - return (dummy) ; -} diff --git a/mtce-common/src/common/tokenUtil.cpp b/mtce-common/src/common/tokenUtil.cpp index adca5106..5ab592a5 100644 --- a/mtce-common/src/common/tokenUtil.cpp +++ b/mtce-common/src/common/tokenUtil.cpp @@ -858,10 +858,5 @@ int keystone_config_handler ( void * user, config_ptr->keystone_region_name = strdup(value); ilog("Region Name : %s\n", config_ptr->keystone_region_name ); } - else if (MATCH("agent", "ceilometer_port")) - { - config_ptr->ceilometer_port = atoi(value); - dlog("Ceilometer Port : %d\n", config_ptr->ceilometer_port ); - } return (PASS); } diff --git a/mtce/src/hwmon/hwmonHttp.cpp b/mtce/src/hwmon/hwmonHttp.cpp index d614f811..607dcca5 100644 --- a/mtce/src/hwmon/hwmonHttp.cpp +++ b/mtce/src/hwmon/hwmonHttp.cpp @@ -36,10 +36,6 @@ #include "hwmonSensor.h" /* for ... hwmonSensor_print */ #include "hwmonAlarm.h" /* for ... hwmonAlarm */ -//ceilometer/ceilometer.conf port=8777 -//ceilometer/ceilometer.conf host=192.168.204.2 - - static event_type hwmon_event ; diff --git a/mtce/src/hwmon/hwmonHttp.h b/mtce/src/hwmon/hwmonHttp.h index cc567f82..3e6545a8 100644 --- a/mtce/src/hwmon/hwmonHttp.h +++ b/mtce/src/hwmon/hwmonHttp.h @@ -47,7 +47,6 @@ typedef struct * 1. the HTTP Client API for * - configuring sysinv with sensor data records as well as modifying * and querying those records. - * - pushing sensor samples to ceilometer * * 2. the HTTP Server handler that services sysinv sensor configuration * change notifications. diff --git a/mtce/src/pmon/scripts/pmon-test.sh b/mtce/src/pmon/scripts/pmon-test.sh index 4bf4af33..2180f879 100755 --- a/mtce/src/pmon/scripts/pmon-test.sh +++ b/mtce/src/pmon/scripts/pmon-test.sh @@ -23,7 +23,6 @@ # controller-0:~# /home/wrsroot/pmon-test.sh restart # # acpid restart PASSED [651]:[19095] -# ceilometer-polling restart PASSED [13844]:[22519] # fsmond restart PASSED [8719]:[26343] # guestServer restart PASSED [8710]:[29108] # hbsClient restart PASSED [8729]:[31248]