summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index f96ebdc..710fbda 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,7 +52,7 @@ fn overview(r: &mut Request) -> IronResult<Response> {
.find("name")
.unwrap_or("World").to_owned();
- let units = unit::get_units().unwrap();
+ let units = unit::get_units("*").unwrap();
let sections = ["service", "timer", "socket", "target", "slice", "mount",
"path"];
@@ -81,7 +81,6 @@ fn journal(r: &mut Request) -> IronResult<Response> {
.get::<Router>()
.unwrap()
.find("unit"), status::BadRequest);
- info!("got here");
let re = Regex::new(r"[-_\w\d]*").unwrap();
if !re.is_match(unit) {
return Ok(Response::with(
@@ -89,17 +88,34 @@ fn journal(r: &mut Request) -> IronResult<Response> {
format!("Unit ({}) does not match {}",
unit, re))));
}
- info!("got here");
Ok(Response::with((status::Ok,
itry!(journal::get_log(unit, 100)))))
}
+fn unit_status(r: &mut Request) -> IronResult<Response> {
+ let unit_name = iexpect!(r.extensions
+ .get::<Router>()
+ .unwrap()
+ .find("unit"), status::BadRequest);
+ let re = Regex::new(r"[-_\w\d]*").unwrap();
+ if !re.is_match(unit_name) {
+ return Ok(Response::with(
+ (status::BadRequest,
+ format!("Unit ({}) does not match {}",
+ unit_name, re))));
+ }
+ let unit = unit::get_units(unit_name);
+ let log = itry!(journal::get_log(unit_name, 15));
+ Ok(Response::with((status::Ok,
+ format!("{:?}\n{}", unit, log))))
+}
+
fn main() {
env_logger::init().unwrap();
let secret = b"secret2".to_vec();
let router = router!(
root: get "/" => overview,
- name: get "/:name" => overview,
+ details: get "/status/:unit" => unit_status,
journal: get "/journal/:unit" => journal,
css: get "/static/main.css" => Static::new(""),
);