From e78e8b757eefb77c47554be3a58a2be2887a5cc5 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallardo Date: Fri, 29 Jan 2021 16:22:45 -0300 Subject: [PATCH] Add info name, location and contact to snmpd.conf Add SNMP system information including name, location and contact details in the fields sysContact, sysLocation and sysName of the snmpd.conf file. Also can be setted the field sysDesc with system description. Story: 2008132 Task: 41716 Signed-off-by: Gonzalo Gallardo Change-Id: I0ed5a347f8be7e11e4acb37392520e4702183ddf --- .../k8sapp_snmp/k8sapp_snmp/helm/snmp.py | 43 ++++++++++++++++--- .../helm-charts/snmp/templates/configmap.yaml | 4 ++ .../helm-charts/snmp/values.yaml | 4 ++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/python-k8sapp-snmp/k8sapp_snmp/k8sapp_snmp/helm/snmp.py b/python-k8sapp-snmp/k8sapp_snmp/k8sapp_snmp/helm/snmp.py index 3d250c4..277fa57 100644 --- a/python-k8sapp-snmp/k8sapp_snmp/k8sapp_snmp/helm/snmp.py +++ b/python-k8sapp-snmp/k8sapp_snmp/k8sapp_snmp/helm/snmp.py @@ -1,19 +1,23 @@ # -# Copyright (c) 2020 Wind River Systems, Inc. +# Copyright (c) 2020-2021 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # + from k8sapp_snmp.common import constants as app_constants +from os import uname +from six import ensure_str +from six import ensure_text +from six import string_types from sysinv.common import constants -from sysinv.common import exception - +from sysinv.common import exception +from sysinv.db import api from sysinv.helm import base from sysinv.helm import common from sysinv.puppet import openstack -from oslo_log import log as logging class SnmpHelm(base.BaseHelm, openstack.OpenstackBasePuppet): @@ -31,6 +35,22 @@ class SnmpHelm(base.BaseHelm, openstack.OpenstackBasePuppet): SERVICE_NAME = 'snmp' SERVICE_FM_NAME = 'fm' SERVICE_FM_PORT = 18002 + UNDEFINED_CONF_VALUE = '?' + KERNEL_RELEASE_IDX = 2 + + def _unicode_represent(self, data): + if isinstance(data, string_types): + try: + result = ensure_str(data) + #Try to encode to detect bad translation + #for multi-bytes characters + result.encode('utf-8') + return result + except Exception as e: + return ensure_text(data) + else: + #If data is NoneType + return ensure_str(self.UNDEFINED_CONF_VALUE) def get_namespaces(self): return self.SUPPORTED_NAMESPACES @@ -49,17 +69,28 @@ class SnmpHelm(base.BaseHelm, openstack.OpenstackBasePuppet): 'fm::database_connection': self._format_database_connection(self.SERVICE_FM_NAME), } - return config + def get_system_info(self): + return uname()[self.KERNEL_RELEASE_IDX] + def get_overrides(self, namespace=None): db_url = self.get_secure_system_config()['fm::database_connection'] + dbapi = api.get_instance() + # Get the contact, location, name and desciption info + system = dbapi.isystem_get_one() overrides = { common.HELM_NS_KUBE_SYSTEM: { 'configmap': { - 'connection': str(db_url) + 'connection': self._unicode_represent(db_url), + 'system_contact' : self._unicode_represent(system.contact), + 'system_location' : self._unicode_represent( + system.location), + 'system_name' : self._unicode_represent(system.name), + 'system_description' : self._unicode_represent( + system.software_version) + ' ' + self.get_system_info() }, } } diff --git a/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/templates/configmap.yaml b/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/templates/configmap.yaml index 5bec78a..38ed119 100755 --- a/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/templates/configmap.yaml +++ b/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/templates/configmap.yaml @@ -5,6 +5,10 @@ metadata: data: {{ (.Files.Glob "snmpd/*").AsConfig | indent 2 }} {{ .Values.configmap.user_conf | indent 4 }} + sysDescr {{ .Values.configmap.system_description }} + sysContact {{ .Values.configmap.system_contact }} + sysName {{ .Values.configmap.system_name }} + sysLocation {{ .Values.configmap.system_location }} --- apiVersion: v1 kind: ConfigMap diff --git a/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/values.yaml b/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/values.yaml index 9566527..f8816a7 100755 --- a/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/values.yaml +++ b/stx-snmp-helm/stx-snmp-helm/helm-charts/snmp/values.yaml @@ -25,6 +25,10 @@ configmap: name_snmpd: snmpd-etc-config name_fm: snmpd-fm user_conf: '# User configuration' + system_description: '' + system_contact: '' + system_name: '' + system_location: '' connection: '' deployment: