Commit 51ec1126 authored by remy's avatar remy
Browse files

update with borg backup and some fix

parent a543788e
...@@ -82,7 +82,7 @@ mysql -uroot -p jsonreader2 < sql/CReaderPanel.sql ...@@ -82,7 +82,7 @@ mysql -uroot -p jsonreader2 < sql/CReaderPanel.sql
To use other JSON reports, you need to clone the plugin (or the SaltStack formula), and then, uncomment or add specific report in `check_salt_json`. Then, add the jsonreader2 plugin title in `config/Plugin.php` (`$SECTION`). To use other JSON reports, you need to clone the plugin (or the SaltStack formula), and then, uncomment or add specific report in `check_salt_json`. Then, add the jsonreader2 plugin title in `config/Plugin.php` (`$SECTION`).
For a new plugin from your own, or an update of jsonreader2, you will need to also add it in the database, and a PHP way to parse the JSON file. Adding it in the database can be done in the WebUI, using the _Misc_ menu items. For a new plugin from your own, or an update of jsonreader2, you will need to also add it in the database, and a PHP way to parse the JSON file. Adding it in the database can be done in the WebUI, using the `Configuration` menu item (standalone version, `misc` otherwise).
### Specific plugin formulas ### Specific plugin formulas
...@@ -91,7 +91,7 @@ All these plugins need to be set accordingly to your SaltStack configuration. ...@@ -91,7 +91,7 @@ All these plugins need to be set accordingly to your SaltStack configuration.
- To check disks smart status, take a look at [`check_disks`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_disks), - To check disks smart status, take a look at [`check_disks`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_disks),
- To check services, take a look at the [`check_services`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_services) formula, - To check services, take a look at the [`check_services`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_services) formula,
- To check D state processes, take a look at [`get_d_states`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/get_d_states) formula, - To check D state processes, take a look at [`get_d_states`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/get_d_states) formula,
<!--- To check borgbackup report, take a look at [`borgbackup`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/borgbackup) formula,--> - To check borgbackup report, take a look at [`borgbackup`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/borgbackup) formula.
### Other Json reports ### Other Json reports
......
...@@ -136,6 +136,13 @@ if($action == "save") { ...@@ -136,6 +136,13 @@ if($action == "save") {
} }
if($action == "delete") { if($action == "delete") {
$current_Creader = CReaderQuery::getCReaderByID($db, $ID); $current_Creader = CReaderQuery::getCReaderByID($db, $ID);
$corresponding_panel = CReaderPanelQuery::getCReaderPanelFromCReaderID($db, $ID)[0];
$PanelTitle = $corresponding_panel->PanelTitle;
$message = CReaderPanelQuery::deleteCReaderPanel($db, $corresponding_panel);
if(!JSONREADER2_STANDALONE) {
$log = new Log(-1, "admin", $PanelTitle, "delete", $message->value, $today, -1);
LogDBQuery::createLog($db, $log);
}
$message = CReaderQuery::deleteCReader($db, $current_Creader[0]); $message = CReaderQuery::deleteCReader($db, $current_Creader[0]);
if(!JSONREADER2_STANDALONE) { if(!JSONREADER2_STANDALONE) {
$log = new Log(-1, "admin", $ID, "delete", $message->value, $today, -1); $log = new Log(-1, "admin", $ID, "delete", $message->value, $today, -1);
......
...@@ -30,6 +30,7 @@ $today = date("Y-m-d G:i:s"); ...@@ -30,6 +30,7 @@ $today = date("Y-m-d G:i:s");
$ID = -1; $ID = -1;
$PanelTitle = NULL; $PanelTitle = NULL;
$position = NULL; $position = NULL;
$CReaderID = NULL;
if(isset($_POST['action'])) { if(isset($_POST['action'])) {
$action = $_POST['action']; $action = $_POST['action'];
...@@ -62,13 +63,14 @@ if(isset($_POST['position'])) { ...@@ -62,13 +63,14 @@ if(isset($_POST['position'])) {
$position = $_POST['position']; $position = $_POST['position'];
} }
$creaderpanel = new CReaderPanel($ID, NULL, $PanelTitle, $position); $creaderpanel = new CReaderPanel($ID, $CReaderID, $PanelTitle, $position);
if($action == "create") { if($action == "create") {
/* uncomment following and comment header Location at the end of this file bellow for debug */ /* uncomment following and comment header Location at the end of this file bellow for debug */
//var_dump($_POST); //var_dump($_POST);
$creaderpanel->escape($db); $creaderpanel->escape($db);
$message = $db->create($creaderpanel); $message = CReaderPanelQuery::createCReaderPanelWithoutCReaderID($db, $creaderpanel);
//$message = $db->create($creaderpanel);
if(!JSONREADER2_STANDALONE) { if(!JSONREADER2_STANDALONE) {
$log = new Log(-1, "admin", $creaderpanel->ID, "insert", $message->value, $today, -1); $log = new Log(-1, "admin", $creaderpanel->ID, "insert", $message->value, $today, -1);
LogDBQuery::createLog($db, $log); LogDBQuery::createLog($db, $log);
...@@ -89,7 +91,7 @@ if($action == "delete") { ...@@ -89,7 +91,7 @@ if($action == "delete") {
} }
} }
} }
$message = CReaderPanelQuery::deleteCReaderPanel($db, $PanelTitle); $message = CReaderPanelQuery::deleteCReaderPanelByTitle($db, $PanelTitle);
if(!JSONREADER2_STANDALONE) { if(!JSONREADER2_STANDALONE) {
$log = new Log(-1, "admin", $PanelTitle, "delete", $message->value, $today, -1); $log = new Log(-1, "admin", $PanelTitle, "delete", $message->value, $today, -1);
LogDBQuery::createLog($db, $log); LogDBQuery::createLog($db, $log);
......
...@@ -81,6 +81,16 @@ class CReaderPanelQuery ...@@ -81,6 +81,16 @@ class CReaderPanelQuery
} }
} }
public static function createCReaderPanelWithoutCReaderID(DBquery $db, CReaderPanel $CReaderPanel) {
$result = mysqli_query($db->dbh, $CReaderPanel->getInsertWithoutCReaderID());
if($result) {
return "";
} else {
var_dump(mysqli_error($db->dbh));
die();
}
}
public static function getNextPosCReaderPanel(DBquery $db) { public static function getNextPosCReaderPanel(DBquery $db) {
$result = mysqli_query($db->dbh, "SELECT MAX(`PanelPosition`) as maxpos FROM `CReaderPanel`;"); $result = mysqli_query($db->dbh, "SELECT MAX(`PanelPosition`) as maxpos FROM `CReaderPanel`;");
while($row = mysqli_fetch_assoc($result)){ while($row = mysqli_fetch_assoc($result)){
...@@ -90,7 +100,17 @@ class CReaderPanelQuery ...@@ -90,7 +100,17 @@ class CReaderPanelQuery
return 0; return 0;
} }
public static function deleteCReaderPanel(DBquery $db, $PanelTitle) { public static function deleteCReaderPanel(DBquery $db, CReaderPanel $CReaderPanel) {
$result = mysqli_query($db->dbh, $CReaderPanel->getDelete());
if($result) {
return "";
} else {
var_dump(mysqli_error($db->dbh));
die();
}
}
public static function deleteCReaderPanelByTitle(DBquery $db, $PanelTitle) {
$Panels = CReaderPanelQuery::getAllCReaderPanelByTitle($db, $PanelTitle); $Panels = CReaderPanelQuery::getAllCReaderPanelByTitle($db, $PanelTitle);
foreach($Panels as $Panel) { foreach($Panels as $Panel) {
$result = mysqli_query($db->dbh, $Panel->getDelete()); $result = mysqli_query($db->dbh, $Panel->getDelete());
......
...@@ -66,7 +66,7 @@ echo '<!-- Navigation --> ...@@ -66,7 +66,7 @@ echo '<!-- Navigation -->
echo ' echo '
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li class="dropdown"> <li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"> Misc <a class="dropdown-toggle" data-toggle="dropdown" href="#"> Configuration
<span class="caret"></span></a> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="/'.Conf::$root_dir.'/services/jsonreaderConfig.php"> Jsonreader Config </a></li> <li><a href="/'.Conf::$root_dir.'/services/jsonreaderConfig.php"> Jsonreader Config </a></li>
......
...@@ -92,8 +92,54 @@ function printArray($array) { ...@@ -92,8 +92,54 @@ function printArray($array) {
} }
/** /**
* * JSON specific parse functions
*/ */
function parseBorgStatusJson($name, $val, $reader) {
$name = remove_quotes_and_new_line($name);
$minionid = "";
if($name == "borg_status") {
foreach($val as $minionid => $subval) {
foreach($subval as $jsonfilename => $subsubval) {
$first_td_displayed = "";
$second_td_displayed = "";
if(!is_array($subsubval)) {
$first_td_displayed = remove_quotes_and_new_line(stripcslashes($jsonfilename));
$second_td_displayed = remove_quotes_and_new_line(stripcslashes($subsubval));
if($second_td_displayed == $reader->BORG_BACKUP_NOT_FOUND) {
$second_td_displayed = '<span class="label" style="background-color: '.$reader->COLOR_BORG_BACKUP_NOT_FOUND.'" >'.$second_td_displayed.'</span>';
$first_td_displayed = '<span class="label" style="background-color: '.$reader->COLOR_BORG_BACKUP_NOT_FOUND.'" >'.$first_td_displayed.'</span>';
}
} else {
foreach($subsubval as $keytype => $details) {
if($keytype == "archives") {
/*
$details is an array of archives
The last item corresponds to the last backup
*/
if(is_array($details)) {
$start = end($details)["start"];
$end = end($details)["time"];
$start_timestamp = strtotime($start);
$end_timestamp = strtotime($end);
$duration = $end_timestamp - $start_timestamp;
$minutes = $duration / 60;
$hours = $minutes / 60;
$duration_str = "duration : ".$hours."h:".$minutes."m";
$first_td_displayed = '<span class="label" style="background-color: '.$reader->COLOR_DEFAULT_SUCCESS.'">'.$start.'</span>';
$second_td_displayed = '<span class="label" style="background-color: '.$reader->COLOR_DEFAULT_SUCCESS.'">'.$duration_str.'</span>';
} else {
$first_td_displayed = '<span class="label" style="background-color: '.$reader->COLOR_DEFAULT_ERROR.'">Unable to parse archive results...</span>';
}
}
}
}
printArray([$minionid,$first_td_displayed,$second_td_displayed]);
}
}
}
}
function parseZpoolJson($name, $val, $reader) { function parseZpoolJson($name, $val, $reader) {
$name = remove_quotes_and_new_line($name); $name = remove_quotes_and_new_line($name);
......
...@@ -44,6 +44,10 @@ class CReaderPanel extends SuperReader ...@@ -44,6 +44,10 @@ class CReaderPanel extends SuperReader
WHERE ID = '$this->ID';"; WHERE ID = '$this->ID';";
} }
public function getInsert() { public function getInsert() {
return "INSERT INTO CReaderPanel
SET CReaderID='$this->CReaderID', PanelTitle='$this->PanelTitle', PanelPosition='$this->PanelPosition';";
}
public function getInsertWithoutCReaderID() {
return "INSERT INTO CReaderPanel return "INSERT INTO CReaderPanel
SET PanelTitle='$this->PanelTitle', PanelPosition='$this->PanelPosition';"; SET PanelTitle='$this->PanelTitle', PanelPosition='$this->PanelPosition';";
} }
......
...@@ -3,7 +3,24 @@ ...@@ -3,7 +3,24 @@
class SuperReader { class SuperReader {
public function __construct($creaders) { public function __construct($creaders) {
$DEFAULT_SUCCESS = "Ok;ok;OK;True;true;TRUE";
$DEFAULT_ERROR = "Error;error;ERROR;Failed;failed;FAILED;False;false;FALSE";
$DEFAULT_WARNING = "Warning;warning;WARNING";
$COLOR_DEFAULT_SUCCESS = "#d32f2f";
$COLOR_DEFAULT_ERROR = "#5cb85c";
$COLOR_DEFAULT_WARNING = "#f57c00";
$this->DEFAULT_SUCCESS = $DEFAULT_SUCCESS;
$this->DEFAULT_ERROR = $DEFAULT_ERROR;
$this->DEFAULT_WARNING = $DEFAULT_WARNING;
$this->COLOR_DEFAULT_SUCCESS = $COLOR_DEFAULT_SUCCESS;
$this->COLOR_DEFAULT_ERROR = $COLOR_DEFAULT_ERROR;
$this->COLOR_DEFAULT_WARNING = $COLOR_DEFAULT_WARNING;
foreach($creaders as $cr) { foreach($creaders as $cr) {
$ckey = $cr->ckey; $ckey = $cr->ckey;
if($cr->FieldType == "textarea") { if($cr->FieldType == "textarea") {
......
...@@ -38,7 +38,7 @@ $creadersuniqpanels = CReaderPanelQuery::getOnlyPanelTitles($db); ...@@ -38,7 +38,7 @@ $creadersuniqpanels = CReaderPanelQuery::getOnlyPanelTitles($db);
$data = array(new Option("text", "text"), new Option("textarea", "textarea")); $data = array(new Option("text", "text"), new Option("textarea", "textarea"));
drawActionInputField("create"); drawActionInputField("create");
drawInputFormField("ckey", "Json Key name (item name)", "", true, false); drawInputFormField("ckey", "Json Key name (item name, without space)", "", true, false);
drawInputFormField("cvalue", "Possible value(s) to parse [1]", "", true, false); drawInputFormField("cvalue", "Possible value(s) to parse [1]", "", true, false);
drawSelectFormField("FieldType", "Field form type", $data, true); drawSelectFormField("FieldType", "Field form type", $data, true);
drawBasicColorPicker("DEFAULT_COLOR"); drawBasicColorPicker("DEFAULT_COLOR");
......
...@@ -153,7 +153,6 @@ $( document ).ready(function() { ...@@ -153,7 +153,6 @@ $( document ).ready(function() {
//echo 'console.log("else------'.$data.'");'; //echo 'console.log("else------'.$data.'");';
/* disk status */ /* disk status */
/* ret = {} */ /* ret = {} */
//parseDiskStatusJson($name, $ubname, $subval, $reader);
if($subname != "retcode"){ if($subname != "retcode"){
echo 'var tr = $("<tr>");'."\n"; echo 'var tr = $("<tr>");'."\n";
$name = remove_quotes_and_new_line($name); $name = remove_quotes_and_new_line($name);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment