From 8f4deefda26d0ebdb37c82dcf74f32b6fc893c59 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Tue, 12 Jan 2016 13:03:51 -0500 Subject: [PATCH] This is a change to the "listcron" API call, specifically it adds the "scrub":"" data, so if a scrub is scheduled for a pool, it will be listed alongside the snap schedule, or on its own if no snapshots are scheduled REST Request: ------------------------------- PUT /sysadm/lifepreserver { "action" : "listcron" } REST Response: ------------------------------- { "args": { "listcron": { "tank1": { "keep": "3", "schedule": "daily@18", "scrub": "daily@22" } } } } WebSocket Request: ------------------------------- { "name" : "lifepreserver", "id" : "fooid", "namespace" : "sysadm", "args" : { "action" : "listcron" } } WebSocket Response: ------------------------------- { "args": { "listcron": { "tank1": { "keep": "3", "schedule": "daily@18", "scrub": "daily@22" } } }, "id": "fooid", "name": "response", "namespace": "sysadm" } --- src/library/sysadm-lifepreserver.cpp | 53 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/src/library/sysadm-lifepreserver.cpp b/src/library/sysadm-lifepreserver.cpp index 211a3a7..21e1efa 100644 --- a/src/library/sysadm-lifepreserver.cpp +++ b/src/library/sysadm-lifepreserver.cpp @@ -20,33 +20,58 @@ QJsonObject LifePreserver::listCron() { QStringList output = General::RunCommand("lpreserver listcron").split("\n"); QList snaps; - QStringList snapitems; // Parse the output - bool inSection = false; + bool inSnapSection = false; + bool inScrubSection = false; for ( int i = 0; i < output.size(); i++) { if ( output.at(i).indexOf("-----------------") != -1 ) { - inSection = true; + inSnapSection = true; continue; } - if (!inSection) + if (!inSnapSection) continue; + if ( output.at(i).indexOf("Pools scheduled for scrub") != -1 ) { + inScrubSection = true; + continue; + } + if ( output.at(i).isEmpty() || output.at(i).indexOf("-----------------") != -1 ) - break; + continue; - // 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: ", ""); + if ( inSnapSection && ! inScrubSection ) { + // Breakdown this cron job + QString pool = output.at(i).section("-", 0, 0).simplified(); + QString freq = output.at(i).section("-", 1, 1).simplified(); + QString keep = output.at(i).section("-", 2, 2).simplified().replace("total: ", ""); - QJsonObject values; - values.insert("schedule", snapitems.at(1)); - values.insert("keep", snapitems.at(2)); - retObject.insert(snapitems.at(0), values); + QJsonObject values; + values.insert("schedule", freq); + values.insert("keep", keep); + retObject.insert(pool, values); + } else if (inSnapSection && inScrubSection ) { + // Add a cron scrub + QString pool = output.at(i).section("-", 0, 0).simplified(); + QString freq = output.at(i).section("-", 1, 1).simplified().replace(" ", ""); + qDebug() << "Found scrub:" << pool << freq; + + QJsonObject values; + QStringList keys = retObject.keys(); + if( keys.contains(pool)){ + // We have an existing pool object, add it + values = retObject[pool].toObject(); + retObject.remove(pool); + values.insert("scrub", freq); + retObject.insert(pool, values); + } else { + // Add a new pool object with the scrub + values.insert("scrub", freq); + retObject.insert(pool, values); + } + } } return retObject;