Skip to content
binarynoirPublic

About

Monitor specified websites or IP addresses to see if it is reachable. It supports various notification methods including Pushover and native desktop notifications.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

NoirCon

NoirCon monitors various types of addresses (e.g., IP addresses, URLs) to check their availability and sends notifications. It supports various notification methods including Pushover and native desktop notifications.

Support me on Buy Me a Coffee Support me on Ko-fi Visit my website

Features

  • Monitors addresses to see if they are available
  • Sends notifications via Pushover and native desktop notifications (macOS, Linux, Windows)
  • Configurable check intervals
  • Verbose logging with different log levels
  • Background execution support
  • Customizable configuration
  • Supports multiple address monitoring
  • Custom scripts on FAIL, PASS, RECOVERED, and UNKNOWN
  • Detailed error reporting

Requirements

  • Bash 4.3+ (macOS ships Bash 3.2; install a newer one with brew install bash)
  • curl for HTTP/S checks
  • jq for reading the configuration file
  • ping, nc (netcat), openssl and whois for ICMP, TCP/UDP, certificate and domain checks
  • timeout for limiting check and command run times
  • GNU realpath on Linux, or grealpath from brew install coreutils on macOS
  • powershell for Windows desktop notifications
  • notify-send for Linux desktop notifications

Installation

macOS Using Homebrew

  1. Tap the repository (if not already tapped):

    brew tap binarynoir/noircon
  2. Install NoirCon:

    brew install noircon

Manual Installation (Linux/macOS Only)

  1. Clone the repository:

    git clone https://github.com/binarynoir/noircon.git
    cd noircon
  2. Make the script executable:

    chmod +x noircon
  3. Install notify-send for desktop notifications (if not already installed) on Linux:

    # On Debian/Ubuntu-based systems
    sudo apt install libnotify-bin
    
    # On Fedora-based systems
    sudo dnf install libnotify
    
    # On Arch-based systems
    sudo pacman -S libnotify

Windows Installation

  1. Install Git for Windows (includes Git Bash, if not installed).

  2. Clone the repository:

    git clone https://github.com/binarynoir/noircon.git
    cd noircon
  3. Make the script executable (in Git Bash or similar terminal):

    chmod +x noircon
  4. Ensure PowerShell is enabled in your Git Bash environment for notifications.

Installing the Man Page (Linux/macOS Only)

  1. Move the man file to the appropriate directory:

    sudo mv noircon.1 /usr/local/share/man/man1/
  2. Update the man database:

    sudo mandb
  3. View the man page:

    man noircon

Setting Up as a Service

Linux

  1. Create a systemd service file:

    sudo nano /etc/systemd/system/noircon.service
  2. Add the following content to the service file:

    [Unit]
    Description=NoirCon Service
    After=network.target
    
    [Service]
    ExecStart=/path/to/noircon
    WorkingDirectory=/path/to
    Restart=always
    User=your-username
    
    [Install]
    WantedBy=multi-user.target

    Replace /path/to/noircon with the actual path to the noircon script and your-username with your actual username.

    Do not add --start here. systemd runs NoirCon in the foreground and restarts it if it stops; --start would detach it from systemd. Logs go to the journal (journalctl -u noircon) as well as the NoirCon log file.

  3. Reload systemd to apply the new service:

    sudo systemctl daemon-reload
  4. Enable the service to start on boot:

    sudo systemctl enable noircon
  5. Start the service:

    sudo systemctl start noircon
  6. Check the status of the service:

    sudo systemctl status noircon

macOS

Run NoirCon as a LaunchAgent so it runs as you, reads your configuration file, and can show desktop notifications.

  1. Create a launchd plist file:

    nano ~/Library/LaunchAgents/com.noircon.plist
  2. Add the following content to the plist file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.noircon</string>
        <key>ProgramArguments</key>
        <array>
            <string>/path/to/noircon</string>
        </array>
        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
        </dict>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/tmp/noircon.launchd.log</string>
    </dict>
    </plist>

    Replace /path/to/noircon with the actual path to the noircon script. Do not add --start; launchd keeps NoirCon running in the foreground. The PATH entry lets launchd find Homebrew's Bash, because macOS's built-in Bash 3.2 cannot run NoirCon.

  3. Load the plist file to start the service:

    launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.noircon.plist
  4. Check the status of the service:

    launchctl print gui/$(id -u)/com.noircon | grep state
  5. To unload the service:

    launchctl bootout gui/$(id -u)/com.noircon

