Add server log monitoring tols

This commit is contained in:
lxsang
2021-09-18 13:13:16 +02:00
parent f453769944
commit ecc54322a3
13 changed files with 615 additions and 0 deletions

View File

@ -0,0 +1,9 @@
# Server log monitor
This application allows to monitor Server Syslog
using Antunnel protocol. Features:
* Realtime log monitoring
* Filter logs by pattern (regular expression), severity
* Recording last n log messages
## Change logs
* v0.1.0-b first beta version

View File

@ -0,0 +1,55 @@
afx-app-window[data-id="ServerLogClient"] p {
margin: 0;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
font-family: "Courier New";
border-bottom: 1px solid gray;
}
afx-app-window[data-id="ServerLogClient"] p:hover {
background-color: gray;
}
afx-app-window[data-id="ServerLogClient"] p.debug{
color:green;
}
/*
afx-app-window[data-id="ServerLogClient"] p.notice, afx-app-window[data-id="ServerLogClient"] p.info{
color:green;
}*/
afx-app-window[data-id="ServerLogClient"] p.warning {
color: orange;
}
afx-app-window[data-id="ServerLogClient"] p.err {
color: orangered;
}
afx-app-window[data-id="ServerLogClient"] p.crit, afx-app-window[data-id="ServerLogClient"] p.alert {
color: orangered;
font-weight: bold;
}
afx-app-window[data-id="ServerLogClient"] p.emerg {
color: red;
font-weight: bold;
}
afx-app-window[data-id="ServerLogClient"] input {
height: 25px;
}
afx-app-window[data-id="ServerLogClient"] afx-hbox[data-id="top-header"] {
border-bottom: 1px solid gray;
}
afx-app-window[data-id="ServerLogClient"] afx-hbox[data-id="top-header"] afx-label.field-label{
text-align: right;
padding-top: 5px;
padding-right: 3px;
}
afx-app-window[data-id="ServerLogClient"] afx-hbox[data-id="top-header"] afx-label.field-label i.label-text{
font-weight: bold;
}

View File

