A simple daemon program to always test connections every few seconds and run given commands if test fails.
Go to file
Tigor Hutasuhut bf1077651d format: used spaces instead of tabs for better gitlab output 2022-09-15 22:54:46 +07:00
src format: used spaces instead of tabs for better gitlab output 2022-09-15 22:54:46 +07:00
.gitignore initial commit 2022-08-31 16:22:51 +07:00
Cargo.lock set program version to 1.0.0 2022-08-31 16:28:29 +07:00
Cargo.toml set program version to 1.0.0 2022-08-31 16:28:29 +07:00
LICENSE Add LICENSE 2022-08-31 09:25:10 +00:00
README.md initial commit 2022-08-31 16:22:51 +07:00
rustfmt.toml format: used spaces instead of tabs for better gitlab output 2022-09-15 22:54:46 +07:00

README.md

Network on Fail

Executes a program or script when ping fails to all given target host by certain amount of times.

By default it runs command for systemctl restart NetworkManager, which will restart your network if you use Network Manager as your primary network management and systemd. (Otherwise it fails, duh).

This program does not assume privilege access and thus if a command requires such thing, you must run this program as a user that can run that command. For example, by using sudo.

Example Usage

network-on-fail --target myamazingwebsite.com,cool.site.io --exec "echo oh no!"

# or

network-on-fail --target myamazingwebsite.com --target cool.site.io --exec "echo oh no!"

Example above will ping (using default ping parameters set by this program) myamazingwebsite.com at first, then when fails, pings cool.site.io. If that fails too, a counter will then be raised.

When counter reached maximum allowed (default 3), the exec command will be launched. In which case at the example command above, "echo oh no" will be executed.

On success ping, counter will be reset to 0.

Command and Arguments

USAGE:
network-on-fail [OPTIONS]

OPTIONS:
    -c, --count <COUNT>
            How many ping run fails before executing command. This means that when a ping run fails
            (all ping attempt to each target failed), a counter will be raised. When the counter
            reached this value, command will be executed then restart back to 0.

            A successful ping will put counter value back to 0.

            [default: 3]

    -d, --delay <DELAY>
            Delay between each ping run in seconds. Delay starts ticking after a ping to a host is a
            success operation

            [default: 10]

    -D, --delay-after-exec <DELAY_AFTER_EXEC>
            Delay after execute command in seconds

            [default: 30]

    -e, --exec <EXEC>...
            Command to execute when ping fails. Use quotes to handle command with spaces. Repeated
            argument will be appended

            [default: systemctl restart NetworkManager]
            [aliases: command]
            [short aliases: C]

    -h, --help
            Print help information

        --ping-count <PING_COUNT>
            Ping number of times before exit waiting for target

            [default: 1]

    -t, --target <TARGET>...
            Target hosts of ping. When one ping fails, the programs tries to ping the others first
            before rising the counter when all fails

            [default: google.com cloudflare.com]
            [aliases: ping]

    -T, --timeout <TIMEOUT>
            Timeout to wait between each ping in seconds

            [default: 5]

    -V, --version
            Print version information