use proxmox-mini-journalreader to display syslog
This commit is contained in:
parent
20197f7cf5
commit
81cc71c0d7
1
debian/control
vendored
1
debian/control
vendored
@ -27,6 +27,7 @@ Architecture: any
|
|||||||
Depends: ${shlibs:Depends}, ${misc:Depends},
|
Depends: ${shlibs:Depends}, ${misc:Depends},
|
||||||
libjs-extjs (>= 6.0.1),
|
libjs-extjs (>= 6.0.1),
|
||||||
fonts-font-awesome,
|
fonts-font-awesome,
|
||||||
|
proxmox-mini-journalreader,
|
||||||
proxmox-widget-toolkit,
|
proxmox-widget-toolkit,
|
||||||
libzstd1 (>= 1.3.8),
|
libzstd1 (>= 1.3.8),
|
||||||
Description: Proxmox Backup Server daemon with tools and GUI
|
Description: Proxmox Backup Server daemon with tools and GUI
|
||||||
|
@ -6,10 +6,12 @@ mod time;
|
|||||||
mod network;
|
mod network;
|
||||||
mod dns;
|
mod dns;
|
||||||
mod syslog;
|
mod syslog;
|
||||||
|
mod journal;
|
||||||
mod services;
|
mod services;
|
||||||
|
|
||||||
pub const SUBDIRS: SubdirMap = &[
|
pub const SUBDIRS: SubdirMap = &[
|
||||||
("dns", &dns::ROUTER),
|
("dns", &dns::ROUTER),
|
||||||
|
("journal", &journal::ROUTER),
|
||||||
("network", &network::ROUTER),
|
("network", &network::ROUTER),
|
||||||
("services", &services::ROUTER),
|
("services", &services::ROUTER),
|
||||||
("syslog", &syslog::ROUTER),
|
("syslog", &syslog::ROUTER),
|
||||||
|
122
src/api2/node/journal.rs
Normal file
122
src/api2/node/journal.rs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
use failure::*;
|
||||||
|
use serde_json::{json, Value};
|
||||||
|
use std::io::{BufRead,BufReader};
|
||||||
|
|
||||||
|
use proxmox::api::{api, ApiMethod, Router, RpcEnvironment};
|
||||||
|
|
||||||
|
use crate::api2::types::*;
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
protected: true,
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
node: {
|
||||||
|
schema: NODE_SCHEMA,
|
||||||
|
},
|
||||||
|
since: {
|
||||||
|
type: Integer,
|
||||||
|
optional: true,
|
||||||
|
description: "Display all log since this UNIX epoch. Conflicts with 'startcursor'.",
|
||||||
|
minimum: 0,
|
||||||
|
},
|
||||||
|
until: {
|
||||||
|
type: Integer,
|
||||||
|
optional: true,
|
||||||
|
description: "Display all log until this UNIX epoch. Conflicts with 'endcursor'.",
|
||||||
|
minimum: 0,
|
||||||
|
},
|
||||||
|
lastentries: {
|
||||||
|
type: Integer,
|
||||||
|
optional: true,
|
||||||
|
description: "Limit to the last X lines. Conflicts with a range.",
|
||||||
|
minimum: 0,
|
||||||
|
},
|
||||||
|
startcursor: {
|
||||||
|
type: String,
|
||||||
|
description: "Start after the given Cursor. Conflicts with 'since'.",
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
endcursor: {
|
||||||
|
type: String,
|
||||||
|
description: "End before the given Cursor. Conflicts with 'until'",
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: Array,
|
||||||
|
description: "Returns a list of journal entries.",
|
||||||
|
items: {
|
||||||
|
type: String,
|
||||||
|
description: "Line text.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)]
|
||||||
|
/// Read syslog entries.
|
||||||
|
fn get_journal(
|
||||||
|
param: Value,
|
||||||
|
_info: &ApiMethod,
|
||||||
|
_rpcenv: &mut dyn RpcEnvironment,
|
||||||
|
) -> Result<Value, Error> {
|
||||||
|
|
||||||
|
let mut args = vec![];
|
||||||
|
|
||||||
|
if let Some(lastentries) = param["lastentries"].as_u64() {
|
||||||
|
args.push(String::from("-n"));
|
||||||
|
args.push(format!("{}", lastentries));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(since) = param["since"].as_str() {
|
||||||
|
args.push(String::from("-b"));
|
||||||
|
args.push(since.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(until) = param["until"].as_str() {
|
||||||
|
args.push(String::from("-e"));
|
||||||
|
args.push(until.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(startcursor) = param["startcursor"].as_str() {
|
||||||
|
args.push(String::from("-f"));
|
||||||
|
args.push(startcursor.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(endcursor) = param["endcursor"].as_str() {
|
||||||
|
args.push(String::from("-t"));
|
||||||
|
args.push(endcursor.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut lines: Vec<String> = vec![];
|
||||||
|
|
||||||
|
let mut child = Command::new("/usr/bin/mini-journalreader")
|
||||||
|
.args(&args)
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.spawn()?;
|
||||||
|
|
||||||
|
if let Some(ref mut stdout) = child.stdout {
|
||||||
|
for line in BufReader::new(stdout).lines() {
|
||||||
|
match line {
|
||||||
|
Ok(line) => {
|
||||||
|
lines.push(line);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("reading journal failed: {}", err);
|
||||||
|
let _ = child.kill();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let status = child.wait().unwrap();
|
||||||
|
if !status.success() {
|
||||||
|
log::error!("journalctl failed with {}", status);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(json!(lines))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const ROUTER: Router = Router::new()
|
||||||
|
.get(&API_METHOD_GET_JOURNAL);
|
@ -49,11 +49,10 @@ Ext.define('PBS.ServerAdministration', {
|
|||||||
nodename: 'localhost'
|
nodename: 'localhost'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
xtype: 'proxmoxLogView',
|
xtype: 'proxmoxJournalView',
|
||||||
itemId: 'logs',
|
itemId: 'logs',
|
||||||
title: gettext('Syslog'),
|
title: gettext('Syslog'),
|
||||||
url: "/api2/extjs/nodes/localhost/syslog",
|
url: "/api2/extjs/nodes/localhost/journal",
|
||||||
log_select_timespan: 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
xtype: 'proxmoxNodeTasks',
|
xtype: 'proxmoxNodeTasks',
|
||||||
|
Loading…
Reference in New Issue
Block a user