1 /* xppc-mib.c - subdriver to monitor XPPC SNMP devices with NUT
2  *
3  *  Copyright (C)
4  *  2011 - 2012	Arnaud Quette <arnaud.quette@free.fr>
5  *  2014       	Charles Lepple <clepple+nut@gmail.com>
6  *
7  *  Note: this subdriver was initially generated as a "stub" by the
8  *  scripts/subdriver/gen-snmp-subdriver.sh script.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
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
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include "xppc-mib.h"
26 
27 #define XPPC_MIB_VERSION  "0.2"
28 
29 #define XPPC_SYSOID       ".1.3.6.1.4.1.935"
30 
31 /* To create a value lookup structure (as needed on the 2nd line of the example
32  * below), use the following kind of declaration, outside of the present snmp_info_t[]:
33  * static info_lkp_t onbatt_info[] = {
34  * 	{ 1, "OB" },
35  * 	{ 2, "OL" },
36  * 	{ 0, NULL }
37  * };
38  */
39 
40 /* upsBaseBatteryStatus */
41 static info_lkp_t xpcc_onbatt_info[] = {
42 	{ 1, "" },	/* unknown */
43 	{ 2, "" },	/* batteryNormal */
44 	{ 3, "LB" }	/* batteryLow */
45 };
46 
47 /*
48 upsBaseOutputStatus OBJECT-TYPE
49 	SYNTAX INTEGER {
50 			unknown(1),
51 			onLine(2),
52 			onBattery(3),
53 			onBoost(4),
54 			sleeping(5),
55 			onBypass(6),
56 			rebooting(7),
57 			standBy(8),
58 			onBuck(9) }
59 */
60 static info_lkp_t xpcc_power_info[] = {
61 	{ 1, "" },	/* unknown */
62 	{ 2, "OL" },	/* onLine */
63 	{ 3, "OB" },	/* onBattery */
64 	{ 4, "OL BOOST" },	/* onBoost */
65 	{ 5, "OFF" },	/* sleeping */
66 	{ 6, "BYPASS"},	/* onBypass */
67 	{ 7, "" },	/* rebooting */
68 	{ 8, "OFF" },	/* standBy */
69 	{ 9, "OL TRIM"}	/* onBuck */
70 };
71 
72 /* XPPC Snmp2NUT lookup table */
73 static snmp_info_t xppc_mib[] = {
74 
75 	/* Data format:
76 	 * { info_type, info_flags, info_len, OID, dfl, flags, oid2info, setvar },
77 	 *
78 	 *	info_type:	NUT INFO_ or CMD_ element name
79 	 *	info_flags:	flags to set in addinfo
80 	 *	info_len:	length of strings if STR
81 	 *				cmd value if CMD, multiplier otherwise
82 	 *	OID: SNMP OID or NULL
83 	 *	dfl: default value
84 	 *	flags: snmp-ups internal flags (FIXME: ...)
85 	 *	oid2info: lookup table between OID and NUT values
86 	 *	setvar: variable to set for SU_FLAG_SETINT
87 	 *
88 	 * Example:
89 	 * { "input.voltage", 0, 0.1, ".1.3.6.1.4.1.705.1.6.2.1.2.1", "", SU_INPUT_1, NULL },
90 	 * { "ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.705.1.7.3.0", "", SU_FLAG_OK | SU_STATUS_BATT, onbatt_info },
91 	 *
92 	 * To create a value lookup structure (as needed on the 2nd line), use the
93 	 * following kind of declaration, outside of the present snmp_info_t[]:
94 	 * static info_lkp_t onbatt_info[] = {
95 	 * 	{ 1, "OB" },
96 	 * 	{ 2, "OL" },
97 	 * 	{ 0, NULL }
98 	 * };
99 	 */
100         { "ups.mfr", ST_FLAG_STRING, SU_INFOSIZE, NULL, "Tripp Lite / Phoenixtec",
101                 SU_FLAG_STATIC | SU_FLAG_ABSENT | SU_FLAG_OK, NULL },
102 
103 	/* upsBaseIdentModel.0 = STRING: "Intelligent" */
104 	{ "ups.model", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.935.1.1.1.1.1.1.0", "Generic Phoenixtec SNMP device", SU_FLAG_OK, NULL },
105 	/* upsBaseBatteryStatus.0 = INTEGER: batteryNormal(2) */
106 	{ "ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.935.1.1.1.2.1.1.0", "", SU_STATUS_BATT | SU_TYPE_INT | SU_FLAG_OK, xpcc_onbatt_info },
107 	/* upsSmartBatteryCapacity.0 = INTEGER: 100 */
108 	{ "battery.charge", 0, 1, ".1.3.6.1.4.1.935.1.1.1.2.2.1.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
109 	/* upsSmartBatteryTemperature.0 = INTEGER: 260 */
110 	{ "ups.temperature", 0, 0.1, ".1.3.6.1.4.1.935.1.1.1.2.2.3.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
111 	/* upsSmartInputLineVoltage.0 = INTEGER: 1998 */
112 	{ "input.voltage", 0, 0.1, ".1.3.6.1.4.1.935.1.1.1.3.2.1.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
113 	/* upsBaseOutputStatus.0 = INTEGER: onLine(2) */
114 	{ "ups.status", ST_FLAG_STRING, SU_INFOSIZE, ".1.3.6.1.4.1.935.1.1.1.4.1.1.0", "", SU_TYPE_INT | SU_STATUS_PWR, xpcc_power_info },
115 	/* upsSmartOutputVoltage.0 = INTEGER: 2309 */
116 	{ "output.voltage", 0, 0.1, ".1.3.6.1.4.1.935.1.1.1.4.2.1.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
117 	/* upsSmartOutputFrequency.0 = INTEGER: 500 */
118 	{ "output.frequency", 0, 0.1, ".1.3.6.1.4.1.935.1.1.1.4.2.2.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
119 	/* upsSmartOutputLoad.0 = INTEGER: 7 */
120 	{ "ups.load", 0, 1, ".1.3.6.1.4.1.935.1.1.1.4.2.3.0", NULL, SU_TYPE_INT | SU_FLAG_OK, NULL },
121 
122 	/* end of structure. */
123 	{ NULL, 0, 0, NULL, NULL, 0, NULL }
124 };
125 
126 mib2nut_info_t	xppc = { "xppc", XPPC_MIB_VERSION, NULL, NULL, xppc_mib, XPPC_SYSOID };
127