mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add a new API call for sysadm/lifepserver which returns the system-wide
settings of the utility
REST Request:
-------------------------------
PUT /sysadm/lifepreserver
{
"action" : "settings"
}
REST Response:
-------------------------------
{
"args": {
"settings": {
"diskwarn": "85%",
"email": "WARN",
"emailaddress": "krismoore134@gmail.com",
"recursive": "ON"
}
}
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"args" : {
"action" : "settings"
},
"namespace" : "sysadm",
"name" : "lifepreserver"
}
WebSocket Response:
-------------------------------
{
"args": {
"settings": {
"diskwarn": "85%",
"email": "WARN",
"emailaddress": "krismoore134@gmail.com",
"recursive": "ON"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -105,3 +105,51 @@ QJsonObject LifePreserver::listSnap(QJsonObject jsin) {
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Return a list of settings for life-preserver
|
||||
QJsonObject LifePreserver::settings() {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList output = General::RunCommand("lpreserver get").split("\n");
|
||||
QStringList setitems;
|
||||
QString tmpkey;
|
||||
QRegExp sep("\\s+");
|
||||
|
||||
// Parse the output
|
||||
bool inSection = false;
|
||||
for ( int i = 0; i < output.size(); i++)
|
||||
{
|
||||
if ( output.at(i).indexOf("-----------------") != -1 ) {
|
||||
inSection = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inSection)
|
||||
continue;
|
||||
|
||||
if ( output.at(i).isEmpty() || output.at(i).indexOf("-----------------") != -1 )
|
||||
break;
|
||||
|
||||
// Breakdown the setting we got
|
||||
tmpkey = "";
|
||||
setitems.clear();
|
||||
setitems << output.at(i).section(":", 0, 0).simplified();
|
||||
setitems << output.at(i).section(":", 1, 1).simplified();
|
||||
if ( setitems.at(0) == "Recursive mode" )
|
||||
tmpkey = "recursive";
|
||||
if ( setitems.at(0) == "E-mail notifications" )
|
||||
tmpkey = "email";
|
||||
if ( setitems.at(0) == "E-mail addresses" )
|
||||
tmpkey = "emailaddress";
|
||||
if ( setitems.at(0) == "Disk space warn at" )
|
||||
tmpkey = "diskwarn";
|
||||
|
||||
// Unknown key we dont support?
|
||||
if ( tmpkey.isEmpty() )
|
||||
continue;
|
||||
|
||||
retObject.insert(tmpkey, setitems.at(1));
|
||||
}
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
// List schedule snapshots
|
||||
static QJsonObject listCron();
|
||||
static QJsonObject listSnap(QJsonObject jsin);
|
||||
static QJsonObject settings();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
@@ -149,6 +149,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const Q
|
||||
ok = true;
|
||||
out->insert("listsnap", sysadm::LifePreserver::listSnap(in_args.toObject()));
|
||||
}
|
||||
if(act=="settings"){
|
||||
ok = true;
|
||||
out->insert("settings", sysadm::LifePreserver::settings());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
|
||||
Reference in New Issue
Block a user