From 1c7beb800513403f6f768e152567fcf116a3b948 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 14 Dec 2016 16:53:35 +0000 Subject: [PATCH] - Add platform objects These were accidentally overwritten by the sensor registration changes. They belong in their own file anyways so the code has been split and the registration moved to a common location. --- .../onlp_snmp/module/src/onlp_snmp_module.c | 20 ++- .../onlp_snmp/module/src/onlp_snmp_platform.c | 114 ++++++++++++++++++ .../onlp_snmp/module/src/onlp_snmp_sensors.c | 2 +- 3 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_platform.c diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_module.c b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_module.c index 76b7ac4f..3b9adbbb 100644 --- a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_module.c +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_module.c @@ -34,16 +34,30 @@ void __onlp_snmp_module_init__(void) #include +static int +onlp_snmp_client__(int enable, void* cookie) +{ + /* onlp_snmp_sensors.c */ + extern int onlp_snmp_sensors_init(void); + /* onlp_snmp_platform.c */ + extern int onlp_snmp_platform_init(void); + + onlp_snmp_sensors_init(); + onlp_snmp_platform_init(); + + return 0; +} + int onlp_snmp_snmp_subagent_register(void) { - return snmp_subagent_client_register("onlp_snmp_sensors", - onlp_snmp_sensors_client, + return snmp_subagent_client_register("onlp_snmp_client", + onlp_snmp_client__, NULL); } int onlp_snmp_snmp_subagent_unregister(void) { - return snmp_subagent_client_unregister("onlp_snmp_sensors"); + return snmp_subagent_client_unregister("onlp_snmp_client"); } #endif /* DEPENDMODULE_INCLUDE_SNMP_SUBAGENT */ diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_platform.c b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_platform.c new file mode 100644 index 00000000..1a6b3e55 --- /dev/null +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_platform.c @@ -0,0 +1,114 @@ +/************************************************************ + * + * + * Copyright 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/legal/epl-v10.html + * + * 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. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include "onlp_snmp_log.h" + +#include +#include +#include +#include + +static void +platform_string_register(int index, const char* desc, char* value) +{ + oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1}; + tree[11] = index; + + if(!value || !value[0]) { + return; + } + + char* s = aim_strdup(value); + + netsnmp_handler_registration *reg = + netsnmp_create_handler_registration( + desc, NULL, + tree, OID_LENGTH(tree), + HANDLER_CAN_RONLY); + netsnmp_watcher_info *winfo = + netsnmp_create_watcher_info( + s, strlen(s), + ASN_OCTET_STR, WATCHER_FIXED_SIZE); + netsnmp_register_watched_scalar( reg, winfo ); +} + +void +platform_int_register(int index, char* desc, int value) +{ + oid tree[] = { 1, 3, 6, 1, 4, 1, 42623, 1, 1, 1, 1, 1}; + tree[11] = index; + + int* v = aim_zmalloc(sizeof(value)); + *v = value; + + netsnmp_register_int_instance(desc, + tree, + OID_LENGTH(tree), + v, NULL); +} + + +void +onlp_snmp_platform_init(void) +{ + /** + * This is the base of the platform:general:system tree + */ + onlp_sys_info_t si; + if(onlp_sys_info_get(&si) >= 0) { + +#define REGISTER_STR(_index, _field) \ + do { \ + platform_string_register(_index, #_field, (char*)si.onie_info._field); \ + } while(0) + +#define REGISTER_INT(_index, _field) \ + do { \ + platform_int_register(_index, #_field, si.onie_info._field); \ + } while(0) + + REGISTER_STR(1, product_name); + REGISTER_STR(2, part_number); + REGISTER_STR(3, serial_number); + char* mstring = aim_fstrdup("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + si.onie_info.mac[0], si.onie_info.mac[1], si.onie_info.mac[2], + si.onie_info.mac[3], si.onie_info.mac[4], si.onie_info.mac[5]); + platform_string_register(4, "mac", mstring); + aim_free(mstring); + + REGISTER_INT(5, mac_range); + REGISTER_STR(6, manufacturer); + REGISTER_STR(7, manufacture_date); + REGISTER_STR(8, vendor); + REGISTER_STR(9, platform_name); + REGISTER_INT(10, device_version); + REGISTER_STR(11, label_revision); + REGISTER_STR(12, country_code); + REGISTER_STR(13, diag_version); + REGISTER_STR(14, service_tag); + REGISTER_STR(15, onie_version); + } +} + diff --git a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c index ecae68b4..84b18308 100644 --- a/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c +++ b/packages/base/any/onlp-snmpd/builds/src/onlp_snmp/module/src/onlp_snmp_sensors.c @@ -1136,7 +1136,7 @@ setup_alarm__(void) int -onlp_snmp_sensors_client(int enable, void* cookie) +onlp_snmp_sensors_init(void) { init_all_tables__(); setup_alarm__();