@ -0,0 +1 @@
var OS;!function(t){let e;!function(t){class e extends t.BaseApplication{constructor(t){super("ServerLogClient",t)}check(t){return!(!this.filter.record||!this.filter[t.severity_label]||this.filter.pattern&&!t.message.match(this.filter.pattern))}log(t){if(this.check(t)){if(this.logs.length>=this.filter.max_log){let t=this.logs.shift();$(t.el).remove()}t.el=$("<p />").addClass(t.severity_label),t.el.text(t.message),$(this.log_container).append(t.el),this.log_container.scrollTop=this.log_container.scrollHeight,this.logs.push(t)}}openSession(){this.sub=new Antunnel.Subscriber(this.setting.topic),this.sub.onopen=()=>{console.log("Subscribed")},this.sub.onerror=t=>{this.error(__("Unable to connect to: syslog"),t),this.sub=void 0},this.sub.onmessage=t=>{if(t.data){let e=JSON.parse(new TextDecoder("utf-8").decode(t.data));e.priority&&(e.priority=parseInt(e.priority)),e.severity&&(e.severity=parseInt(e.severity)),e.facility&&(e.facility=parseInt(e.facility)),this.log(e)}},this.sub.onclose=()=>{this.sub=void 0,this.notify(__("Connection closed")),this.quit(!0)},this.tunnel.subscribe(this.sub)}cleanup(){this.sub&&this.sub.close()}checklib(){Antunnel.tunnel?(this.tunnel=Antunnel.tunnel,this.openSession()):this._gui.pushService("Antunnel/AntunnelService").then(t=>{let e=this.systemsetting.system.tunnel_uri;e||(this.error(__("Unable to connect to the tunnel")),this.quit(!0)),Antunnel.init(e).then(t=>{this.notify(__("Tunnel now connected to the server at: {0}",e)),this.tunnel=Antunnel.tunnel,this.openSession()}).catch(t=>{Antunnel.tunnel&&(Antunnel.tunnel.close(),this.error(__("Unable to connect to the tunnel: {0}",t.toString()),t),this.quit(!0))})}).catch(t=>{this.error(__("Unable to run Antunnel service: {0}",t.toString()),t),this.quit(!0)})}main(){if(!Antunnel)return this.error(__("Antunnel library is not available")),void this.quit(!0);this.log_container=this.find("log-container"),this.logs=[],$(this.log_container).css("overflow-y","auto"),this.find("menu-level").items=[{text:__("Default level"),nodes:[{text:__("Debug"),switch:!0,checked:!0,severity:"debug"},{text:__("Notice"),switch:!0,checked:!0,severity:"notice"},{text:__("Info"),switch:!0,checked:!0,severity:"info"},{text:__("Warning"),switch:!0,checked:!0,severity:"warning"},{text:__("Error"),switch:!0,checked:!0,severity:"err"},{text:__("Critical"),switch:!0,checked:!0,severity:"crit"},{text:__("Alert"),switch:!0,checked:!0,severity:"alert"},{text:__("Emergency"),switch:!0,checked:!0,severity:"emerg"}],onchildselect:t=>{let e=t.data.item.data;this.filter[e.severity]=e.checked}}],this.filter={max_log:500,err:!0,emerg:!0,debug:!0,info:!0,notice:!0,warning:!0,crit:!0,alert:!0,pattern:void 0,record:!0};let t=this.find("txt-n-log");t.value=this.filter.max_log.toString(),$(t).on("keyup",e=>{if("Enter"===e.key){let e=parseInt(t.value);if(!isNaN(e))for(this.filter.max_log=e;this.logs.length>e;)this.logs.shift().el.remove();t.value=this.filter.max_log.toString()}}),this.find("btn-clear").onbtclick=()=>{this.logs=[],$(this.log_container).empty()};let e=this.find("txt-reg");$(e).on("keyup",t=>{if("Enter"===t.key){if(""===e.value.trim())return this.filter.pattern=void 0;try{this.filter.pattern=new RegExp(e.value,"g")}catch(t){this.error(__("Invalid regular expression: {0}",t.toString()),t),this.filter.pattern=void 0,e.value=""}}}),this.find("sw-record").onswchange=t=>{this.filter.record=t.data},this.setting.topic?this.checklib():this._gui.openDialog("PromptDialog",{title:__("Enter topic name"),label:__("Please enter Antunnel topic name")}).then(t=>{this.setting.topic=t,this.checklib()})}}t.ServerLogClient=e,e.dependencies=["pkg://Antunnel/main.js"],e.singleton=!0}(e=t.application||(t.application={}))}(OS||(OS={}));

View File

@ -0,0 +1,18 @@
{
"pkgname": "ServerLogClient",
"app":"ServerLogClient",
"name":"Server log monitor",
"description":"Client for server Syslog monitoring",
"info":{
"author": "",
"email": ""
},
"version":"0.0.1-b",
"category":"System",
"iconclass":"bi bi-receipt-cutoff",
"mimes":["none"],
"dependencies": [
"Antunnel@0.1.8-a"
],
"locale": {}
}

View File

@ -0,0 +1,17 @@
<afx-app-window apptitle="__(Server system log)" width="600" height="400" data-id="ServerLogClient">
<afx-vbox >
<afx-hbox data-height="25" data-id="top-header">
<afx-button data-height="25" text="__(Clear)" data-id="btn-clear" data-width="60"></afx-button>
<afx-menu data-id="menu-level" data-width="100"></afx-menu>
<afx-label class="field-label" text="__(Filter)" data-width="50"></afx-label>
<input type="text" data-id="txt-reg"></input>
<afx-label class="field-label" text="__(Keep upto)" data-width="70"></afx-label>
<input type="text" data-width="50" data-id="txt-n-log"></input>
<afx-label class="field-label" text="__(Record)" data-width="50"></afx-label>
<afx-switch swon="true" data-id="sw-record" data-width="30"></afx-switch>
</afx-hbox>
<div data-id="log-container">
</div>
</afx-vbox>
</afx-app-window>