Nalar

Nalar ( aka. NGINX Access Log Analyzer for Rust ) is a Rust library designed for analyzing Nginx access logs. It's purpose is to simplify the process of setting up necessary log configuration in nginx.conf and provide user-friendly statistics on incoming traffic to your web server. Self-hosting is intended for user convenience.

!!! WARNING: THIS CRATE IS CURRENTLY IN DEVELOPMENT AND IS NOT YET READY FOR USE IN PRODUCTION. !!!

Table of Contents

Capabilities

Features

Dependencies

Installation

To use Nalar in your project, add it to your Cargo.toml file:

toml [dependencies] nalar = "x.x.x"

Usage

Here is a simple example demonstrating some of crates current functionality:

```rust use nalar::utils::{ accesslog::AccessLog, regexutils::get_captures };

fn main() { let teststr: &str = r#"1001:111:c111:11a1:c11e:111a:c111:1f11 - - [04/Jun/2023:02:51:24 +0000] "GET /style.css HTTP/1.1" 304 0 "https://cocks.rs/" "Mozilla/5.0 (X11; Linux x8664; rv:109.0) Gecko/20100101 Firefox/113.0""#;

println!("EXAMPLE DEMONSTRATING SOME CURRENT FUNCTIONALITY\n\n");

println!("test_str: {}\n\n", test_str);

let log = AccessLog::default();

println!("default log instantiated: {}\n\n", log);

println!("{}\n\n", log.conf_get());

let caps = match get_captures(log, test_str) {
    Ok(caps) => caps,
    Err(e) => {
        return eprintln!("{}", e);
    },
};

caps.name("remote_addr").map(|m| println!("remote_addr: {}", m.as_str()));
caps.name("remote_user").map(|m| println!("remote_user: {}", m.as_str()));
caps.name("time_local").map(|m| println!("time_local: {}", m.as_str()));
caps.name("request").map(|m| println!("request: {}", m.as_str()));
caps.name("status").map(|m| println!("status: {}", m.as_str()));
caps.name("body_bytes_sent").map(|m| println!("body_bytes_sent: {}", m.as_str()));
caps.name("http_referer").map(|m| println!("http_referer: {}", m.as_str()));
caps.name("http_user_agent").map(|m| println!("http_user_agent: {}", m.as_str()));

println!("\n\n");

} ```

Available Log Formats

nalar currently supports three distinct log formats for NGINX access logs:

  1. Default:

  2. More:

  3. Detailed:

You can configure nalar to use any of these log formats by calling the conf_entry() function on the LogFormat enum corresponding to the format you want to use.

For example: rust let format = LogFormat::Detailed; let conf_entry = format.conf_entry();

This would return the string that you need to add to your NGINX configuration file to set the log format to 'Detailed'.

The LogFormat enum also includes name() and variables() methods that return the name of the format and the variables used in the format respectively.

rust let format_name = format.name(); // Returns "detailed". let variables_used = format.variables(); // Returns a string listing the variables used in the Detailed log format.

Documentation

Generate and view the documentation by running cargo doc --open.

Testing

Run the internal testing suite using cargo test.

Authors

License

MIT License