4 * rfc1628 aka UPS-MIB driver
8 * Copyright (C) 2000-2004 Kern Sibbald
9 * Copyright (C) 1999-2002 Riccardo Facchetti <riccardo@apcupsd.org>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General
13 * Public License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #include "snmp_private.h"
30 static int rfc_1628_check_alarms(UPSINFO
*ups
)
32 struct snmp_ups_internal_data
*Sid
=
33 (struct snmp_ups_internal_data
*)ups
->driver_internal_data
;
34 struct snmp_session
*s
= &Sid
->session
;
35 ups_mib_t
*data
= (ups_mib_t
*)Sid
->MIB
;
38 * Check the Ethernet COMMLOST first, then check the
39 * Agent/SNMP->UPS serial COMMLOST together with all the other
42 if (ups_mib_mgr_get_upsAlarmEntry(s
, &(data
->upsAlarmEntry
)) == -1) {
44 free(data
->upsAlarmEntry
);
47 ups
->clear_commlost();
50 free(data
->upsAlarmEntry
);
54 int rfc1628_snmp_kill_ups_power(UPSINFO
*ups
)
59 int rfc1628_snmp_ups_get_capabilities(UPSINFO
*ups
)
64 * Assume that an UPS with SNMP control has all the capabilities.
65 * We know that the RFC1628 doesn't even implement some of the
66 * capabilities. We do this way for sake of simplicity.
68 for (i
= 0; i
<= CI_MAX_CAPS
; i
++)
69 ups
->UPS_Cap
[i
] = TRUE
;
74 int rfc1628_snmp_ups_read_static_data(UPSINFO
*ups
)
76 struct snmp_ups_internal_data
*Sid
=
77 (struct snmp_ups_internal_data
*)ups
->driver_internal_data
;
78 struct snmp_session
*s
= &Sid
->session
;
79 ups_mib_t
*data
= (ups_mib_t
*)Sid
->MIB
;
81 if (rfc_1628_check_alarms(ups
) == 0) {
85 data
->upsIdent
= NULL
;
86 ups_mib_mgr_get_upsIdent(s
, &(data
->upsIdent
));
88 SNMP_STRING(upsIdent
, Model
, upsmodel
);
89 SNMP_STRING(upsIdent
, Name
, upsname
);
96 int rfc1628_snmp_ups_read_volatile_data(UPSINFO
*ups
)
98 struct snmp_ups_internal_data
*Sid
=
99 (struct snmp_ups_internal_data
*)ups
->driver_internal_data
;
100 struct snmp_session
*s
= &Sid
->session
;
101 ups_mib_t
*data
= (ups_mib_t
*)Sid
->MIB
;
103 if (rfc_1628_check_alarms(ups
) == 0) {
107 data
->upsBattery
= NULL
;
108 ups_mib_mgr_get_upsBattery(s
, &(data
->upsBattery
));
109 if (data
->upsBattery
) {
110 switch (data
->upsBattery
->__upsBatteryStatus
) {
112 ups
->clear_battlow();
117 default: /* Unknown, assume battery is ok */
118 ups
->clear_battlow();
122 ups
->BattChg
= data
->upsBattery
->__upsEstimatedChargeRemaining
;
123 ups
->UPSTemp
= data
->upsBattery
->__upsBatteryTemperature
;
124 ups
->TimeLeft
= data
->upsBattery
->__upsEstimatedMinutesRemaining
;
126 free(data
->upsBattery
);
129 data
->upsInputEntry
= NULL
;
130 ups_mib_mgr_get_upsInputEntry(s
, &(data
->upsInputEntry
));
131 if (data
->upsInputEntry
) {
132 ups
->LineVoltage
= data
->upsInputEntry
->__upsInputVoltage
;
133 ups
->LineFreq
= data
->upsInputEntry
->__upsInputFrequency
/ 10;
135 if (ups
->LineMax
< ups
->LineVoltage
) {
136 ups
->LineMax
= ups
->LineVoltage
;
139 if (ups
->LineMin
> ups
->LineVoltage
|| ups
->LineMin
== 0) {
140 ups
->LineMin
= ups
->LineVoltage
;
143 free(data
->upsInputEntry
);
146 data
->upsOutputEntry
= NULL
;
147 ups_mib_mgr_get_upsOutputEntry(s
, &(data
->upsOutputEntry
));
148 if (data
->upsOutputEntry
) {
149 ups
->OutputVoltage
= data
->upsOutputEntry
->__upsOutputVoltage
;
150 ups
->UPSLoad
= data
->upsOutputEntry
->__upsOutputPercentLoad
;
151 ups
->OutputCurrent
= data
->upsOutputEntry
->__upsOutputCurrent
;
153 free(data
->upsOutputEntry
);
159 int rfc1628_snmp_ups_check_state(UPSINFO
*ups
)
161 /* Wait the required amount of time before bugging the device. */
162 sleep(ups
->wait_time
);
165 rfc_1628_check_alarms(ups
);