Browse Source

Remove snmp-ext and snmp-audittrail from FM

Remove the libraries libcgtsAgentPlugin and libsnmpAuditPlugin of Fault
Management old net-snmp implementation within Starlingx, to delete the
implementation of non-containerized SNMP.

Story: 2008132
Task: 40866
Signed-off-by: Gonzalo Gallardo <gonzalo.gallardo@windriver.com>

Depends-On: https://review.opendev.org/765381
Change-Id: I3aab46cbd45ae7be9e3f97b3acae0fe4536d1388
changes/75/765875/8
Gonzalo Gallardo 7 months ago
parent
commit
b8bfdbebea
23 changed files with 1 additions and 2893 deletions
  1. +0
    -6
      centos_iso_image.inc
  2. +1
    -2
      centos_pkg_dirs
  3. +0
    -2
      snmp-audittrail/centos/build_srpm.data
  4. +0
    -55
      snmp-audittrail/centos/snmp-audittrail.spec
  5. +0
    -14
      snmp-audittrail/opensuse/snmp-audittrail.changes
  6. +0
    -1
      snmp-audittrail/opensuse/snmp-audittrail.rpmlintrc
  7. +0
    -61
      snmp-audittrail/opensuse/snmp-audittrail.spec
  8. +0
    -202
      snmp-audittrail/sources/LICENSE
  9. +0
    -30
      snmp-audittrail/sources/Makefile
  10. +0
    -422
      snmp-audittrail/sources/snmpAuditPlugin.c
  11. +0
    -2
      snmp-ext/centos/build_srpm.data
  12. +0
    -60
      snmp-ext/centos/snmp-ext.spec
  13. +0
    -9
      snmp-ext/opensuse/snmp-ext.changes
  14. +0
    -1
      snmp-ext/opensuse/snmp-ext.rpmlintrc
  15. +0
    -67
      snmp-ext/opensuse/snmp-ext.spec
  16. +0
    -202
      snmp-ext/sources/LICENSE
  17. +0
    -40
      snmp-ext/sources/Makefile
  18. +0
    -266
      snmp-ext/sources/cgtsActiveAlarms.c
  19. +0
    -164
      snmp-ext/sources/cgtsAgentPlugin.c
  20. +0
    -69
      snmp-ext/sources/cgtsAgentPlugin.h
  21. +0
    -268
      snmp-ext/sources/cgtsEventLogs.c
  22. +0
    -818
      snmp-ext/sources/mibs/wrsAlarmMib.mib.txt
  23. +0
    -132
      snmp-ext/sources/mibs/wrsEnterpriseReg.mib.txt

+ 0
- 6
centos_iso_image.inc View File

@ -14,12 +14,6 @@ fm-mgr
# fm-doc
fm-doc
# snmp-ext
snmp-ext
# snmp-audittrail
snmp-audittrail
# fm-rest-api
fm-rest-api


+ 1
- 2
centos_pkg_dirs View File

@ -4,5 +4,4 @@ fm-mgr
fm-doc
fm-rest-api
python-fmclient
snmp-ext
snmp-audittrail

+ 0
- 2
snmp-audittrail/centos/build_srpm.data View File

@ -1,2 +0,0 @@
SRC_DIR="sources"
TIS_PATCH_VER=PKG_GITREVCOUNT

+ 0
- 55
snmp-audittrail/centos/snmp-audittrail.spec View File

