The web based syslog
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
8.8KB

  1. <?php
  2. spl_autoload_register(function($class) {
  3. include __DIR__ . '/inc/' . strtolower($class) . '_class.php';
  4. });
  5. require 'tpl/head.inc.php';
  6. session_start();
  7. if(isset($_SESSION[LggrState::SESSIONNAME])) {
  8. $state = $_SESSION[LggrState::SESSIONNAME];
  9. } else {
  10. $state = new LggrState();
  11. } // if
  12. $l = null;
  13. try {
  14. $config = new Config();
  15. $l = new Lggr($state, $config);
  16. $aLevels = $l->getLevels();
  17. $aServers = $l->getServers();
  18. } catch(Exception $e) {
  19. echo '<div class="container"><div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div></div>';
  20. require 'tpl/foot.inc.php';
  21. exit;
  22. }
  23. $aRanges = array(
  24. '1' => 'This hour',
  25. '24' => 'Today',
  26. '168' => 'Week'
  27. );
  28. $page = $state->getPage();
  29. try {
  30. if($state->isSearch()) {
  31. $aEvents = $l->getText($state->getSearch(), $state->getSearchProg(), $page*LggrState::PAGELEN, LggrState::PAGELEN);
  32. $searchvalue = htmlentities($state->getSearch());
  33. $searchvalueprog = htmlentities($state->getSearchProg());
  34. $isSearch=true;
  35. $sFilter = 'Text search for';
  36. if('' != $state->getSearch()) $sFilter .= ' message <strong>' . $searchvalue . '</strong>';
  37. if('' != $state->getSearchProg()) $sFilter .= ' program <strong>' . $searchvalueprog . '</strong>';
  38. } elseif($state->isHost() || $state->isLevel()) {
  39. $host = $state->getHost();
  40. $level = $state->getLevel();
  41. $aEvents = $l->getFiltered($host, $level, $page*LggrState::PAGELEN, LggrState::PAGELEN);
  42. $searchvalue='';
  43. $searchvalueprog='';
  44. $isSearch=false;
  45. $sFilter='';
  46. if($state->isHost())
  47. $sFilter .= 'Filter by server <strong>' . htmlentities($state->getHost()) . '</strong>';
  48. if($state->isLevel())
  49. $sFilter .= 'Filter by level <strong>' . htmlentities($state->getLevel()) . '</strong>';
  50. } elseif($state->isFromTo()) {
  51. $aEvents = $l->getFromTo($page*LggrState::PAGELEN, LggrState::PAGELEN);
  52. $sFilter = 'Filter by time range between <strong>' . htmlentities($state->getFrom()) . '</strong> and <strong>' . htmlentities($state->getTo()) . '</strong>';
  53. $searchvalue='';
  54. $searchvalueprog='';
  55. $isSearch=false;
  56. } else {
  57. $sFilter = null;
  58. $aEvents = $l->getLatest($page*LggrState::PAGELEN, LggrState::PAGELEN);
  59. $searchvalue='';
  60. $searchvalueprog='';
  61. $isSearch=false;
  62. } // if search
  63. } catch(Exception $e) {
  64. echo '<div class="container"><div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div></div>';
  65. require 'tpl/foot.inc.php';
  66. exit;
  67. }
  68. require 'tpl/nav.inc.php';
  69. ?>
  70. <div class="container">
  71. <div class="row">
  72. <div class="col-md-4">
  73. <h2><span class="glyphicon glyphicon-tasks" aria-hidden="true"></span> Levels</h2>
  74. <div class="progress">
  75. <?php
  76. $aLevelCount = array();
  77. foreach($aLevels as $level) {
  78. $aLevelCount[$level->level] = $level->c;
  79. switch($level->level) {
  80. case 'emerg':
  81. case 'crit':
  82. case 'err':
  83. $label='progress-bar-danger';
  84. break;
  85. case 'warning':
  86. $label='progress-bar-warning';
  87. break;
  88. case 'notice':
  89. $label='progress-bar-primary';
  90. break;
  91. case 'info':
  92. $label='progress-bar-success';
  93. break;
  94. default: $label='';
  95. } // switch
  96. echo <<<EOL
  97. <div class="progress-bar $label" style="width: {$level->f}%" title="{$level->level} {$level->f}%">
  98. <span class="sr-only">{$level->f}%</span>
  99. </div>
  100. EOL;
  101. } // foreach
  102. ?>
  103. </div>
  104. <p>Distribution of selected event levels.</p>
  105. <p class="lggr-level-buttons">
  106. <?php
  107. if(isset($aLevelCount['emerg'])) {
  108. echo '<button class="btn btn-sm btn-danger" type="button">Emergency <span class="badge">' . $aLevelCount['emerg'] . '</span></button> ';
  109. }
  110. if(isset($aLevelCount['crit'])) {
  111. echo '<button class="btn btn-sm btn-danger" type="button">Critical <span class="badge">' . $aLevelCount['crit'] . '</span></button> ';
  112. }
  113. if(isset($aLevelCount['err'])) {
  114. echo '<button class="btn btn-sm btn-danger" type="button">Error <span class="badge">' . $aLevelCount['err'] . '</span></button> ';
  115. }
  116. if(isset($aLevelCount['err'])) {
  117. echo '<button class="btn btn-sm btn-warning" type="button">Warning <span class="badge">' . $aLevelCount['warning'] . '</span></button> ';
  118. }
  119. if(isset($aLevelCount['notice'])) {
  120. echo '<button class="btn btn-sm btn-primary" type="button">Notice <span class="badge">' . $aLevelCount['notice'] . '</span></button> ';
  121. }
  122. ?>
  123. </p>
  124. </div>
  125. <div class="col-md-4">
  126. <h2><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> Servers</h2>
  127. <?php
  128. foreach($aServers as $server) {
  129. if($server->f < 5) continue;
  130. echo <<<EOL
  131. <div class="progress">
  132. <div class="progress-bar" role="progressbar" aria-valuenow="{$server->f}" aria-valuemin="0" aria-valuemax="100" style="width: {$server->f}%; min-width: 3em" title="{$server->host} {$server->f}%">
  133. {$server->host} {$server->f}%
  134. </div>
  135. </div>
  136. EOL;
  137. } // foreach
  138. ?>
  139. <p>Most reporting servers (5% or more).</p>
  140. </div>
  141. <div class="col-md-4">
  142. <h2><span class="glyphicon glyphicon-filter" aria-hidden="true"></span> Filter</h2>
  143. <div class="dropdown">
  144. <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
  145. Server
  146. <span class="caret"></span>
  147. </button>
  148. <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
  149. <?php
  150. foreach($aServers as $server) {
  151. echo '<li role="presentation"><a role="menuitem" tabindex="-1" href="./do.php?a=host&host=' . urlencode($server->host) . '">' . $server->host . '</a></li>';
  152. } // foreach
  153. ?>
  154. </ul>
  155. </div><!-- dropdown -->
  156. <p><div class="btn-group btn-group-xs" role="group" aria-label="level">
  157. <?php
  158. foreach($aLevels as $level) {
  159. if($state->isLevel() && ($level->level == $state->getLevel())) {
  160. echo '<button type="button" class="btn btn-primary newlog-level">' . $level->level . '</button>';
  161. } else {
  162. echo '<button type="button" class="btn btn-default newlog-level">' . $level->level . '</button>';
  163. }
  164. } // foreach
  165. ?>
  166. </div></p>
  167. <p><div class="btn-group" role="group" aria-label="range">
  168. <?php
  169. foreach($aRanges as $rangeValue => $rangeText) {
  170. if($state->getRange() == $rangeValue) {
  171. echo '<button type="button" class="btn btn-primary newlog-range" data-range="' . $rangeValue . '">' . $rangeText . '</button>';
  172. } else {
  173. echo '<button type="button" class="btn btn-default newlog-range" data-range="' . $rangeValue . '">' . $rangeText . '</button>';
  174. }
  175. } // foreach
  176. if($state->isFromTo()) {
  177. echo '<button type="button" class="btn btn-primary newlog-range" id="btnspecialrange">Special</button>';
  178. } else {
  179. echo '<button type="button" class="btn btn-default newlog-range" id="btnspecialrange">Special</button>';
  180. } // if
  181. ?>
  182. </div></p>
  183. <form action="do.php" method="post" id="tsfromto">
  184. <input type="hidden" name="a" value="fromto">
  185. <input type="text" name="tsfrom" id="tsfrom" class="tspick" placeholder="from">
  186. <input type="text" name="tsto" id="tsto" class="tspick" placeholder="to">
  187. <button type="submit" class="btn btn-default">filter</button>
  188. </form>
  189. <p><a type="button" role="button" href="./do.php?a=reset" class="btn btn-default">
  190. <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Reset
  191. </a></p>
  192. </div>
  193. </div>
  194. </div> <!-- /container -->
  195. <div class="container">
  196. <?php
  197. if(null != $sFilter) {
  198. echo '<div class="alert alert-info" role="alert">' . $sFilter . '</div>';
  199. } // if
  200. if(0 == count($aEvents)) {
  201. echo '<div class="alert alert-danger" role="alert">empty result</div>';
  202. } // if
  203. ?>
  204. </div>
  205. <div class="container datablock">
  206. <?php
  207. include 'tpl/paginate.inc.php';
  208. $i=0;
  209. foreach($aEvents as $event) {
  210. $i++;
  211. if(0 == $i % 2) {
  212. $rowclass='even';
  213. } else {
  214. $rowclass='odd';
  215. } // if
  216. switch($event->level) {
  217. case 'emerg': $label = '<span class="label label-danger">Emergency</span>'; break;
  218. case 'crit': $label = '<span class="label label-danger">Critical</span>'; break;
  219. case 'err': $label = '<span class="label label-danger">Error</span>'; break;
  220. case 'warning': $label = '<span class="label label-warning">Warning</span>'; break;
  221. case 'notice': $label='<span class="label label-primary">Notice</span>'; break;
  222. case 'info': $label = '<span class="label label-success">Info</span>'; break;
  223. default: $label = '<span class="label label-default">' . $event->level . '</span>';
  224. } // switch
  225. $host = htmlentities($event->host);
  226. $program = htmlentities($event->program);
  227. $msg = htmlentities($event->message);
  228. echo <<<EOL
  229. <div class="row datarow $rowclass" data-id="{$event->id}">
  230. <div class="col-md-2 col-xs-6 newlog-date">{$event->date}</div>
  231. <div class="col-md-1 col-xs-2">{$event->facility}</div>
  232. <div class="col-md-1 col-xs-2">$label</div>
  233. <div class="col-md-1 col-xs-2">$host</div>
  234. <div class="col-md-2 col-xs-12">$program</div>
  235. <div class="col-md-5 col-xs-12 newlog-msg" title="$msg"><tt>{$msg}</tt></div>
  236. </div><!-- row -->
  237. EOL;
  238. } // foreach
  239. ?>
  240. <div id="dialog" title="Details">I'm a dialog</div>
  241. <?php
  242. include 'tpl/paginate.inc.php';
  243. ?>
  244. </div>
  245. <?php
  246. $aPerf = $l->getPerf();
  247. require 'tpl/foot.inc.php'
  248. ?>
Social stuff:
Mastodon