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 <gonzalo.gallardo@windriver.com> Change-Id: I0ed5a347f8be7e11e4acb37392520e4702183ddf
This commit is contained in:
parent
f15426c720
commit
e78e8b757e
@ -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()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user