@ -1,55 +0,0 @@
Summary: StarlingX SNMP Audit Trail
Name: snmp-audittrail
Version: 1.0
Release: %{tis_patch_ver}%{?_tis_dist}
License: Apache-2.0
Group: base
Packager: Wind River <info@windriver.com>
URL: unknown
Source0: %{name}-%{version}.tar.gz
BuildRequires: net-snmp-devel
BuildRequires: fm-common-dev
BuildRequires: uuid-devel
BuildRequires: uuid
BuildRequires: libuuid-devel
Requires: net-snmp
Requires: uuid
%description
StarlingX SNMP Audit Trail provides audit trail support for incoming
SNMP requests.
%package -n snmp-audittrail-devel
Summary: StarlingX SNMP Audit Trail Package - Development files
Group: devel
Requires: snmp-audittrail = %{version}-%{release}
%description -n snmp-audittrail-devel
StarlingX SNMP Audit Trail provides audit trail support for incoming SNMP requests.
This package contains symbolic links, header files, and related items necessary
for software development.
%prep
%setup
%build
VER=%{version}
MAJOR=`echo $VER | awk -F . '{print $1}'`
MINOR=`echo $VER | awk -F . '{print $2}'`
make MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver} %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
VER=%{version}
MAJOR=`echo $VER | awk -F . '{print $1}'`
MINOR=`echo $VER | awk -F . '{print $2}'`
make install DESTDIR=$RPM_BUILD_ROOT LIB_DIR=%{_libdir} MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver}
%files
%defattr(-,root,root,-)
%doc LICENSE
%{_libdir}/*.so.*
%files -n snmp-audittrail-devel
%defattr(-,root,root,-)
%{_libdir}/*.so

+ 0
- 14
snmp-audittrail/opensuse/snmp-audittrail.changes View File

@ -1,14 +0,0 @@
-------------------------------------------------------------------
Thu Jun 13 20:56:01 UTC 2019 - sgw@linux.intel.com
- convert from tarball to _service file
-------------------------------------------------------------------
Mon Jun 10 23:21:36 UTC 2019 - sgw@linux.intel.com
- spec-cleaner and rpmlint checked
-------------------------------------------------------------------
Thu May 23 20:39:25 UTC 2019 - sgw@bigsur.com
- Initial Commit

+ 0
- 1
snmp-audittrail/opensuse/snmp-audittrail.rpmlintrc View File

@ -1 +0,0 @@
setBadness('script-without-shebang', 2)

+ 0
- 61
snmp-audittrail/opensuse/snmp-audittrail.spec View File

@ -1,61 +0,0 @@
Name: snmp-audittrail
Version: 1.0.0
Release: %{tis_patch_ver}%{?_tis_dist}
Summary: StarlingX SNMP Audit Trail
License: Apache-2.0
Group: Development/Tools/Other
URL: https://opendev.org/starlingx/fault
Source0: %{name}-%{version}.tar.gz
BuildRequires: fm-common-devel
BuildRequires: libuuid-devel
BuildRequires: net-snmp-devel
BuildRequires: uuid-devel
Requires: net-snmp
Requires: uuid
%if 0%{?suse_version}
BuildRequires: gcc-c++
%endif
%description
StarlingX SNMP Audit Trail provides audit trail support for incoming
SNMP requests.
%package -n snmp-audittrail-devel
Summary: StarlingX SNMP Audit Trail Package - Development files
Group: Development/Tools/Other
Requires: snmp-audittrail = %{version}-%{release}
%description -n snmp-audittrail-devel
StarlingX SNMP Audit Trail provides audit trail support for incoming SNMP requests.
This package contains symbolic links, header files, and related items necessary
for software development.
%prep
%autosetup -n %{name}-%{version}/sources
%build
VER=%{version}
MAJOR=`echo $VER | awk -F . '{print $1}'`
MINOR=`echo $VER | awk -F . '{print $2}'`
make MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver} %{?_smp_mflags}
%install
VER=%{version}
MAJOR=`echo $VER | awk -F . '{print $1}'`
MINOR=`echo $VER | awk -F . '{print $2}'`
make install DESTDIR=%{buildroot} LIB_DIR=%{_libdir} MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%defattr(-,root,root,-)
%license LICENSE
%{_libdir}/*.so.*
%files -n snmp-audittrail-devel
%defattr(-,root,root,-)
%{_libdir}/*.so
%changelog

+ 0
- 202
snmp-audittrail/sources/LICENSE View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

+ 0
- 30
snmp-audittrail/sources/Makefile View File

@ -1,30 +0,0 @@
SRCS = snmpAuditPlugin.c
OBJS = $(SRCS:.c=.o)
LDLIBS = -lfmcommon -lnetsnmp -lnetsnmpagent -luuid
INCLUDES += -I./
CCFLAGS = -fPIC -g -O2 -Wall -Werror -Wformat -Wformat-security
LIBCGTSAGENT_SO := libsnmpAuditPlugin.so
MAJOR ?= 1
MINOR ?= 0
PATCH ?= 0
DESTDIR ?= /usr/lib64
build: lib
.c.o:
$(CXX) $(CCFLAGS) $(INCLUDES) -c $< -o $@
lib: $(OBJS)
$(CXX) $(OBJS) $(LDLIBS) -o $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) -shared
ln -sf $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(LIBCGTSAGENT_SO).$(MAJOR)
ln -sf $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(LIBCGTSAGENT_SO)
clean:
@rm -f $(OBJ) *.o *.so.*
install:
install -m 755 -d $(DESTDIR)$(LIB_DIR)
install -m 755 $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DESTDIR)$(LIB_DIR)
ln -s $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DESTDIR)$(LIB_DIR)/$(LIBCGTSAGENT_SO).$(MAJOR)
ln -s $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DESTDIR)$(LIB_DIR)/$(LIBCGTSAGENT_SO)

+ 0
- 422
snmp-audittrail/sources/snmpAuditPlugin.c View File

@ -1,422 +0,0 @@
/*
* Copyright (c) 2017 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <arpa/inet.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/net-snmp-features.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/library/callback.h>
#include <net-snmp/library/snmp_transport.h>
#include <net-snmp/library/snmp_api.h>
#include <net-snmp/library/mib.h>
#include <net-snmp/library/snmp.h>
#include <net-snmp/library/vacm.h>
#include <net-snmp/library/snmpUDPDomain.h>
#include <net-snmp/library/tools.h>
#include <net-snmp/agent/agent_callbacks.h>
#include <net-snmp/agent/agent_handler.h>
#include <net-snmp/agent/agent_registry.h>
#define LOG_BUF_STR (256)
#define AUDIT_TAG "snmp-auditor"
/* Used to keep track of the first handler call for a transaction */
typedef struct s_audit_req_t {
long transid;
long reqid;
} audit_req_t;
typedef struct s_enum_to_string_t {
const int enumval;
const char *str;
} enum_to_string_t;
/* Logs IP session information, in the format: "remote IP:port ==> local IP:port" */
static inline char* fmtaddr(const char *prefix, int af,
void *remote_addr, unsigned short remote_port,
char*buf, size_t buflen)
{
char remote_addr_str[LOG_BUF_STR+1];
if (NULL == inet_ntop(af, remote_addr, remote_addr_str, sizeof(remote_addr_str))) {
strncpy(remote_addr_str, "UNKNOWN", LOG_BUF_STR+1);
}
remote_addr_str[LOG_BUF_STR] = 0;
snprintf(buf, buflen, "transport:%s remote:%s", prefix, remote_addr_str);
return buf;
}
#ifdef NETSNMP_ENABLE_IPV6
static char* ipv6_fmtaddr(const char *prefix, netsnmp_addr_pair *addr_pair, char*buf, size_t buflen)
{
return fmtaddr(prefix, AF_INET6,
(void *)&addr_pair->remote_addr.sin6.sin6_addr, addr_pair->remote_addr.sin6.sin6_port,
buf, buflen);
}
#endif
static char* ipv4_fmtaddr(const char *prefix, netsnmp_addr_pair *addr_pair, char*buf, size_t buflen)
{
return fmtaddr(prefix, AF_INET,
(void *)&addr_pair->remote_addr.sin.sin_addr, addr_pair->remote_addr.sin.sin_port,
buf, buflen);
}
/* Logs IP session information */
static char* log_session_addresses(const oid* tDomain, netsnmp_addr_pair *addr_pair, char*buf, size_t buflen)
{
if (tDomain == netsnmpUDPDomain) {
return ipv4_fmtaddr("udp", addr_pair, buf, buflen);
}
if (tDomain == netsnmp_snmpTCPDomain) {
return ipv4_fmtaddr("tcp", addr_pair, buf, buflen);
}
#ifdef NETSNMP_ENABLE_IPV6
if (tDomain == netsnmp_UDPIPv6Domain) {
return ipv6_fmtaddr("udpv6", addr_pair, buf, buflen);
}
if (tDomain == netsnmp_TCPIPv6Domain) {
return ipv6_fmtaddr("tcpv6", addr_pair, buf, buflen);
}
#endif
strncpy(buf, "IP FMT ERROR", buflen);
buf[buflen-1] = 0;
return buf;
}
/* SNMP OID formatting (a wrapper around the 'standard' function */
static inline char* fmtoid(const oid * theoid, size_t len, int* no_overflow)
{
u_char *buf = NULL;
size_t buf_len = 0;
size_t out_len = 0;
*no_overflow = sprint_realloc_objid(&buf, &buf_len, &out_len, 1, theoid, len);
if (NULL == buf) {
*no_overflow = 0;
}
return (char*)buf;
}
/* SNMP var bind formatting (a convenience function) - formats the OID (variable name)
This function is always called with var != NULL */
static inline char* fmtmsg_var(netsnmp_variable_list * var, int* no_overflow)
{
return fmtoid(var->name, var->name_length, no_overflow);
}
static const char* get_version(long version)
{
switch (version) {
case 0: return "v1";
case 1: return "v2c";
case 2: return "v3";
}
return "error";
}
static const char *get_str_from_enum(int enumval, const enum_to_string_t* table, const char* defval)
{
const enum_to_string_t* ptr = table;
for ( ; ptr->str != NULL; ++ptr) {
if (ptr->enumval == enumval) {
return ptr->str;
}
}
if (NULL == defval) {
return "unknown";
}
return defval;
}
static const char *get_auth_error(int errorcode)
{
static enum_to_string_t errorcodes_str[] = {
{ VACM_SUCCESS, "Success", },
{ VACM_NOSECNAME, "InvalidCommunityName" },
{ VACM_NOGROUP, "NoGroup" },
{ VACM_NOACCESS, "NoAccess" },
{ VACM_NOVIEW, "NoViewAccess" },
{ VACM_NOTINVIEW, "NotInView" },
{ VACM_NOSUCHCONTEXT, "NoSuchContext" },
{ VACM_SUBTREE_UNKNOWN,"SubtreeUnknown" },
{0, NULL}
};
return get_str_from_enum(errorcode, errorcodes_str, "unknown err");
}
static const char *get_result_error(int errorcode)
{
static enum_to_string_t errorcodes_str[] = {
{ 0, "pass" },
{ SNMP_NOSUCHOBJECT, "NoSuchObject" },
{ SNMP_NOSUCHINSTANCE, "NoSuchInstance" },
{ SNMP_ENDOFMIBVIEW, "EndOfMIBView" },
{0, NULL}
};
return get_str_from_enum(errorcode, errorcodes_str, "pass");
}
/* Logs all var-binds in PDU (only variable names, aka OID's) */
static void log_var_list(netsnmp_pdu *pdu)
{
netsnmp_variable_list * var;
for (var = pdu->variables; var != NULL; var = var->next_variable) {
int no_overflow_var = 0;
char* var_str = fmtmsg_var(var, &no_overflow_var);
snmp_log(LOG_INFO, AUDIT_TAG" reqid:%ld oid:%s%s\n",
pdu->reqid,
(var_str != NULL) ? var_str : "INVALID",
(no_overflow_var) ? "" : " [TRUNCATED]");
free(var_str);
}
}
/* Logs the 'header' of a PDU/request (IP addresses, reqid, msg type, version) */
static void log_pdu_header(netsnmp_pdu *pdu, const char *status)
{
char buf[LOG_BUF_STR];
netsnmp_addr_pair *addr_pair = (netsnmp_addr_pair *)pdu->transport_data;
snmp_log(LOG_INFO, AUDIT_TAG" %s reqid:%ld msg-type:%s version:%s%s\n",
log_session_addresses(pdu->tDomain, addr_pair, buf, sizeof(buf)),
pdu->reqid, snmp_pdu_type(pdu->command), get_version(pdu->version), status);
}
/* Logs the results of a request, namely results obtained from actual processing handlers */
static void log_results(long reqid, netsnmp_request_info *requests)
{
netsnmp_request_info *req;
for (req = requests; req != NULL; req = req->next) {
netsnmp_variable_list *var = req->requestvb;
if (NULL == var) {
continue;
}
if (var->type != ASN_NULL) { /* NULL means no result, so skip */
int no_overflow_var = 0;
char* var_str = fmtmsg_var(var, &no_overflow_var);
/* Print only first variable: this is the request that we get a result for */
snmp_log(LOG_INFO, AUDIT_TAG" reqid:%ld oid:%s%s status:%s\n", reqid,
(var_str != NULL) ? var_str : "INVALID",
(no_overflow_var) ? "" : " [TRUNCATED]", get_result_error(var->type));
free(var_str);
}
}
}
static void log_invalid_oid_trees(netsnmp_pdu *pdu)
{
char buf[LOG_BUF_STR];
netsnmp_variable_list *var;
netsnmp_addr_pair *addr_pair = (netsnmp_addr_pair *)pdu->transport_data;
int first_time = 1;
for (var = pdu->variables; var != NULL; var = var->next_variable) {
netsnmp_subtree *tp = netsnmp_subtree_find(var->name, var->name_length,
NULL, pdu->contextName);
if (tp != NULL) {
int prefix_len = netsnmp_oid_find_prefix(tp->start_a,
tp->start_len,
tp->end_a, tp->end_len);
while (prefix_len < 1) {
tp = tp->next;
if (NULL == tp) {
break;
}
prefix_len = netsnmp_oid_find_prefix(tp->start_a,
tp->start_len,
tp->end_a, tp->end_len);
}
DEBUGMSGTL(("helper:snmpAudit", "var=%p tp=%p prefix_len=%d\n", var, tp, prefix_len ));
}
else {
DEBUGMSGTL(("helper:snmpAudit", "tp NOT found var=%p\n", var));
}
if (NULL == tp) {
int no_overflow_var = 0;
char* var_str = fmtmsg_var(var, &no_overflow_var);
if (first_time) {
first_time = 0;
snmp_log(LOG_INFO, AUDIT_TAG" %s reqid:%ld msg-type:%s version:%s\n",
log_session_addresses(pdu->tDomain, addr_pair, buf, sizeof(buf)), pdu->reqid,
snmp_pdu_type(pdu->command),
get_version(pdu->version));
log_var_list(pdu);
}
snmp_log(LOG_INFO, AUDIT_TAG" reqid:%ld oid:%s%s status:%s\n",
pdu->reqid,
(var_str != NULL) ? var_str : "INVALID",
(no_overflow_var) ? "" : " [TRUNCATED]",
get_result_error(SNMP_ENDOFMIBVIEW));
free(var_str);
}
}
}
/*
* Register with 'SNMPD_CALLBACK_ACM_CHECK_INITIAL == minorId'
* This function is used to log authorization errors and invalid OID's errors,
* for GET BULK and GET NEXT requests
*/
static int audit_callback_acm_check_initial(int majorID, int minorID, void *serverarg,
void *clientarg)
{
struct view_parameters *view_parms =
(struct view_parameters *) serverarg;
netsnmp_pdu *pdu = view_parms->pdu;
DEBUGMSGTL(("helper:snmpAudit", "%s msg-type: %s errcode=%d minorID=%d\n",
__FUNCTION__, snmp_pdu_type(pdu->command), view_parms->errorcode, minorID));
if (view_parms->errorcode != VACM_SUCCESS) {
/* Log Authentication errors */
char buf[LOG_BUF_STR];
netsnmp_addr_pair *addr_pair = (netsnmp_addr_pair *)pdu->transport_data;
snmp_log(LOG_INFO, AUDIT_TAG" %s reqid:%ld msg-type:%s version:%s status:%s\n",
log_session_addresses(pdu->tDomain, addr_pair, buf, sizeof(buf)), pdu->reqid,
snmp_pdu_type(pdu->command), get_version(pdu->version),
get_auth_error(view_parms->errorcode));
log_var_list(pdu);
return 0;
}
if (SNMP_MSG_GETBULK == pdu->command ||
SNMP_MSG_GETNEXT == pdu->command) {
/* Log possible invalid OID subtrees for GETNEXT and GETBULK request
* (e.g. "1.10" - outside the normal ISO MIB subtree)
*/
log_invalid_oid_trees(pdu);
}
return 0;
}
/*
* Register with 'SNMPD_CALLBACK_ACM_CHECK == minorId'
* This function is used to log SET requests (which are normally rejected)
*/
static int audit_callback_acm_check(int majorID, int minorID, void *serverarg,
void *clientarg)
{
struct view_parameters *view_parms =
(struct view_parameters *) serverarg;
netsnmp_pdu *pdu = view_parms->pdu;
DEBUGMSGTL(("helper:snmpAudit", "%s msg-type: %s errcode=%d minorID=%d\n",
__FUNCTION__, snmp_pdu_type(pdu->command), view_parms->errorcode, minorID));
if (SNMP_MSG_SET == pdu->command) {
char status_buf[LOG_BUF_STR];
snprintf(status_buf, LOG_BUF_STR,
" status:%s", get_auth_error(view_parms->errorcode));
log_pdu_header(pdu, status_buf);
log_var_list(pdu);
}
return 0;
}
/* Main log handler function: logs 'normal' requests:
* everything except SET operations, authentication errors and GETBULK/GETNEXT for invalid OIDs */
static int audit_log_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
static audit_req_t req = {
.transid = 0,
.reqid = 0
};
netsnmp_pdu *orig_pdu = reqinfo->asp->orig_pdu;
int ret;
/* Note. Assumes single-threaded processing. */
if ((req.transid != orig_pdu->transid) &&
(req.reqid != orig_pdu->reqid)) {
/* New transaction */
req.transid = orig_pdu->transid;
req.reqid = orig_pdu->reqid;
/* Logs session information (e.g. IP addresses, version...) */
log_pdu_header(orig_pdu, "");
/* Logs the variables names in the request */
log_var_list(orig_pdu);
}
/* Calls the next handlers, to obtain processing results */
ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
/* Logs the variables names in the results
* resulted from the calls to 'netsnmp_call_next_handler' above
* which invokes all other handlers in the chain.
*/
log_results(orig_pdu->reqid, requests);
return ret;
}
/*
* Initialization routine, automatically called by the agent
* (to get called, the function name must match init_FILENAME())
*/
extern "C" void init_snmpAuditPlugin(void) {
netsnmp_mib_handler *audit_handler = NULL;
snmp_log(LOG_INFO, "init_snmpAuditPlugin\n");
audit_handler = netsnmp_create_handler("snmpAudit",
audit_log_handler);
if (audit_handler != NULL) {
netsnmp_register_handler_by_name("snmpAudit", audit_handler);
}
netsnmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_ACM_CHECK,
audit_callback_acm_check,
NULL, NETSNMP_CALLBACK_LOWEST_PRIORITY );
netsnmp_register_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_ACM_CHECK_INITIAL,
audit_callback_acm_check_initial,
NULL, NETSNMP_CALLBACK_LOWEST_PRIORITY);
}
extern "C" void deinit_snmpAuditPlugin(void)
{
snmp_log(LOG_INFO, "deinit_snmpAuditPlugin\n");
snmp_unregister_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_ACM_CHECK,
audit_callback_acm_check, NULL, 1);
snmp_unregister_callback(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_ACM_CHECK_INITIAL,
audit_callback_acm_check_initial, NULL, 1);
}

