Commit cfb7d36a authored by remy's avatar remy
Browse files

adding missing files / SuperReader Class; more dynamic reader

parent a6b9d93d
<?php
class Reader {
// default value
var $DEFAULT_SUCCESS = "1";
// _hosts_status
// nothing
// _services
// nothing
// _disks
var $DISKS_USAGE_DANGER = 90;
var $DISKS_USAGE_WARNING = 75;
// _disks_status
var $DISKS_STATUS_OK = "OK";
// _zpool
var $ZPOOL_STATUS_SUCCESS = "all pools are healthy";
var $ZPOOL_STATUS_INFO = "no pools available";
var $ZPOOL_STATUS_PRIMARY = "ZFS modules"; // contain this expression
var $ZPOOL_STATUS_WARNING = "ONLINE"; // contain this expression
// _dstates
// nothing
// _biosdate
// nothing
// _saltversion
var $SALTVERSION = ["2019", "3000", "3001", "3002", "3003"];
var $SALTVERSION_SUCCESS = ["3003", "2019"];
var $SALTVERSION_WARNING = ["2000", "3001"];
// _kernelversion
// nothing
// _osversion
var $OSVERSION_SUCCESS = ["Ubuntu-18.04", "Debian-10", "CentOS Linux-7", "Raspbian-9", "Ubuntu-20.04"];
// _websites_checksums & _websites_status
var $WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS = "OK";
var $WEBSITE_CHECKSUMS_AND_STATUS_WARNING = ["Found", "Permanently"];
// _websites_certs
var $WEBSITES_CERTS_SUCCESS = 5;
var $WEBSITES_CERTS_WARNING = 1;
var $WEBSITES_CERTS_STATUS_OK = "Ok";
//=============================================
// COLOR
//=============================================
// default value
var $COLOR_DEFAULT_SUCCESS = "#FFFFFF";
// _hosts_status
// nothing
// _services
// nothing
// _disks
var $COLOR_DISKS_USAGE_DANGER = "#FFFFFF";
var $COLOR_DISKS_USAGE_WARNING = "#FFFFFF";
// _disks_status
var $COLOR_DISKS_STATUS_OK = "#FFFFFF";
// _zpool
var $COLOR_ZPOOL_STATUS_SUCCESS = "#FFFFFF";
var $COLOR_ZPOOL_STATUS_INFO = "#FFFFFF";
var $COLOR_ZPOOL_STATUS_PRIMARY = "#FFFFFF";
var $COLOR_ZPOOL_STATUS_WARNING = "#FFFFFF";
// _dstates
// nothing
// _biosdate
// nothing
// _saltversion
var $COLOR_SALTVERSION = "#FFFFFF";
var $COLOR_SALTVERSION_SUCCESS = "#FFFFFF";
var $COLOR_SALTVERSION_WARNING = "#FFFFFF";
// _kernelversion
// nothing
// _osversion
var $COLOR_OSVERSION_SUCCESS = "#FFFFFF";
// _websites_checksums & _websites_status
var $COLOR_WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS = "#FFFFFF";
var $COLOR_WEBSITE_CHECKSUMS_AND_STATUS_WARNING = "#FFFFFF";
// _websites_certs
var $COLOR_WEBSITES_CERTS_SUCCESS = "#FFFFFF";
var $COLOR_WEBSITES_CERTS_WARNING = "#FFFFFF";
var $COLOR_WEBSITES_CERTS_STATUS_OK = "#FFFFFF";
//=========================================================//
public function __construct($creader, $creadercolor) {
$this->DEFAULT_SUCCESS = $creader["DEFAULT_SUCCESS"][0];
// _hosts_status
// nothing
// _services
// nothing
// _disks
$this->DISKS_USAGE_DANGER = intval($creader["DISKS_USAGE_DANGER"][0]);
$this->DISKS_USAGE_WARNING = intval($creader["DISKS_USAGE_WARNING"][0]);
// _disks_status
$this->DISKS_STATUS_OK = $creader["DISKS_STATUS_OK"][0];
// _zpool
$this->ZPOOL_STATUS_SUCCESS = $creader["ZPOOL_STATUS_SUCCESS"][0];
$this->ZPOOL_STATUS_INFO = $creader["ZPOOL_STATUS_INFO"][0];
$this->ZPOOL_STATUS_PRIMARY = $creader["ZPOOL_STATUS_PRIMARY"][0];
$this->ZPOOL_STATUS_WARNING = $creader["ZPOOL_STATUS_WARNING"][0];
// _dstates
// nothing
// _biosdate
// nothing
// _saltversion
$this->SALTVERSION = $creader["SALTVERSION"];
$this->SALTVERSION_SUCCESS = $creader["SALTVERSION_SUCCESS"];
$this->SALTVERSION_WARNING = $creader["SALTVERSION_WARNING"];
// _kernelversion
// nothing
// _osversion
$this->OSVERSION_SUCCESS = $creader["OSVERSION_SUCCESS"];
// _websites_checksums & _websites_status
$this->WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS = $creader["WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS"][0];
$this->WEBSITE_CHECKSUMS_AND_STATUS_WARNING = $creader["WEBSITE_CHECKSUMS_AND_STATUS_WARNING"];
// _websites_certs
$this->WEBSITES_CERTS_SUCCESS = intval($creader["WEBSITES_CERTS_SUCCESS"][0]);
$this->WEBSITES_CERTS_WARNING = intval($creader["WEBSITES_CERTS_WARNING"][0]);
$this->WEBSITES_CERTS_STATUS_OK = $creader["WEBSITES_CERTS_STATUS_OK"][0];
// =====================================
// COLOR
// =====================================
$this->COLOR_DEFAULT_SUCCESS = $creadercolor["DEFAULT_SUCCESS"];
// _hosts_status
// nothing
// _services
// nothing
// _disks
$this->COLOR_DISKS_USAGE_DANGER = $creadercolor["DISKS_USAGE_DANGER"];
$this->COLOR_DISKS_USAGE_WARNING = $creadercolor["DISKS_USAGE_WARNING"];
// _disks_status
$this->COLOR_DISKS_STATUS_OK = $creadercolor["DISKS_STATUS_OK"];
// _zpool
$this->COLOR_ZPOOL_STATUS_SUCCESS = $creadercolor["ZPOOL_STATUS_SUCCESS"];
$this->COLOR_ZPOOL_STATUS_INFO = $creadercolor["ZPOOL_STATUS_INFO"];
$this->COLOR_ZPOOL_STATUS_PRIMARY = $creadercolor["ZPOOL_STATUS_PRIMARY"];
$this->COLOR_ZPOOL_STATUS_WARNING = $creadercolor["ZPOOL_STATUS_WARNING"];
// _dstates
// nothing
// _biosdate
// nothing
// _saltversion
$this->COLOR_SALTVERSION = $creadercolor["SALTVERSION"];
$this->COLOR_SALTVERSION_SUCCESS = $creadercolor["SALTVERSION_SUCCESS"];
$this->COLOR_SALTVERSION_WARNING = $creadercolor["SALTVERSION_WARNING"];
// _kernelversion
// nothing
// _osversion
$this->COLOR_OSVERSION_SUCCESS = $creadercolor["OSVERSION_SUCCESS"];
// _websites_checksums & _websites_status
$this->COLOR_WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS = $creadercolor["WEBSITE_CHECKSUMS_AND_STATUS_SUCCESS"];
$this->COLOR_WEBSITE_CHECKSUMS_AND_STATUS_WARNING = $creadercolor["WEBSITE_CHECKSUMS_AND_STATUS_WARNING"];
// _websites_certs
$this->COLOR_WEBSITES_CERTS_SUCCESS = $creadercolor["WEBSITES_CERTS_SUCCESS"];
$this->COLOR_WEBSITES_CERTS_WARNING = $creadercolor["WEBSITES_CERTS_WARNING"];
$this->COLOR_WEBSITES_CERTS_STATUS_OK = $creadercolor["WEBSITES_CERTS_STATUS_OK"];
}
}
?>
\ No newline at end of file
......@@ -232,8 +232,8 @@ function parseSaltversionJson($name, $val, $reader) {
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION_SUCCESS.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
} else if(in_array ($val, $reader->SALTVERSION_WARNING)) {
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION_WARNING.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
} else if(in_array ($val, $reader->SALTVERSION)) {
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
} else if(in_array ($val, $reader->SALTVERSION_INFO)) {
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION_INFO.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
} else {
// looking for version 3003.X if 3003 otherwise false
foreach ($reader->SALTVERSION as $valueSV) {
......@@ -249,7 +249,7 @@ function parseSaltversionJson($name, $val, $reader) {
}
}
if($found) {
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
$val = '<span class="label" style="background-color: '.$reader->COLOR_SALTVERSION_INFO.'"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
} else {
$val = '<span class="label" style="background-color: #e74c3c"><i class="fas fa-code-branch"></i>&nbsp;'.$val.'</span>';
}
......@@ -258,12 +258,13 @@ function parseSaltversionJson($name, $val, $reader) {
}
function parseServiceJsonArray($name, $service_array, $reader) {
echo 'var tr = $("<tr>");'."\n";
$tdhtml = [];
// name == salt hostname
// name == salt minion id
$name = remove_quotes_and_new_line($name);
echo "$('<td>').html('".$name."').appendTo(tr);"."\n";
$pgrep = False;
$html_str_result = "";
$html_str_changes = "";
$html_str_service_name = "";
foreach ($service_array as $daemon_type => $daemonval) {
if(is_array($daemonval) && $daemon_type == "name") {
$daemonval = $daemonval[0];
......@@ -276,24 +277,22 @@ function parseServiceJsonArray($name, $service_array, $reader) {
}
if(is_numeric($daemonval)) {
//$daemonval = '<span class="label label-success">'.$daemonval.'</span>';
$html_str_result = "<td><span class='label' style='background-color: ".$reader->COLOR_DEFAULT_SUCCESS."'>".$daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_TRUE.'">'.$daemonval.'</span></td>';
} else {
//$daemonval = '<span class="label label-danger">'.$daemonval.'</span>';
$html_str_result = "<td><span class='label' style='background-color: #e74c3c'>".$daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_FALSE.'">'.$daemonval.'</span></td>';
}
//$html_str_result = "<td>".$daemonval."</td>";
}
elseif($daemon_type == "name" && $daemonval != "customservice.status") {
$daemonval = remove_quotes_and_new_line($daemonval);
if(is_numeric($daemonval)) {
$html_str_result = "<td><span class='label' style='background-color: ".$reader->COLOR_DEFAULT_SUCCESS."'>".$daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_TRUE.'">'.$daemonval.'</span></td>';
} else {
$html_str_result = "<td><span class='label' style='background-color: #e74c3c'>".$daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_FALSE.'">'.$daemonval.'</span></td>';
}
//$html_str_name = "<td>".$daemonval."</td>";
//using pgrep in customservice when the service name is not available.
//...sge for example
/*
Using pgrep in customservice when the service name is not available.
...sge for example
*/
$pgrep = True;
}
elseif($daemon_type == "changes") {
......@@ -319,29 +318,27 @@ function parseServiceJsonArray($name, $service_array, $reader) {
$ret_daemonval[1] = remove_quotes_and_new_line($ret_daemonval[1]);
if($ret_daemonval[1] == "false" || $ret_daemonval[1] == "")
{ $ret_daemonval[1] = 0; }
$html_str_name = "<td>".$ret_daemonval[0]."</td>";
$html_str_service_name = '<td>'.$ret_daemonval[0].'</td>';
if($ret_daemonval[1] == "1") {
$html_str_changes = "<td><span class='label' style='background-color: ".$reader->COLOR_DEFAULT_SUCCESS."'>".$ret_daemonval[1]."</span></td>";
$html_str_changes = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_TRUE.'">'.$ret_daemonval[1].'</span></td>';
} else {
$html_str_changes = "<td><span class='label' style='background-color: #e74c3c'>".$ret_daemonval[1]."</span></td>";
$html_str_changes = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_FALSE.'">'.$ret_daemonval[1].'</span></td>';
}
//$html_str_changes = "<td>".$ret_daemonval[1]."</td>";
}
elseif(array_key_exists("customservice.status", $daemonval)) {
$ret_daemonval = $daemonval["customservice.status"];
$ret_daemonval[0] = remove_quotes_and_new_line($ret_daemonval[0]);
$ret_daemonval[1] = remove_quotes_and_new_line($ret_daemonval[1]);
$html_str_name = "<td>".$ret_daemonval[0]."</td>";
$html_str_service_name = "<td>".$ret_daemonval[0]."</td>";
if($ret_daemonval[1] != "false" && $ret_daemonval[1] != 0) {
$html_str_changes = "<td><span class='label' style='background-color: ".$reader->COLOR_DEFAULT_SUCCESS."'>".$ret_daemonval[1]."</span></td>";
$html_str_changes = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_TRUE.'">'.$ret_daemonval[1].'</span></td>';
} else {
if(empty($ret_daemonval[1])) {
$ret_daemonval[1] = 0;
}
$html_str_changes = "<td><span class='label' style='background-color: #e74c3c'>".$ret_daemonval[1]."</span></td>";
$html_str_changes = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_FALSE.'">'.$ret_daemonval[1].'</span></td>';
}
}
elseif(array_key_exists("stdout", $daemonval)) {
......@@ -349,27 +346,20 @@ function parseServiceJsonArray($name, $service_array, $reader) {
$ret_daemonval[0] = remove_quotes_and_new_line($ret_daemonval);
// $pgrep == True
if(is_numeric($ret_daemonval)) {
$html_str_result = "<td><span class='label' style='background-color: ".$reader->COLOR_DEFAULT_SUCCESS."'>".$ret_daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_TRUE.'">'.$ret_daemonval.'</span></td>';
} else {
$html_str_result = "<td><span class='label' style='background-color: #e74c3c'>".$ret_daemonval."</span></td>";
$html_str_result = '<td><span class="label" style="background-color: '.$reader->COLOR_SERVICE_STATE_FALSE.'">'.$ret_daemonval.'</span></td>';
}
//$html_str_result = "<td>".$ret_daemonval."</td>";
}
}
$tdhtml['result'] = $html_str_result;
$tdhtml['name'] = $html_str_name;
$tdhtml['service_name'] = $html_str_service_name;
$tdhtml['changes'] = $html_str_changes;
}
echo 'tr.append("'.$tdhtml['result'].'");'."\n";
echo 'tr.append("'.$tdhtml['name'].'");'."\n";
echo 'tr.append("'.$tdhtml['changes'].'");'."\n";
echo 'tbody.append(tr);'."\n";
printArray([$name, $tdhtml['result'], $tdhtml['service_name'], $tdhtml['changes']]);
//reinitialize
$pgrep = False;
//$html_str_name = "";
//$html_str_result = "";
//$html_str_changes = "";
}
function getDateTimeTitle($filename) {
......
<?php
require_once(__DIR__.'/../config/Plugin.php');
require_once(__DIR__.'/'.JSR_PATH.'/model/Model.php');
//require_once(__DIR__.'/'.JSR_PATH.'/model/Model.php');
require_once(__DIR__.'/SuperReader.php');
/**
* CReader model
*/
class CReader extends Model
class CReader extends SuperReader
{
var $ID = 0;
var $ckey = "";
......
<?php
require_once(__DIR__.'/../config/Plugin.php');
require_once(__DIR__.'/'.JSR_PATH.'/model/Model.php');
//require_once(__DIR__.'/'.JSR_PATH.'/model/Model.php');
require_once(__DIR__.'/SuperReader.php');
/**
* CReaderPanel model
*/
class CReaderPanel extends Model
class CReaderPanel extends SuperReader
{
var $ID = 0;
var $CReaderID = "";
......
<?php
class SuperReader {
public function __construct($creaders) {
foreach($creaders as $cr) {
$ckey = $cr->ckey;
if($cr->FieldType == "textarea") {
$arrvals = explode(";", $cr->cvalue);
} else {
$arrvals = $cr->cvalue;
}
is_numeric($arrvals) ? $this->$ckey = intval($arrvals) : $this->$ckey = $arrvals;
$colorkey = "COLOR_".$ckey;
$this->$colorkey = $cr->color;
}
}
}
?>
\ No newline at end of file
......@@ -11,16 +11,16 @@ if(!JSONREADER2_STANDALONE) {
}
}
include(JSR_PATH."/include/buildHeader.php");
include("../config/Reader.php");
require_once JSR_PATH."/dao/DBquery.php";
require_once "../dao/CReaderQuery.php";
require_once "../include/toolReader.php";
require_once "../dao/ReaderTableDBQuery.php";
require_once "../model/SuperReader.php";
$db = new DBquery();
$creaders = CReaderQuery::getAllCReader($db);
$creadersColor = CReaderQuery::getAllCReaderColor($db);
$reader = new Reader($creaders, $creadersColor);
$creadersO = CReaderQuery::getAllCReaderObjects($db);
$reader = new SuperReader($creadersO);
$readersTable = ReaderTableDBQuery::getAllReaderTable($db);
?>
......@@ -113,6 +113,10 @@ $( document ).ready(function() {
// tbody
echo "var tbody = $('tbody');"."\n";
foreach ($json as $name => $val) {
/*
Corresponding function name is a CamelCase string of
the json export filename with "parse" prefix and "Json" suffix.
*/
$camelfunctionname = snake_case_to_CamelCase($data);
$camelfunctionname = snake_case_to_CamelCase($readerTable->name);
$camelfunctionname = "parse".$camelfunctionname."Json";
......
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