1 #include <net-snmp/net-snmp-config.h>
2 #include <net-snmp/net-snmp-includes.h>
3 #include <net-snmp/agent/net-snmp-agent-includes.h>
4 #include <net-snmp/agent/hardware/sensors.h>
5 #include "hw_sensors_private.h"
6
7 #include <time.h>
8
9 #include <kstat.h>
10 #include </usr/platform/sun4u/include/sys/envctrl.h>
11
netsnmp_sensor_arch_init(void)12 void netsnmp_sensor_arch_init( void ) {
13 DEBUGMSGTL(("sensors:arch", "Initialise KStat Sensors module\n"));
14 }
15
16
17 int
netsnmp_sensor_arch_load(netsnmp_cache * cache,void * vp)18 netsnmp_sensor_arch_load(netsnmp_cache *cache, void *vp) {
19 netsnmp_sensor_info *sp;
20
21 int i;
22 const char *fantypes[]={"CPU","PWR","AFB"};
23 char name[ 256 ];
24
25 kstat_ctl_t *kc;
26 kstat_t *kp;
27 envctrl_fan_t *fan_info;
28 envctrl_ps_t *power_info;
29 envctrl_encl_t *enc_info;
30
31
32 DEBUGMSGTL(("sensors:arch", "Reload KStat Sensors module\n"));
33
34 kc = kstat_open();
35 if ( kc == 0) {
36 DEBUGMSGTL(("sensors:arch", "Couldn't open kstat\n"));
37 return 1;
38 }
39
40
41 /*
42 * Retrieve fan information
43 */
44 kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_FANSTAT);
45 if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
46 DEBUGMSGTL(("sensors:arch", "No fan information\n"));
47 } else {
48 fan_info = (envctrl_fan_t *)kp->ks_data;
49 for (i=0; i<kp->ks_ndata; i++) {
50 memset( name, 0, 256 );
51 snprintf( name, 255, "%s%d", fantypes[fan_info->type], fan_info->instance );
52
53 sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_RPM );
54 if ( sp ) {
55 sp->value = fan_info->fanspeed;
56 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
57 snprintf( sp->descr, 255, "fan type %s number %d",
58 fantypes[fan_info->type], fan_info->instance );
59 }
60
61 fan_info++;
62 }
63 }
64
65
66 /*
67 * Retrieve Power Supply information
68 */
69 kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_PSNAME);
70 if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
71 DEBUGMSGTL(("sensors:arch", "No PSU information\n"));
72 } else {
73 power_info = (envctrl_ps_t *)kp->ks_data;
74 for (i=0; i<kp->ks_ndata; i++) {
75 memset( name, 0, 256 );
76 snprintf( name, 255, "PSU%d", power_info->instance );
77
78 sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
79 if ( sp ) {
80 sp->value = power_info->ps_tempr;
81 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
82 snprintf( sp->descr, 255, "power supply %d", power_info->instance );
83 }
84
85 power_info++;
86 }
87 }
88
89
90 /*
91 * Retrieve Enclosure information
92 */
93 kp = kstat_lookup( kc, ENVCTRL_MODULE_NAME, 0, ENVCTRL_KSTAT_ENCL);
94 if (( kp == 0 ) || (kstat_read( kc, kp, 0 ) == -1 )) {
95 DEBUGMSGTL(("sensors:arch", "No enclosure information\n"));
96 } else {
97 enc_info = (envctrl_encl_t *)kp->ks_data;
98 for (i=0; i<kp->ks_ndata; i++) {
99 /*
100 * The enclosure information covers several different types of sensor
101 */
102 switch ( enc_info->type ) {
103 case ENVCTRL_ENCL_FSP:
104 DEBUGMSGTL(("sensors:arch:detail", "Enclosure Front Panel\n"));
105 sp = sensor_by_name( "FSP", NETSNMP_SENSOR_TYPE_OTHER);
106 if ( sp ) {
107 sp->value = enc_info->value;
108 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
109 }
110 break;
111
112 case ENVCTRL_ENCL_AMBTEMPR:
113 DEBUGMSGTL(("sensors:arch:detail", "Enclosure Ambient Temperature\n"));
114 sp = sensor_by_name( "Ambient", NETSNMP_SENSOR_TYPE_TEMPERATURE);
115 if ( sp ) {
116 sp->value = enc_info->value;
117 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
118 }
119 break;
120
121 case ENVCTRL_ENCL_CPUTEMPR:
122 DEBUGMSGTL(("sensors:arch:detail", "Enclosure CPU Temperature\n"));
123 memset( name, 0, 256 );
124 snprintf( name, 255, "CPU%d", enc_info->instance );
125 sp = sensor_by_name( name, NETSNMP_SENSOR_TYPE_TEMPERATURE);
126 if ( sp ) {
127 sp->value = enc_info->value;
128 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
129 snprintf( sp->descr, 255, "CPU%d temperature", enc_info->instance );
130 }
131 break;
132
133 case ENVCTRL_ENCL_BACKPLANE4:
134 DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
135 sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
136 if ( sp ) {
137 sp->value = enc_info->value;
138 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
139 }
140 break;
141
142 case ENVCTRL_ENCL_BACKPLANE8:
143 DEBUGMSGTL(("sensors:arch:detail", "Enclosure Backplane4\n"));
144 sp = sensor_by_name( "Backplane4", NETSNMP_SENSOR_TYPE_OTHER);
145 if ( sp ) {
146 sp->value = enc_info->value;
147 sp->flags|= NETSNMP_SENSOR_FLAG_ACTIVE;
148 }
149 break;
150
151 default:
152 DEBUGMSGTL(("sensors:arch:detail", "Unrecognised Enclosure entry (%d)n",
153 enc_info->type));
154 }
155
156 enc_info++;
157 }
158 }
159
160 kstat_close(kc);
161 return 0;
162 }
163