+ 0
- 2
snmp-ext/centos/build_srpm.data View File

@ -1,2 +0,0 @@
SRC_DIR="sources"
TIS_PATCH_VER=PKG_GITREVCOUNT

+ 0
- 60
snmp-ext/centos/snmp-ext.spec View File

@ -1,60 +0,0 @@
Summary: CGTS Platform SNMP extension Package
Name: snmp-ext
Version: 1.0
Release: %{tis_patch_ver}%{?_tis_dist}
License: Apache-2.0
Group: base
Packager: Wind River <info@windriver.com>
URL: unknown
Source0: %{name}-%{version}.tar.gz
BuildRequires: fm-common-dev
BuildRequires: net-snmp-devel
BuildRequires: libuuid-devel
Requires: fm-common
Requires: net-snmp
%define mib_ver 2.0
%description
StarlingX platform SNMP extension provides Wind River enterprise MIBs support
and it serves as SNMP based alarm surveillance module for Network Manager
System.
%package -n snmp-ext-devel
Summary: StarlingX Platform SNMP extension Package - Development files
Group: devel
Requires: snmp-ext = %{version}-%{release}
%description -n snmp-ext-devel
StarlingX platform SNMP extension provides Wind River enterprise MIBs support
and it serves as SNMP based alarm surveillance module for Network Manager
System. This package contains symbolic links, header files, and related
items necessary for software development.
%prep
%setup
%build
MAJOR=`echo %{version} | awk -F . '{print $1}'`
MINOR=`echo %{version} | awk -F . '{print $2}'`
make MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver} %{?_smp_mflags}
%install
MAJOR=`echo %{version} | awk -F . '{print $1}'`
MINOR=`echo %{version} | awk -F . '{print $2}'`
make DEST_DIR=%{buildroot} \
LIB_DIR=%{_libdir} \
MAJOR=$MAJOR \
MINOR=$MINOR \
MIBVER=%{mib_ver} \
PATCH=%{tis_patch_ver} install
%files
%defattr(-,root,root,-)
%doc LICENSE
%{_libdir}/*.so.*
%{_datadir}/snmp/mibs/*
%files -n snmp-ext-devel
%defattr(-,root,root,-)
%{_libdir}/*.so

+ 0
- 9
snmp-ext/opensuse/snmp-ext.changes View File

@ -1,9 +0,0 @@
-------------------------------------------------------------------
Mon Jun 10 23:47:39 UTC 2019 - sgw@linux.intel.com
- spec-cleaner and rpmlint checked
-------------------------------------------------------------------
Thu May 23 21:03:10 UTC 2019 - sgw@bigsur.com
- Initial Commit

+ 0
- 1
snmp-ext/opensuse/snmp-ext.rpmlintrc View File

@ -1 +0,0 @@
setBadness('script-without-shebang', 2)

+ 0
- 67
snmp-ext/opensuse/snmp-ext.spec View File

@ -1,67 +0,0 @@
%define mib_ver 2.0
Name: snmp-ext
Version: 1.0.0
Release: %{tis_patch_ver}%{?_tis_dist}
Summary: StarlingX Platform SNMP extension Package
License: Apache-2.0
Group: Development/Tools/Other
URL: https://opendev.org/starlingx/fault
Source0: %{name}-%{version}.tar.gz
BuildRequires: fm-common-devel
BuildRequires: libuuid-devel
BuildRequires: net-snmp-devel
Requires: fm-common
Requires: net-snmp
%if 0%{?suse_version}
BuildRequires: gcc-c++
%endif
%description
StarlingX Cloud platform SNMP extension provides Wind River enterprise MIBs support
and it serves as SNMP based alarm surveillance module for Network Manager
System.
%package -n snmp-ext-devel
Summary: StarlingX Cloud Platform SNMP extension Package - Development files
Group: Development/Tools/Other
Requires: snmp-ext = %{version}-%{release}
%description -n snmp-ext-devel
StarlingX Cloud platform SNMP extension provides Wind River enterprise MIBs support
and it serves as SNMP based alarm surveillance module for Network Manager
System. This package contains symbolic links, header files, and related
items necessary for software development.
%prep
%autosetup -n %{name}-%{version}/sources
%build
MAJOR=`echo %{version} | awk -F . '{print $1}'`
MINOR=`echo %{version} | awk -F . '{print $2}'`
make MAJOR=$MAJOR MINOR=$MINOR PATCH=%{tis_patch_ver} %{?_smp_mflags}
%install
MAJOR=`echo %{version} | awk -F . '{print $1}'`
MINOR=`echo %{version} | awk -F . '{print $2}'`
make DEST_DIR=%{buildroot} \
LIB_DIR=%{_libdir} \
MAJOR=$MAJOR \
MINOR=$MINOR \
MIBVER=%{mib_ver} \
PATCH=%{tis_patch_ver} install
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files
%defattr(-,root,root,-)
%license LICENSE
%{_libdir}/*.so.*
%{_datadir}/snmp/mibs/*
%files -n snmp-ext-devel
%defattr(-,root,root,-)
%{_libdir}/*.so
%changelog

+ 0
- 202
snmp-ext/sources/LICENSE View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

+ 0
- 40
snmp-ext/sources/Makefile View File

@ -1,40 +0,0 @@
#
# SPDX-License-Identifier: Apache-2.0
#
MAJOR ?= 1
MINOR ?= 0
PATCH ?= 0
MIBVER ?= 2.0
DEST_DIR ?= /
DATA_DIR ?= /usr/share
LIB_DIR ?= /usr/lib64
SRCS = cgtsActiveAlarms.c cgtsAgentPlugin.c cgtsEventLogs.c
OBJS = $(SRCS:.c=.o)
LDLIBS = -lfmcommon -lnetsnmp -lnetsnmpagent -luuid
INCLUDES += -I./
CCFLAGS = -fPIC -g -O2 -Wall -Werror -Wformat -Wformat-security
LIBCGTSAGENT_SO := libcgtsAgentPlugin.so
.c.o:
$(CXX) $(CCFLAGS) $(INCLUDES) -c $< -o $@
lib: $(OBJS)
$(CXX) $(OBJS) $(LDLIBS) -o $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) -shared
ln -sf $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(LIBCGTSAGENT_SO).$(MAJOR)
ln -sf $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(LIBCGTSAGENT_SO)
clean:
@rm -f $(OBJ) *.o *.so.* *.tgz
install:
install -m 755 -d $(DEST_DIR)$(LIB_DIR)
install -m 755 $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DEST_DIR)$(LIB_DIR)
install -m 755 -d $(DEST_DIR)$(DATA_DIR)/snmp/mibs
install -m 644 mibs/wrsAlarmMib.mib.txt $(DEST_DIR)$(DATA_DIR)/snmp/mibs/
install -m 644 mibs/wrsEnterpriseReg.mib.txt $(DEST_DIR)$(DATA_DIR)/snmp/mibs/
ln -s $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DEST_DIR)$(LIB_DIR)/$(LIBCGTSAGENT_SO).$(MAJOR)
ln -s $(LIBCGTSAGENT_SO).$(MAJOR).$(MINOR).$(PATCH) $(DEST_DIR)$(LIB_DIR)/$(LIBCGTSAGENT_SO)

+ 0
- 266
snmp-ext/sources/cgtsActiveAlarms.c View File

@ -1,266 +0,0 @@
/*
* Copyright (c) 2013-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/net-snmp-features.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <fmDbAPI.h>
#include "cgtsAgentPlugin.h"
netsnmp_feature_require(date_n_time)
#define MINLOADFREQ 1 /* min reload frequency in seconds */
static long Active_Alarm_Count = 0;
static struct activealarm *alarm_list;
static struct activealarm *alarmaddr, savealarm, *savealarmaddr;
static int saveIndex = 0;
static char saveUuid[36];
static long LastLoad = 0; /* ET in secs at last table load */
extern long long_return;
int Active_Alarm_Get_Count(void);
static void
Alarm_Scan_Init()
{
struct timeval et; /* elapsed time */
struct activealarm **activealarm_ptr;
SFmAlarmQueryT aquery;
size_t i = 0;
saveIndex = 0;
netsnmp_get_monotonic_clock(&et);
if ( et.tv_sec < LastLoad + MINLOADFREQ ) {
DEBUGMSG(("cgtsAgentPlugin", "Skip reload" ));
alarmaddr = alarm_list;
return;
}
LastLoad = et.tv_sec;
/*
* free old list:
*/
while (alarm_list) {
struct activealarm *old = alarm_list;
alarm_list = alarm_list->next;
free(old);
}
alarmaddr = 0;
activealarm_ptr = &alarm_list;
/*
* query active alarm list from DB
*/
if (fm_snmp_util_get_all_alarms(getAlarmSession(), &aquery) != true){
DEBUGMSG(("cgtsAgentPlugin", "get_all_alarms from db failed\n"));
return;
}
DEBUGMSG(("cgtsAgentPlugin", "get_all_alarms returns %lu alarms\n", aquery.num));
for (i = 0; i < aquery.num; ++i){
struct activealarm *almnew;
/*populate alarm_list*/
almnew = (struct activealarm *) calloc(1, sizeof(struct activealarm));
if (almnew == NULL)
break; /* alloc error */
*activealarm_ptr = almnew;
activealarm_ptr = &almnew->next;
memset(&almnew->alarmdata, 0 , sizeof(almnew->alarmdata));
memcpy(&almnew->alarmdata, aquery.alarm + i, sizeof(almnew->alarmdata));
}
alarmaddr = alarm_list;
free(aquery.alarm);
}
static int
Alarm_Scan_NextAlarm(int *Index,
char *Name,
struct activealarm *Aalm)
{
struct activealarm alm;
while (alarmaddr) {
alm = *alarmaddr;
strlcpy(saveUuid, alm.alarmdata.uuid, sizeof(saveUuid));
if (Index)
*Index = ++saveIndex;
if (Aalm)
*Aalm = alm;
if (Name)
strcpy(Name, saveUuid);
savealarm = alm;
savealarmaddr = alarmaddr;
alarmaddr = alm.next;
return 1;
}
return 0;
}
static int
Alarm_Scan_By_Index(int Index,
char *Name,
struct activealarm *Aalm)
{
int i;
DEBUGMSGTL(("cgtsAgentPlugin","Alarm_Scan_By_Index"));
Alarm_Scan_Init();
while (Alarm_Scan_NextAlarm(&i, Name, Aalm)) {
if (i == Index)
break;
}
if (i != Index)
return (-1); /* Error, doesn't exist */
return (0); /* DONE */
}
static int
header_alarmEntry(struct variable *vp,
oid * name,
size_t * length,
int exact, size_t * var_len,
WriteMethod ** write_method)
{
#define ALM_ENTRY_NAME_LENGTH 14
oid newname[MAX_OID_LEN];
register int index;
int result, count;
DEBUGMSGTL(("cgtsAgentPlugin", "header_alarmEntry: "));
DEBUGMSGOID(("cgtsAgentPlugin", name, *length));
DEBUGMSG(("cgtsAgentPlugin", "exact %d\n", exact));
memcpy((char *) newname, (char *) vp->name,
(int) vp->namelen * sizeof(oid));
/*
* find "next" alarm
*/
count = Active_Alarm_Get_Count();
DEBUGMSG(("cgtsAgentPlugin", "count %d\n", count));
for (index = 1; index <= count; index++) {
newname[ALM_ENTRY_NAME_LENGTH] = (oid) index;
result =
snmp_oid_compare(name, *length, newname,
(int) vp->namelen + 1);
if ((exact && (result == 0)) || (!exact && (result < 0)))
break;
}
if (index > count) {
DEBUGMSGTL(("cgtsAgentPlugin", "... index out of range\n"));
return MATCH_FAILED;
}
memcpy((char *) name, (char *) newname,
((int) vp->namelen + 1) * sizeof(oid));
*length = vp->namelen + 1;
*write_method = 0;
*var_len = sizeof(long); /* default to 'long' results */
DEBUGMSGTL(("cgtsAgentPlugin", "... get ALM data "));
DEBUGMSGOID(("cgtsAgentPlugin", name, *length));
DEBUGMSG(("cgtsAgentPlugin", "\n"));
DEBUGMSG(("cgtsAgentPlugin","Return index: %d\n", index));
return index;
}
int
Active_Alarm_Get_Count(void)
{
static time_t scan_time = 0;
time_t time_now = time(NULL);
if (!Active_Alarm_Count || (time_now > scan_time + 60)) {
scan_time = time_now;
Alarm_Scan_Init();
Active_Alarm_Count = 0;
while (Alarm_Scan_NextAlarm(NULL, NULL, NULL) != 0) {
Active_Alarm_Count++;
}
}
return (Active_Alarm_Count);
}
u_char *
var_alarms(struct variable *vp,
oid * name,
size_t * length,
int exact, size_t * var_len,
WriteMethod ** write_method)
{
static struct activealarm alrm;
static char Name[36];
char *cp;
int index = 0;
DEBUGMSGTL(("cgtsAgentPlugin", "var_alarms"));
index = header_alarmEntry(vp, name, length, exact, var_len, write_method);
if (index == MATCH_FAILED)
return NULL;
Alarm_Scan_By_Index(index, Name, &alrm);
switch (vp->magic) {
case ALARM_INDEX:
long_return = index;
return (u_char *) & long_return;
case ALARM_UUID:
cp = Name;
*var_len = strlen(cp);
return (u_char *) cp;
case ALARM_ID:
cp = alrm.alarmdata.alarm_id;
*var_len = strlen(cp);
return (u_char *) cp;
case ALARM_INSTANCE_ID:
cp = alrm.alarmdata.entity_instance_id;
*var_len = strlen(cp);
return (u_char *) cp;
case ALARM_TIME:{
time_t when = alrm.alarmdata.timestamp/SECOND_PER_MICROSECOND;
cp = (char *) date_n_time(&when, var_len );
return (u_char *) cp;
}
case ALARM_SEVERITY:
long_return = alrm.alarmdata.severity;
return (u_char *) & long_return;
case ALARM_REASONTEXT:
cp = alrm.alarmdata.reason_text;
*var_len = strlen(cp);
return (u_char *) cp;
case ALARM_EVENTTYPE:
long_return = alrm.alarmdata.alarm_type;
return (u_char *) & long_return;
case ALARM_PROBABLECAUSE:
long_return = alrm.alarmdata.probable_cause;
return (u_char *) & long_return;
case ALARM_REPAIRACTION:
cp = alrm.alarmdata.proposed_repair_action;
*var_len = strlen(cp);
return (u_char *) cp;
case ALARM_SERVICEAFFECTING:
long_return = alrm.alarmdata.service_affecting;
return (u_char *) & long_return;
case ALARM_SUPPRESSION:
long_return = alrm.alarmdata.suppression;
return (u_char *) & long_return;
default:
DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_alarms\n",
vp->magic));
}
return NULL;
}

