Skip to content

Commit c05ca1f

Browse files
authored
Merge pull request networkupstools#2363 from jimklimov/nutconf-vocabulary
Extend `nutconf` vocabulary
2 parents fc2ab18 + a760767 commit c05ca1f

File tree

6 files changed

+57
-24
lines changed

6 files changed

+57
-24
lines changed

common/nutconf.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Copyright (C)
55
2012 Emilien Kia <[email protected]>
6+
2024 Jim Klimov <[email protected]>
67
78
This program is free software; you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
@@ -1075,6 +1076,18 @@ UpsmonConfiguration::NotifyType UpsmonConfiguration::NotifyTypeFromString(const
10751076
return NOTIFY_NOCOMM;
10761077
else if(str=="NOPARENT")
10771078
return NOTIFY_NOPARENT;
1079+
else if(str=="CAL")
1080+
return NOTIFY_CAL;
1081+
else if(str=="NOTCAL")
1082+
return NOTIFY_NOTCAL;
1083+
else if(str=="OFF")
1084+
return NOTIFY_OFF;
1085+
else if(str=="NOTOFF")
1086+
return NOTIFY_NOTOFF;
1087+
else if(str=="BYPASS")
1088+
return NOTIFY_BYPASS;
1089+
else if(str=="NOTBYPASS")
1090+
return NOTIFY_NOTBYPASS;
10781091
else
10791092
return NOTIFY_TYPE_MAX;
10801093
}
@@ -1177,7 +1190,7 @@ void UpsmonConfigParser::onParseDirective(const std::string& directiveName, char
11771190
monitor.powerValue = StringToSettableNumber<unsigned int>(*it++);
11781191
monitor.username = *it++;
11791192
monitor.password = *it++;
1180-
monitor.isMaster = (*it) == "master";
1193+
monitor.isMaster = (*it) == "primary"; // master for NUT v2.7.4 and older
11811194
_config->monitors.push_back(monitor);
11821195
}
11831196
}
@@ -1220,7 +1233,7 @@ void UpsmonConfigParser::onParseDirective(const std::string& directiveName, char
12201233
{
12211234
if(values.size()>0)
12221235
{
1223-
_config->hotSync = StringToSettableNumber<unsigned int>(values.front());
1236+
_config->hostSync = StringToSettableNumber<unsigned int>(values.front());
12241237
}
12251238
}
12261239
else if(directiveName == "DEADTIME")
@@ -1570,11 +1583,11 @@ UpsdUsersConfiguration::upsmon_mode_t UpsdUsersConfiguration::getUpsmonMode() co
15701583
{
15711584
std::string mode_str = getStr("upsmon", "upsmon");
15721585

1573-
if ("master" == mode_str)
1574-
return UPSMON_MASTER;
1586+
if ("primary" == mode_str || "master" == mode_str)
1587+
return UPSMON_PRIMARY;
15751588

1576-
if ("slave" == mode_str)
1577-
return UPSMON_SLAVE;
1589+
if ("secondary" == mode_str || "slave" == mode_str)
1590+
return UPSMON_SECONDARY;
15781591

15791592
return UPSMON_UNDEF;
15801593
}
@@ -1584,7 +1597,8 @@ void UpsdUsersConfiguration::setUpsmonMode(upsmon_mode_t mode)
15841597
{
15851598
assert(UPSMON_UNDEF != mode);
15861599

1587-
setStr("upsmon", "upsmon", (UPSMON_MASTER == mode ? "master" : "slave"));
1600+
setStr("upsmon", "upsmon", (UPSMON_PRIMARY == mode ? "primary" : "secondary"));
1601+
/* NUT v2.7.4 and older: setStr("upsmon", "upsmon", (UPSMON_PRIMARY == mode ? "master" : "slave")); */
15881602
}
15891603

15901604

common/nutwriter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Copyright (C)
55
2012 Vaclav Krpec <[email protected]>
6+
2024 Jim Klimov <[email protected]>
67
78
This program is free software; you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
@@ -240,6 +241,12 @@ const NotifyFlagsStrings::TypeStrings NotifyFlagsStrings::type_str = {
240241
"REPLBATT", // NOTIFY_REPLBATT
241242
"NOCOMM", // NOTIFY_NOCOMM
242243
"NOPARENT", // NOTIFY_NOPARENT
244+
"CAL\t", // NOTIFY_CAL (including padding)
245+
"NOTCAL", // NOTIFY_NOTCAL
246+
"OFF\t", // NOTIFY_OFF (including padding)
247+
"NOTOFF", // NOTIFY_NOTOFF
248+
"BYPASS", // NOTIFY_BYPASS
249+
"NOTBYPASS", // NOTIFY_NOTBYPASS
243250
};
244251

245252

@@ -391,8 +398,9 @@ static std::string serializeMonitor(const UpsmonConfiguration::Monitor & monitor
391398
// Username & password
392399
directive << monitor.username << ' ' << monitor.password << ' ';
393400

394-
// Master/slave
395-
directive << (monitor.isMaster ? "master" : "slave");
401+
// Primary/secondary (legacy master/slave)
402+
directive << (monitor.isMaster ? "primary" : "secondary");
403+
/* NUT v2.7.4 and older: directive << (monitor.isMaster ? "master" : "slave");*/
396404

397405
return directive.str();
398406
}
@@ -438,7 +446,7 @@ NutWriter::status_t UpsmonConfigWriter::writeConfig(const UpsmonConfiguration &
438446
UPSMON_DIRECTIVEX("MINSUPPLIES", unsigned int, config.minSupplies, false);
439447
UPSMON_DIRECTIVEX("POLLFREQ", unsigned int, config.poolFreq, false);
440448
UPSMON_DIRECTIVEX("POLLFREQALERT", unsigned int, config.poolFreqAlert, false);
441-
UPSMON_DIRECTIVEX("HOSTSYNC", unsigned int, config.hotSync, false);
449+
UPSMON_DIRECTIVEX("HOSTSYNC", unsigned int, config.hostSync, false);
442450
UPSMON_DIRECTIVEX("DEADTIME", unsigned int, config.deadTime, false);
443451
UPSMON_DIRECTIVEX("RBWARNTIME", unsigned int, config.rbWarnTime, false);
444452
UPSMON_DIRECTIVEX("NOCOMMWARNTIME", unsigned int, config.noCommWarnTime, false);

include/nutconf.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Copyright (C)
55
2012 Emilien Kia <[email protected]>
6+
2024 Jim Klimov <[email protected]>
67
78
This program is free software; you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
@@ -637,7 +638,7 @@ class UpsmonConfiguration : public Serialisable
637638
void parseFromString(const std::string& str);
638639

639640
Settable<std::string> runAsUser, shutdownCmd, notifyCmd, powerDownFlag;
640-
Settable<unsigned int> minSupplies, poolFreq, poolFreqAlert, hotSync;
641+
Settable<unsigned int> minSupplies, poolFreq, poolFreqAlert, hostSync;
641642
Settable<unsigned int> deadTime, rbWarnTime, noCommWarnTime, finalDelay;
642643

643644
enum NotifyFlag {
@@ -658,6 +659,12 @@ class UpsmonConfiguration : public Serialisable
658659
NOTIFY_REPLBATT,
659660
NOTIFY_NOCOMM,
660661
NOTIFY_NOPARENT,
662+
NOTIFY_CAL,
663+
NOTIFY_NOTCAL,
664+
NOTIFY_OFF,
665+
NOTIFY_NOTOFF,
666+
NOTIFY_BYPASS,
667+
NOTIFY_NOTBYPASS,
661668
NOTIFY_TYPE_MAX
662669
};
663670

@@ -1077,8 +1084,8 @@ class UpsdUsersConfiguration : public GenericConfiguration
10771084
/** upsmon mode */
10781085
typedef enum {
10791086
UPSMON_UNDEF = 0, /**< Unknown mode */
1080-
UPSMON_MASTER, /**< Master mode */
1081-
UPSMON_SLAVE, /**< Slave mode */
1087+
UPSMON_PRIMARY, /**< Primary (legacy "Master") mode */
1088+
UPSMON_SECONDARY, /**< Secondary (legacy "Slave") mode */
10821089
} upsmon_mode_t;
10831090

10841091
/** User-specific configuration attributes getters and setters \{ */

tests/nutconf_parser_ut.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void NutConfTest::testUpsmonConfigParser()
278278
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find POWERDOWNFLAG '/etc/killpower'", string("/etc/killpower"), *conf.powerDownFlag);
279279
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find POLLFREQ 30", 30u, *conf.poolFreq);
280280
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find POLLFREQALERT 5", 5u, *conf.poolFreqAlert);
281-
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find HOSTSYNC 15", 15u, *conf.hotSync);
281+
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find HOSTSYNC 15", 15u, *conf.hostSync);
282282
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find DEADTIME 15", 15u, *conf.deadTime);
283283
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find RBWARNTIME 43200", 43200u, *conf.rbWarnTime);
284284
CPPUNIT_ASSERT_EQUAL_MESSAGE("Cannot find NOCOMMWARNTIME 300", 300u, *conf.noCommWarnTime);

tests/nutconf_ut.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Copyright (C)
55
2012 Vaclav Krpec <[email protected]>
6+
2024 Jim Klimov <[email protected]>
67
78
This program is free software; you can redistribute it and/or modify
89
it under the terms of the GNU General Public License as published by
@@ -211,7 +212,7 @@ void NutConfigUnitTest::testUpsdUsersConfiguration() {
211212
load(static_cast<nut::Serialisable *>(&config), ABS_TOP_SRCDIR "/conf/upsd.users.sample");
212213

213214
config.setPassword("upsmon", "ytrewq");
214-
config.setUpsmonMode(nut::UpsdUsersConfiguration::UPSMON_MASTER);
215+
config.setUpsmonMode(nut::UpsdUsersConfiguration::UPSMON_PRIMARY);
215216

216217
config.setPassword("admin", "qwerty=ui");
217218
config.setActions("admin", nut::ConfigParamList(1, "SET"));
@@ -225,7 +226,7 @@ void NutConfigUnitTest::testUpsdUsersConfiguration() {
225226
"\n"
226227
"[upsmon]\n"
227228
"\tpassword = ytrewq\n"
228-
"\tupsmon master\n"
229+
"\tupsmon primary\n"
229230
"\n"
230231
);
231232
}

tools/nutconf/nutconf-cli.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
2-
* Copyright (C) 2013 - EATON
2+
* Copyright (C)
3+
* 2013 - EATON
4+
* 2024 - Jim Klimov <[email protected]>
35
*
46
* This program is free software; you can redistribute it and/or modify
57
* it under the terms of the GNU General Public License as published by
@@ -126,11 +128,12 @@ const char * Usage::s_text[] = {
126128
"",
127129
"NUT modes: standalone, netserver, netclient, controlled, manual, none",
128130
"Monitor is specified by the following sequence:",
129-
" <ups_ID> <host>[:<port>] <power_value> <user> <passwd> (\"master\"|\"slave\")",
131+
" <ups_ID> <host>[:<port>] <power_value> <user> <passwd> (\"primary\"|\"secondary\")",
130132
"UPS device is specified by the following sequence:",
131133
" <ups_ID> <driver> <port> [<key>=<value>]*",
132134
"Notification types:",
133-
" ONLINE, ONBATT, LOWBATT, FSD, COMMOK, COMMBAD, SHUTDOWN, REPLBATT, NOCOMM, NOPARENT",
135+
" ONLINE, ONBATT, LOWBATT, FSD, COMMOK, COMMBAD, SHUTDOWN, REPLBATT, NOCOMM, NOPARENT,",
136+
" CAL, NOTCAL, OFF, NOTOFF, BYPASS, NOTBYPASS",
134137
"Notification flags:",
135138
" SYSLOG, WALL, EXEC, IGNORE",
136139
"User specification:",
@@ -2087,7 +2090,7 @@ static nut::UpsmonConfiguration::Monitor monitor(
20872090
monitor.hostname = host_port.substr(0, colon_idx);
20882091
monitor.port = port;
20892092
monitor.powerValue = power_value;
2090-
monitor.isMaster = "master" == mode;
2093+
monitor.isMaster = ("primary" == mode || "master" == mode);
20912094

20922095
return monitor;
20932096
}
@@ -2591,11 +2594,11 @@ static void setUsers(
25912594
nut::UpsdUsersConfiguration::upsmon_mode_t mode =
25922595
nut::UpsdUsersConfiguration::UPSMON_UNDEF;
25932596

2594-
if ("master" == upsmon_user->mode)
2595-
mode = nut::UpsdUsersConfiguration::UPSMON_MASTER;
2597+
if ("primary" == upsmon_user->mode || "master" == upsmon_user->mode)
2598+
mode = nut::UpsdUsersConfiguration::UPSMON_PRIMARY;
25962599

2597-
else if ("slave" == upsmon_user->mode)
2598-
mode = nut::UpsdUsersConfiguration::UPSMON_SLAVE;
2600+
else if ("secondary" == upsmon_user->mode || "slave" == upsmon_user->mode)
2601+
mode = nut::UpsdUsersConfiguration::UPSMON_SECONDARY;
25992602

26002603
else {
26012604
std::cerr

0 commit comments

Comments
 (0)