⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmp_rsa.c

📁 HIP 硬件设备管理标准接口
💻 C
📖 第 1 页 / 共 2 页
字号:
/*      -*- linux-c -*- * * (C) Copyright IBM Corp. 2003, 2004 * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This * file and program are licensed under a BSD style license.  See * the Copying file included with the OpenHPI distribution for * full licensing terms. * * Author(s): *      Renier Morales <renierm@users.sf.net> *      Steve Sherman <stevees@us.ibm.com> *      W. David Ashley<dashley@us.ibm.com> */#include <glib.h>#include <SaHpi.h>#include <openhpi.h>#include <oh_plugin.h>#include <snmp_util.h>#include <oh_utils.h>#include <rsa_resources.h>#include <snmp_rsa_control.h>#include <snmp_rsa_discover.h>#include <snmp_rsa_sel.h>#include <snmp_rsa_sensor.h>#include <snmp_rsa_session.h>#include <snmp_rsa_hotswap.h>#include <snmp_rsa_watchdog.h>#include <snmp_rsa_inventory.h>#include <snmp_rsa_utils.h>#include <snmp_rsa.h>/** * snmp_rsa_get_event: * @hnd:  * @event:  * @timeout:  * * Return value:  **/static int snmp_rsa_get_event(void *hnd, struct oh_event *event, struct timeval *timeout){        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;                if(g_slist_length(handle->eventq)>0) {                memcpy(event, handle->eventq->data, sizeof(*event));                free(handle->eventq->data);                handle->eventq = g_slist_remove_link(handle->eventq, handle->eventq);                return 1;        } else {                return 0;	}}/* Search for sensor.Num, since some sensors may not have an OID */#define find_sensors(rdr_array) \do { \        int j; \	for(j=0; rdr_array[j].sensor.Num != 0; j++) { \		e = snmp_rsa_discover_sensors(handle, \                                              parent_ep, \                                              &rdr_array[j]); \                if(e != NULL) { \                        struct RSA_SensorInfo *rsa_data = g_memdup(&(rdr_array[j].rsa_sensor_info), \                                                                           sizeof(struct RSA_SensorInfo)); \                        oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); \                        tmpqueue = g_slist_append(tmpqueue, e); \                } \        } \} while(0)#define find_controls(rdr_array) \do { \        int j; \        for(j=0; rdr_array[j].rsa_control_info.mib.oid != NULL; j++) { \	        e = snmp_rsa_discover_controls(handle, \                                               parent_ep, \                                               &rdr_array[j]); \                if(e != NULL) { \                        struct RSA_ControlInfo *rsa_data = g_memdup(&(rdr_array[j].rsa_control_info), \                                                                    sizeof(struct RSA_ControlInfo)); \                        oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); \                        tmpqueue = g_slist_append(tmpqueue, e); \                } \        } \} while(0)#define find_inventories(rdr_array) \do { \        int j; \        for (j=0; rdr_array[j].rsa_inventory_info.mib.oid.OidManufacturer != NULL; j++) { \                e = snmp_rsa_discover_inventories(handle, \                                                  parent_ep, \                                                  &rdr_array[j]); \                if(e != NULL) { \                        struct RSA_InventoryInfo *rsa_data = g_memdup(&(rdr_array[j].rsa_inventory_info), \                                                                      sizeof(struct RSA_InventoryInfo)); \                        oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0); \                        tmpqueue = g_slist_append(tmpqueue, e); \                } \        } \} while(0)static int snmp_rsa_discover_resources(void *hnd){        SaHpiEntityPathT entity_root;                guint i;        struct oh_event *e;	struct snmp_value get_value;//	struct snmp_value get_active;        struct oh_handler_state *handle = (struct oh_handler_state *)hnd;        struct snmp_rsa_hnd *custom_handle = (struct snmp_rsa_hnd *)handle->data;        RPTable *tmpcache = (RPTable *)g_malloc0(sizeof(RPTable));        GSList *tmpqueue = NULL;        char *root_tuple = (char *)g_hash_table_lookup(handle->config,"entity_root");                                string2entitypath(root_tuple, &entity_root);        /* see if the chassis exists by querying system health */        if(snmp_get(custom_handle->ss,".1.3.6.1.4.1.2.3.51.1.2.7.1.0",&get_value) != 0) {                /* If we get here, something is hosed. No need to do more discovery */                dbg("Couldn't fetch SNMP RSA system health.\n");                dbg("There is no chassis.");                g_free(tmpcache);                return -1;        }        /* discover the chassis */        e = snmp_rsa_discover_chassis(handle, &entity_root);        if(e != NULL) {                struct ResourceMibInfo *res_mib =                        g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CHASSIS].rsa_res_info.mib),                                 sizeof(struct snmp_rpt));                oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);                tmpqueue = g_slist_append(tmpqueue, e);                SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;                SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;		find_sensors(snmp_rsa_chassis_sensors);                        		find_controls(snmp_rsa_chassis_controls);		find_inventories(snmp_rsa_chassis_inventories);        }        /* discover all cpus */        for (i = 0; i < RSA_MAX_CPU; i++) {                /* see if the cpu exists by querying the thermal sensor */                if((snmp_get(custom_handle->ss,                             snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info.mib.oid,                             &get_value) != 0) ||                   (get_value.type != ASN_OCTET_STR) ||                   (strcmp(get_value.string, "Not Readable!") == 0)) {                        /* If we get here the CPU is not installed */                        dbg("CPU %d not found.\n", i+RSA_HPI_INSTANCE_BASE);                        continue;                }                e = snmp_rsa_discover_cpu(handle, &entity_root, i);                if(e != NULL) {                        struct ResourceMibInfo *res_mib =                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_CPU].rsa_res_info.mib),                                         sizeof(struct snmp_rpt));                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);                        tmpqueue = g_slist_append(tmpqueue, e);                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;                        /* add the CPU thermal sensor */                        e = snmp_rsa_discover_sensors(handle,                                                      parent_ep,                                                      &snmp_rsa_cpu_thermal_sensors[i]);                        if(e != NULL) {                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_cpu_thermal_sensors[i].rsa_sensor_info),                                                                           sizeof(struct RSA_SensorInfo));                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);                                tmpqueue = g_slist_append(tmpqueue, e);                        }                }        }        /* discover all dasd */        for (i = 0; i < RSA_MAX_DASD; i++) {                /* see if the dasd exists by querying the thermal sensor */                if((snmp_get(custom_handle->ss,                             snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info.mib.oid,                             &get_value) != 0) ||                   (get_value.type != ASN_OCTET_STR) ||                   (strcmp(get_value.string, "Not Readable!") == 0)) {                        /* If we get here the DASD is not installed */                        dbg("DASD %d not found.\n", i+RSA_HPI_INSTANCE_BASE);                        continue;                }                e = snmp_rsa_discover_dasd(handle, &entity_root, i);                if(e != NULL) {                        struct ResourceMibInfo *res_mib =                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_DASD].rsa_res_info.mib),                                         sizeof(struct snmp_rpt));                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);                        tmpqueue = g_slist_append(tmpqueue, e);                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;                        /* add the DASD thermal sensor */                        e = snmp_rsa_discover_sensors(handle,                                                      parent_ep,                                                      &snmp_rsa_dasd_thermal_sensors[i]);                        if(e != NULL) {                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_dasd_thermal_sensors[i].rsa_sensor_info),                                                                           sizeof(struct RSA_SensorInfo));                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);                                tmpqueue = g_slist_append(tmpqueue, e);                        }                }        }        /* discover all fans */        for (i = 0; i < RSA_MAX_FAN; i++) {                /* see if the fan exists by querying the  sensor */                if((snmp_get(custom_handle->ss,                             snmp_rsa_fan_sensors[i].rsa_sensor_info.mib.oid,                             &get_value) != 0) ||                   (get_value.type != ASN_OCTET_STR) ||                   (strcmp(get_value.string, "Not Readable!") == 0)) {                        /* If we get here the fan is not installed */                        dbg("Fan %d not found.\n", i+RSA_HPI_INSTANCE_BASE);                        continue;                }                e = snmp_rsa_discover_fan(handle, &entity_root, i);                if(e != NULL) {                        struct ResourceMibInfo *res_mib =                                g_memdup(&(snmp_rsa_rpt_array[RSA_RPT_ENTRY_FAN].rsa_res_info.mib),                                         sizeof(struct snmp_rpt));                        oh_add_resource(tmpcache,&(e->u.res_event.entry),res_mib,0);                        tmpqueue = g_slist_append(tmpqueue, e);                        SaHpiResourceIdT rid = e->u.res_event.entry.ResourceId;                        SaHpiEntityPathT parent_ep = e->u.res_event.entry.ResourceEntity;                        /* add the fan sensor */                        e = snmp_rsa_discover_sensors(handle,                                                      parent_ep,                                                      &snmp_rsa_fan_sensors[i]);                        if(e != NULL) {                                struct RSA_SensorInfo *rsa_data = g_memdup(&(snmp_rsa_fan_sensors[i].rsa_sensor_info),                                                                           sizeof(struct RSA_SensorInfo));                                oh_add_rdr(tmpcache,rid,&(e->u.rdr_event.rdr), rsa_data, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -