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:
Kris Moore
2016-01-08 14:47:55 -05:00
parent adf6fe6ab7
commit 9160af8912
3 changed files with 53 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -17,6 +17,7 @@ public:
// List schedule snapshots
static QJsonObject listCron();
static QJsonObject listSnap(QJsonObject jsin);
static QJsonObject settings();
};
} //end of pcbsd namespace

View File

@@ -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