summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-26 06:44:52 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-26 06:54:51 -0400
commitdd3406a9b60e1fb9308f1e68e247aa8f67e440b4 (patch)
treed1f65b05cde9b32b9345f8e4ccbea6dbb0060d83 /src/main.rs
parent8d414d7b8fdcad0466f413419d37edc1ebf922d0 (diff)
Add minimial unit details page.
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(""),
);