+ 0
- 164
snmp-ext/sources/cgtsAgentPlugin.c View File

@ -1,164 +0,0 @@
/*
* Copyright (c) 2016 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <stdbool.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/net-snmp-features.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "cgtsAgentPlugin.h"
#define CGTS_ALM_TABLE_NAME "wrsAlarmActiveTable"
#define CGTS_EVENT_TABLE_NAME "wrsEventTable"
#define _UNREGISTER_MIB(var, miboid) \
do{ \
size_t varsize = sizeof(struct variable2); \
struct variable2 *vp; \
oid myoid[MAX_OID_LEN]; \
size_t length; \
int i, result; \
int numvars = sizeof(var)/varsize; \
int miboidlen = sizeof(miboid)/sizeof(oid); \
for (i=0; i < numvars; i++) { \
vp = (struct variable2 *)((char *)var + varsize * i); \
memcpy(myoid, miboid, miboidlen * sizeof(oid)); \
memcpy(myoid+miboidlen, vp->name, vp->namelen * sizeof(oid)); \
length = miboidlen + vp->namelen; \
result = unregister_mib(myoid, length); \
DEBUGMSGOID(("cgtsAgentPlugin", myoid, length)); \
if (result != MIB_UNREGISTERED_OK) { \
snmp_log(LOG_ERR, "%s: Unregistering failed:%d\n", \
__FUNCTION__, result); \
} else { \
DEBUGMSGTL(("cgtsAgentPlugin", "Unregistering succeeded\n")); \
} \
} \
}while(0);
static TFmAlarmSessionT alm_handle;
/*
* * the OID we want to register our integer at. This should be the
* * OID node for the entire table. In our case this is the
* * wrsAlarmActiveTable oid definition
*/
oid cgtsAlarmTable_oid[] =
{ 1, 3, 6, 1, 4, 1, 731, 1, 1, 1, 1, 1};
oid cgtsEventLogTable_oid[] =
{ 1, 3, 6, 1, 4, 1, 731, 1, 1, 1, 1, 4};
struct variable2 alarm_variables[] = {
{ALARM_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 1}},
{ALARM_UUID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 2}},
{ALARM_ID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 3}},
{ALARM_INSTANCE_ID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 4}},
{ALARM_TIME, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 5}},
{ALARM_SEVERITY, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 6}},
{ALARM_REASONTEXT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 7}},
{ALARM_EVENTTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 8}},
{ALARM_PROBABLECAUSE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 9}},
{ALARM_REPAIRACTION , ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 10}},
{ALARM_SERVICEAFFECTING, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 11}},
{ALARM_SUPPRESSION, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_alarms, 2, {1, 12}},
};
struct variable2 event_log_variables[] = {
{EVENT_INDEX, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 1}},
{EVENT_UUID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 2}},
{EVENT_EVENT_ID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 3}},
{EVENT_STATE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 4}},
{EVENT_INSTANCE_ID, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 5}},
{EVENT_TIME, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 6}},
{EVENT_SEVERITY, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 7}},
{EVENT_REASONTEXT, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 8}},
{EVENT_EVENTTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 9}},
{EVENT_PROBABLECAUSE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 10}},
{EVENT_REPAIRACTION , ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 11}},
{EVENT_SERVICEAFFECTING, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 12}},
{EVENT_SUPPRESSION, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
var_events, 2, {1, 13}},
};
TFmAlarmSessionT getAlarmSession()
{
return alm_handle;
}
/*
* our initialization routine, automatically called by the agent
* (to get called, the function name must match init_FILENAME())
*/
void
init_cgtsAgentPlugin(void)
{
snmp_log(LOG_INFO,"init_cgtsAgentPlugin start");
snmp_log(LOG_INFO,"MIB registration: %s",CGTS_ALM_TABLE_NAME);
REGISTER_MIB(CGTS_ALM_TABLE_NAME, alarm_variables,
variable2, cgtsAlarmTable_oid);
snmp_log(LOG_INFO,"MIB registration: %s",CGTS_EVENT_TABLE_NAME);
REGISTER_MIB(CGTS_EVENT_TABLE_NAME, event_log_variables,
variable2, cgtsEventLogTable_oid);
snmp_log(LOG_INFO,"get alarm database handler");
if (fm_snmp_util_create_session(&alm_handle, NULL) != true){
snmp_log(LOG_ERR,"failed to get alarm database handler");
exit(-1);
}
/*
* a debugging statement. Run the agent with -DcgtsAgentPlugin to see
* the output of this debugging statement.
*/
DEBUGMSGTL(("cgtsAgentPlugin", "Done initializing.\n"));
}
void
deinit_cgtsAgentPlugin(void)
{
snmp_log(LOG_INFO,"deinit_cgtsAgentPlugin start");
_UNREGISTER_MIB(alarm_variables, cgtsAlarmTable_oid);
_UNREGISTER_MIB(event_log_variables, cgtsEventLogTable_oid);
fm_snmp_util_destroy_session(alm_handle);
}

