mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 02:20:17 +00:00
[API CHANGE] Adjust the output structure for the "sysctllist" action in the system manager.
The output now returns objects with value, type, and description of each sysctl instead of just the values.
REST Request (example):
-------------------------------
PUT /sysadm/systemmanager
{
"action" : "sysctllist"
}
WebSocket Request:
-------------------------------
{
"id" : "fooid",
"namespace" : "sysadm",
"args" : {
"action" : "sysctllist"
},
"name" : "systemmanager"
}
Response:
-------------------------------
{
"args": {
"sysctllist": {
"compat.ia32.maxdsiz": {
"type": "unsigned long",
"value": "536870912"
},
"compat.ia32.maxssiz": {
"type": "unsigned long",
"value": "67108864"
},
"compat.ia32.maxvmem": {
"type": "unsigned long",
"value": "0"
},
"compat.linux.osname": {
"description": "Linux kernel OS name",
"type": "string",
"value": "Linux"
},
"compat.linux.osrelease": {
"description": "Linux kernel OS release",
"type": "string",
"value": "2.6.32"
},
"compat.linux.oss_version": {
"description": "Linux OSS version",
"type": "integer",
"value": "198144"
}
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -586,6 +586,10 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemMgmtRequest(const QJso
|
||||
ok = true;
|
||||
out->insert("reboot", sysadm::SysMgmt::systemReboot());
|
||||
}
|
||||
/*else if(act=="getsysctl"){
|
||||
ok = true;
|
||||
out->insert("getsysctl", sysadm::SysMgmt::getSysctl(in_args.toObject()));
|
||||
}*/
|
||||
else if(act=="setsysctl"){
|
||||
ok = true;
|
||||
out->insert("setsysctl", sysadm::SysMgmt::setSysctl(in_args.toObject()));
|
||||
|
||||
@@ -293,6 +293,26 @@ QJsonObject SysMgmt::procInfo() {
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Get a sysctl
|
||||
QJsonObject SysMgmt::getSysctl(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList sysctl;
|
||||
if(jsin.value("sysctl").isArray()){ sysctl = General::JsonArrayToStringList(jsin.value("sysctl").toArray()); }
|
||||
else if(jsin.value("sysctl").isString()){ sysctl << jsin.value("sysctl").toString(); }
|
||||
if ( sysctl.isEmpty() ) {
|
||||
retObject.insert("error", "Missing required key 'sysctl'");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
QStringList output = General::RunCommand("sysctl", sysctl).split("\n");
|
||||
for(int i=0; i<output.length(); i++){
|
||||
if( !output[i].contains(":") ){ continue; }
|
||||
retObject.insert(output[i].section(":",0,0), output[i].section(":",1,-1).simplified());
|
||||
}
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// Set a sysctl
|
||||
QJsonObject SysMgmt::setSysctl(QJsonObject jsin) {
|
||||
QJsonObject retObject;
|
||||
@@ -319,18 +339,29 @@ QJsonObject SysMgmt::sysctlList() {
|
||||
QJsonObject retObject;
|
||||
|
||||
// This can be cleaned up and not use CLI
|
||||
QStringList output = General::RunCommand("sysctl -W -a").split("\n");
|
||||
QStringList output = General::RunCommand("sysctl -aW").split("\n");
|
||||
QStringList details = General::RunCommand("sysctl -aWdt").split("\n");
|
||||
|
||||
QString sysctl, value;
|
||||
QString sysctl, type, description;
|
||||
for(int i=0; i<output.length(); i++){
|
||||
if ( output.at(i).isEmpty())
|
||||
continue;
|
||||
|
||||
if ( output.at(i).isEmpty()){ continue; }
|
||||
QJsonObject tmp;
|
||||
sysctl = output.at(i).section(":", 0, 0);
|
||||
value = output.at(i).section(":", 1, -1).simplified();
|
||||
retObject.insert(sysctl, value);
|
||||
tmp.insert("value", output.at(i).section(":", 1, -1).simplified() );
|
||||
retObject.insert(sysctl, tmp);
|
||||
}
|
||||
for(int i=0; i<details.length(); i++){
|
||||
if ( details.at(i).isEmpty() ){ continue; }
|
||||
sysctl = details[i].section(":",0,0);
|
||||
type = details[i].section(":",1,1).simplified();
|
||||
description = details[i].section(":",2,-1).simplified();
|
||||
if(retObject.contains(sysctl)){
|
||||
QJsonObject tmp = retObject.value(sysctl).toObject();
|
||||
tmp.insert("type", type);
|
||||
if(!description.isEmpty()){ tmp.insert("description", description); }
|
||||
retObject.insert(sysctl, tmp); //replace the sysctl object into the output object
|
||||
}
|
||||
}
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
static QJsonObject killProc(QJsonObject);
|
||||
static QJsonObject memoryStats();
|
||||
static QJsonObject procInfo();
|
||||
static QJsonObject getSysctl(QJsonObject);
|
||||
static QJsonObject setSysctl(QJsonObject);
|
||||
static QJsonObject sysctlList();
|
||||
static QJsonObject systemInfo();
|
||||
|
||||
Reference in New Issue
Block a user