Setting Up NoirCon as a Service on Windows

  1. Create a Task in Task Scheduler:

    • Open Task Scheduler and select "Create Task".
    • In the "General" tab, name the task "NoirCon" and select "Run whether user is logged on or not".
    • In the "Triggers" tab, click "New" and set the trigger to "At startup".
    • In the "Actions" tab, click "New" and set the action to "Start a program".
      • In the "Program/script" field, enter the path to bash.exe (usually located in C:\Program Files\Git\bin\bash.exe if using Git Bash).
      • In the "Add arguments (optional)" field, enter the path to the noircon script and the --start argument, e.g., /path/to/noircon --start.
    • In the "Conditions" tab, uncheck "Start the task only if the computer is on AC power" to ensure it runs on battery power as well.
    • In the "Settings" tab, ensure "Allow task to be run on demand" is checked.
  2. Save and Test the Task:

    • Click "OK" to save the task.
    • To test the task, right-click on the "NoirCon" task in Task Scheduler and select "Run".
  3. Verify the Task:

    • Check the status of the task in Task Scheduler to ensure it is running.
    • Verify that NoirCon is running by checking the log file or the expected notifications.

Usage

Run the script with the desired options. Below are some examples:

  • Start application with default settings:

    ./noircon
  • Specify a custom configuration file:

    ./noircon --config /path/to/config
  • Run the script in the background:

    ./noircon --start
  • Send Pushover notifications:

    ./noircon --pushover --user-key YOUR_USER_KEY --api-token YOUR_API_TOKEN

Configuration

NoirCon uses a configuration file to store default settings. The default location is ~/.config/noircon.json. You can initialize a configuration file with default settings using:

./noircon --init

Example Configuration File

{
   "configuration": {
      "CACHE_DIR": "/tmp/noircon_cache",
      "LOG_FILE": "/tmp/noircon_cache/noircon.log",
      "CHECK_INTERVAL": "60s",
      "TIMEOUT": "5s",
      "SYSTEM_NAME": "test system",
      "PUSHOVER_NOTIFICATION": "false",
      "PUSHOVER_USER_KEY": "",
      "PUSHOVER_API_TOKEN": "",
      "DESKTOP_NOTIFICATION": "true",
      "VERBOSE": "false",
      "LOG_LEVEL": "INFO"
   },
   "connections": {
      "default": [
         {
            "NAME": "Ping Test",
            "TYPE": "PING",
            "HOST": "1.1.1.1",
            "TIMEOUT": "3s",
            "PASS_CMD": "./test/test_cmd.sh",
            "FAIL_CMD": "./test/test_cmd.sh"
         },
         {
            "NAME": "HTTP/S Test",
            "TYPE": "HTTP",
            "URL": "google.com",
            "TIMEOUT": "3s"
         },
         {
            "NAME": "TCP Test",
            "TYPE": "TCP",
            "HOST": "www.example.com",
            "PORT": "443",
            "TIMEOUT": "5s"
         },
         {
            "NAME": "UDP Test",
            "TYPE": "UDP",
            "HOST": "pool.ntp.org",
            "PORT": "123",
            "TIMEOUT": "15s"
         },
         {
            "NAME": "Domain Expiry Test",
            "TYPE": "DOMAIN",
            "DOMAIN": "google.com",
            "EXPIRY_DAYS": "200d",
            "TIMEOUT": "15s",
            "CHECK_FREQUENCY": "30d"
         },
         {
            "NAME": "Cert Expiry Test",
            "TYPE": "CERT",
            "DOMAIN": "google.com",
            "EXPIRY_DAYS": "30d",
            "TIMEOUT": "20s",
            "PASS_CMD": "./test/test_cmd.sh",
            "FAIL_CMD": "./test/test_cmd.sh",
            "RECOVERED_CMD": "./test/test_cmd.sh",
            "CHECK_FREQUENCY": "30d"
         }
      ]
   }
}

Configuration Notes

  • --init creates the configuration file so only your user can read it, because it can hold your Pushover keys. Keep it out of version control.
  • Settings given on the command line override the configuration file.
  • Unknown keys in the configuration section are ignored with a warning, so a typo cannot change unrelated settings.
  • CHECK_INTERVAL and TIMEOUT take a whole number with an optional s, m, h or d suffix, such as 30s or 5m.
  • The cache directory must belong to your user. NoirCon refuses to use system directories, your home directory, or a directory owned by someone else.

