mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 18:20:23 +00:00
Add LifePreserver API first list-cron call
This commit is contained in:
@@ -49,11 +49,5 @@ int main( int argc, char ** argv )
|
||||
qDebug() << " - Allow Secure Wifi:" << set.wifisecurity;
|
||||
}
|
||||
|
||||
// LP tests
|
||||
qDebug() << "Life-Preserver::listCron()";
|
||||
QList<QStringList> cronSnaps = sysadm::LifePreserver::listCron();
|
||||
for ( int i = 0; i < cronSnaps.size(); i++)
|
||||
qDebug() << cronSnaps.at(i);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
using namespace sysadm;
|
||||
|
||||
// Build list of scheduled cron snapshot jobs
|
||||
QList<QStringList> LifePreserver::listCron() {
|
||||
QJsonObject LifePreserver::listCron() {
|
||||
QJsonObject retObject;
|
||||
|
||||
QStringList output = General::RunCommand("lpreserver listcron").split("\n");
|
||||
QList<QStringList> snaps;
|
||||
QStringList snapitems;
|
||||
@@ -33,14 +35,17 @@ QList<QStringList> LifePreserver::listCron() {
|
||||
if ( output.at(i).isEmpty() || output.at(i).indexOf("-----------------") != -1 )
|
||||
break;
|
||||
|
||||
// Save this cron job
|
||||
// Breakdown this cron job
|
||||
snapitems.clear();
|
||||
snapitems << output.at(i).section("-", 0, 0).simplified();
|
||||
snapitems << output.at(i).section("-", 1, 1).simplified();
|
||||
snapitems << output.at(i).section("-", 2, 2).simplified().replace("total: ", "");
|
||||
|
||||
snaps << snapitems;
|
||||
QJsonObject values;
|
||||
values.insert("schedule", snapitems.at(1));
|
||||
values.insert("keep", snapitems.at(2));
|
||||
retObject.insert(snapitems.at(0), values);
|
||||
}
|
||||
|
||||
return snaps;
|
||||
return retObject;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#ifndef __PCBSD_LIB_UTILS_LIFEPRESERVER_H
|
||||
#define __PCBSD_LIB_UTILS_LIFEPRESERVER_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include "sysadm-global.h"
|
||||
|
||||
namespace sysadm{
|
||||
@@ -14,7 +15,7 @@ namespace sysadm{
|
||||
class LifePreserver{
|
||||
public:
|
||||
// List schedule snapshots
|
||||
static QList<QStringList> listCron();
|
||||
static QJsonObject listCron();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
//sysadm library interface classes
|
||||
#include "sysadm-general.h"
|
||||
#include "sysadm-network.h"
|
||||
#include "sysadm-lifepreserver.h"
|
||||
|
||||
#include "syscache-client.h"
|
||||
#include "dispatcher-client.h"
|
||||
@@ -30,6 +31,8 @@ RestOutputStruct::ExitCode WebSocket::EvaluateBackendRequest(QString namesp, QSt
|
||||
return EvaluateSyscacheRequest(args, out);
|
||||
}else if(namesp=="sysadm" && name=="network"){
|
||||
return EvaluateSysadmNetworkRequest(args, out);
|
||||
}else if(namesp=="sysadm" && name=="lifepreserver"){
|
||||
return EvaluateSysadmLifePreserverRequest(args, out);
|
||||
}else{
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
@@ -130,3 +133,27 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmNetworkRequest(const QJsonVa
|
||||
}
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
//==== SYSADM -- LifePreserver ====
|
||||
RestOutputStruct::ExitCode WebSocket::EvaluateSysadmLifePreserverRequest(const QJsonValue in_args, QJsonObject *out){
|
||||
if(in_args.isObject()){
|
||||
QStringList keys = in_args.toObject().keys();
|
||||
bool ok = false;
|
||||
if(keys.contains("action")){
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="listcron"){
|
||||
ok = true;
|
||||
out->insert("listcron", sysadm::LifePreserver::listCron());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
//If nothing done - return the proper code
|
||||
if(!ok){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
}else{ // if(in_args.isArray()){
|
||||
return RestOutputStruct::BADREQUEST;
|
||||
}
|
||||
return RestOutputStruct::OK;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// =================================
|
||||
#include "WebSocket.h"
|
||||
|
||||
#define DEBUG 0
|
||||
#define DEBUG 1
|
||||
#define IDLETIMEOUTMINS 30
|
||||
|
||||
WebSocket::WebSocket(QWebSocket *sock, QString ID, AuthorizationManager *auth){
|
||||
|
||||
@@ -52,8 +52,10 @@ private:
|
||||
// -- Individual subsystems
|
||||
RestOutputStruct::ExitCode EvaluateSyscacheRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
RestOutputStruct::ExitCode EvaluateDispatcherRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm library/subsystems
|
||||
// -- sysadm Network API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmNetworkRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
// -- sysadm LifePreserver API
|
||||
RestOutputStruct::ExitCode EvaluateSysadmLifePreserverRequest(const QJsonValue in_args, QJsonObject *out);
|
||||
|
||||
private slots:
|
||||
void checkIdle(); //see if the currently-connected client is idle
|
||||
|
||||
Reference in New Issue
Block a user