+ 0
- 69
snmp-ext/sources/cgtsAgentPlugin.h View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2013-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
#ifndef CGTSAGENTPLUGIN_H
#define CGTSAGENTPLUGIN_H
#include <fmAPI.h>
#include <fmDbAPI.h>
#include <net-snmp/agent/snmp_vars.h>
extern FindVarMethod var_alarms;
extern FindVarMethod var_events;
/* Active alarm Table */
#define ALARM_INDEX 1
#define ALARM_UUID 2
#define ALARM_ID 3
#define ALARM_INSTANCE_ID 4
#define ALARM_TIME 5
#define ALARM_SEVERITY 6
#define ALARM_REASONTEXT 7
#define ALARM_EVENTTYPE 8
#define ALARM_PROBABLECAUSE 9
#define ALARM_REPAIRACTION 10
#define ALARM_SERVICEAFFECTING 11
#define ALARM_SUPPRESSION 12
/* Event Log Table */
#define EVENT_INDEX 1
#define EVENT_UUID 2
#define EVENT_EVENT_ID 3
#define EVENT_STATE 4
#define EVENT_INSTANCE_ID 5
#define EVENT_TIME 6
#define EVENT_SEVERITY 7
#define EVENT_REASONTEXT 8
#define EVENT_EVENTTYPE 9
#define EVENT_PROBABLECAUSE 10
#define EVENT_REPAIRACTION 11
#define EVENT_SERVICEAFFECTING 12
#define EVENT_SUPPRESSION 13
#define SECOND_PER_MICROSECOND 1000000
struct activealarm {
SFmAlarmDataT alarmdata;
struct activealarm *next;
};
/*
* function declarations
*/
#ifdef __cplusplus
extern "C" {
#endif
void init_cgtsAgentPlugin(void);
void deinit_cgtsAgentPlugin(void);
TFmAlarmSessionT getAlarmSession();
#ifdef __cplusplus
}
#endif
#endif /* CGTSAGENTPLUGIN_H */

+ 0
- 268
snmp-ext/sources/cgtsEventLogs.c View File

@ -1,268 +0,0 @@
/*
* Copyright (c) 2013-2016 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/