Options

General Options

  • -h, --help: Display the help message.
  • -V, --version: Display the script version.

Configuration and Initialization

  • -c, --config <config_file>: Specify a custom configuration file.
  • -i, --init: Initialize the configuration file.
  • -f, --force-init: Force initialize the configuration file if one exists.
  • -S, --show-config: Show the configuration settings.
  • -e, --show-config-file: Show the configuration file.
  • -E, --edit-config: Edit the configuration file.

Cache Management

  • -x, --clean: Delete all cached files.
  • -C, --cache-dir <path>: Specify a custom cache directory.

Notification Options

  • -n, --system-name <name>: Name of the system running the script.
  • -p, --pushover: Send Pushover notifications.
  • -u, --user-key <key>: Specify the user key for Pushover notifications.
  • -a, --api-token <token>: Specify the API token for Pushover notifications.
  • -d, --desktop: Send native desktop notifications (macOS, Linux and Windows).

Logging and Output

  • -v, --verbose: Enable verbose output.
  • -l, --log: Log the log file to the screen.
  • -o, --output <file>: Specify a custom log file location.
  • -L, --log-level <level>: Set the log level (FATAL, ERROR, WARN, INFO, DEBUG).

Remote Connection Configuration

  • -I, --interval <s,m,h,d>: Set the interval between checks (default: 60 seconds).
  • -T, --timeout <s,m,h,d>: Set the connection timeout for remote connections (default: 5 seconds).
  • -N, --repeat <number>: Repeat the checks in interactive mode N number of times and exit (default: 0).
  • -Z, --list-connections: List the current status of all remote connections.
  • -H, --history: Output a history of the connections to the screen.
  • -F, --force: Ignore the check frequency and check all connections.

Process Management

  • -s, --start: Start the NoirCon service in the background.
  • -k, --stop: Stop the NoirCon service.
  • -r, --restart: Restart the NoirCon service.
  • -t, --status: Check the current status of the NoirCon service. Exits with code 0 when it is running and 3 when it is stopped.

Docker Deployment Instructions

This guide provides step-by-step instructions to deploy the NoirCon service using Docker.

Docker Prerequisites

Ensure you have the following installed on your system:

  • Docker

Build and Deploy

Clone the repository, then build the image from the repository root. The image contains the noircon script from your checkout and runs it as an unprivileged user.

git clone https://github.com/binarynoir/noircon.git
cd noircon
docker build -t noircon-image .
docker run -d --restart unless-stopped --name noircon noircon-image

The image creates a default configuration at /app/noircon.json. To use your own, mount it over that file:

docker run -d --restart unless-stopped --name noircon \
  -v "$PWD/noircon.json:/app/noircon.json:ro" noircon-image

NoirCon runs in the foreground, so docker logs noircon shows its output and docker stop noircon shuts it down cleanly. Arguments after the image name are passed to NoirCon, for example docker run --rm noircon-image --show-config.

Instructions for Running the Tests

The tests run offline against local test servers, so they do not depend on outside websites.

Prerequisites

  • Bash 4.3+ and the dependencies listed under Requirements
  • python3 for the local test web server
  • shellcheck to lint the scripts (optional)

Steps to Run the Tests

From the repository root:

./test/test.sh

The script prints ok or FAIL for each check and exits with a non-zero status if any check fails. It works in a temporary directory and removes everything it creates when it exits.

To lint the scripts:

shellcheck -s bash noircon test/*.sh scripts/*.sh

GitHub Actions runs the linter and the tests on Linux and macOS for every push and pull request.

Releases

Releasing new releases

  1. Update VERSION and LAST_UPDATED in the noircon script.

  2. Add an entry for the new version to CHANGELOG.md.

  3. Commit the changes and merge them to main.

  4. Run the release script from the repository root:

    ./scripts/publish-release.sh

The script checks that the working tree is clean, that you are on main, and that the changelog has an entry for the version. It then tags the version and pushes the tag. The tag starts the release workflow, which runs CI, checks that the tag matches VERSION, creates the GitHub release, and updates the Homebrew formula.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Author

John Smith III

Acknowledgments

Thanks to all contributors and users for their support and feedback.

About

Monitor specified websites or IP addresses to see if it is reachable. It supports various notification methods including Pushover and native desktop notifications.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages