Skip to content

Floofies/monit-ls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

monit-ls

monit-ls is a Node.js CLI script designed to fetch status information from Monit hosts and present it in various formats, including human-readable command-line output, JSON, and HTML.

The script uses ejs for HTML templating. A basic HTML template is embedded within the script. For more complex HTML reports, you can create a template.ejs file in the same directory as index.js, and the script will use that instead.

Features:

  • Multiple Monit Hosts: Query status from one or more Monit instances.
  • Flexible Configuration: Specify Monit host URLs directly via command-line arguments or through a JSON configuration file.
  • Error Handling: Gracefully handles unreachable Monit hosts or API errors.

Output Formats:

  • Table: A formatted ASCII spreadsheet for easy readability in the terminal.
  • JSON: A structured JSON object suitable for programmatic consumption.
  • HTML: A basic HTML report for web-based viewing.

Usage

The monit-ls script can be executed directly from the project directory, or via the monitls command.

You can specify Monit hosts in 3 ways. Provide a comma-separated list of Monit URLs. Include authentication credentials (username:password) directly in the URL if required.

Command-Line Options

Option Description
-h, --hosts hosts Comma-separated list of Monit URLs. (e.g. http://user:pass@host:2812)
-c, --config path Path to a JSON config file containing the list of hosts.
-f, --format format Output format: json, table, html.
-o, --output path File path to save the output.
-t, --template path Path to a custom EJS template for HTML reports.
-w, --wait timeout Number of seconds to wait for a response from each host.

Examples

  1. Via the first argument:
monitls http://user:pass@monit-host1:2812,http://monit-host2:2812
  1. Via the --hosts option:
monitls --hosts http://user:pass@monit-host1:2812,http://monit-host2:2812
  1. Using a configuration file with the --config option:
  • Create a JSON file (e.g., config.json) with a hosts array.
  • A custom EJS template path may also be supplied via a template string.
monitls --config ~/path/to/config.json

config.json example:

{
	"hosts": [
		"http://user:pass@monit-host1:2812",
		"http://monit-host2:2812"
	],
	"template": "~/path/to/custom_template.ejs",
	"wait": 5
}

Output Formats

Use the --format option to choose the output format. The default is table.

Table (default):

monitls --hosts http://user:pass@monit-host:2812 --format table

Example output:

┌───────────┬─────────┬──────┬────────┬──────────────┐
│ Host      │ Service │ Type │ Status │ Uptime/Usage │
├───────────┼─────────┼──────┼────────┼──────────────┤
│ test-host │ apache2 │ 3    │ OK     │ Up: 500s     │
├───────────┼─────────┼──────┼────────┼──────────────┤
│           │ rootfs  │ 5    │ OK     │ Disk: 45.0%  │
└───────────┴─────────┴──────┴────────┴──────────────┘

JSON:

monitls --hosts http://user:pass@monit-host:2812 --format json

Example output (truncated):

[
	{
		"url": "http://user:pass@monit-host:2812",
		"success": true,
		"data": {
			"$": { ... },
			"server": { ... },
			"platform": { ... },
			"service": [ { ... }, { ... } ]
		}
	}
]

HTML:

monitls --hosts http://user:pass@monit-host:2812 --format html

This will output HTML content to the console. To save it to a file, use the --output option.

Saving Output to a File

Use the --output <path> option to save the generated output to a specified file.

monitls --hosts http://user:pass@monit-host:2812 --format html --output monit_report.html

About

A tiny CLI script for NodeJS which lists data from Monit hosts. Outputs in human-readable or JSON formats.

Topics

Resources

License

Stars

Watchers

Forks

Contributors