Skip to content

Commit dc246eb

Browse files
author
John Smith III
committed
reorganized code and functions and added additional information
1 parent 10f96b4 commit dc246eb

File tree

3 files changed

+68
-37
lines changed

3 files changed

+68
-37
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- none
1111

12+
## [1.0.1] - 2024-11-21
13+
14+
### Changed
15+
16+
- Showing the version information now includes last updated date
17+
- Reorganized functions for maintainability
18+
- Updated cli help and man page for better grouping of topics
19+
1220
## [1.0.0] - 2024-11-21
1321

1422
### Added

noirnet

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
# Description: Monitors to see if the device has internet and DNS access and send notifications.
44
# Author: John Smith III
55
# License: MIT License
6-
# Version: 1.0.0
7-
# Last Updated: 2024-11-22
86

97
# App version and name
10-
VERSION=1.0.0
8+
VERSION=1.0.1
119
APP_NAME="NoirNet"
10+
LAST_UPDATED="2024-11-22"
1211

1312
# Default configuration file location
1413
CONFIG_FILE="$HOME/.noirnetrc"
@@ -92,7 +91,8 @@ init_csv() {
9291

9392
# Function: Show version information
9493
show_version() {
95-
printf "$APP_NAME version: %s\n" "$VERSION"
94+
printf "%s version: %s\n" "$APP_NAME" "$VERSION"
95+
printf "Last updated: %s\n" "$LAST_UPDATE"
9696
exit 0
9797
}
9898

@@ -592,9 +592,9 @@ init_config() {
592592
# This file contains the settings for the $APP_NAME application.
593593
594594
# General Settings
595-
CONFIG_FILE="$CONFIG_FILE"
596595
CACHE_DIR="$CACHE_DIR"
597596
LOG_FILE="$LOG_FILE"
597+
CONFIG_FILE="$CONFIG_FILE"
598598
599599
# Monitoring Settings (in seconds)
600600
CHECK_INTERVAL=$CHECK_INTERVAL
@@ -630,17 +630,17 @@ EOF
630630

631631
# Function: Show configuration information
632632
show_config() {
633-
[ -n "$CONFIG_FILE" ] && log_message "INFO" "Configuration file: $CONFIG_FILE" "$LINENO"
634633
[ -n "$CACHE_DIR" ] && log_message "INFO" "Cache directory: $CACHE_DIR" "$LINENO"
635634
[ -n "$LOG_FILE" ] && log_message "INFO" "Log file: $LOG_FILE" "$LINENO"
635+
[ -n "$LOG_LEVEL" ] && log_message "INFO" "Log Level: $LOG_LEVEL" "$LINENO"
636+
[ -n "$VERBOSE" ] && log_message "INFO" "Verbose enabled: $VERBOSE" "$LINENO"
637+
[ -n "$CONFIG_FILE" ] && log_message "INFO" "Configuration file: $CONFIG_FILE" "$LINENO"
638+
[ -n "$PUSHOVER_NOTIFICATION" ] && log_message "INFO" "Pushover enabled: $PUSHOVER_NOTIFICATION" "$LINENO"
639+
[ -n "$DESKTOP_NOTIFICATION" ] && log_message "INFO" "Desktop notification enabled: $DESKTOP_NOTIFICATION" "$LINENO"
636640
[ -n "$PING_TARGET" ] && log_message "INFO" "Ping target: $PING_TARGET" "$LINENO"
637641
[ -n "$DNS_TEST_DOMAIN" ] && log_message "INFO" "Test domain target: $DNS_TEST_DOMAIN" "$LINENO"
638642
[ -n "$CHECK_INTERVAL" ] && log_message "INFO" "Check interval: $CHECK_INTERVAL sec(s)" "$LINENO"
639643
[ -n "$TIMEOUT" ] && log_message "INFO" "Timeout interval: $TIMEOUT sec(s)" "$LINENO"
640-
[ -n "$PUSHOVER_NOTIFICATION" ] && log_message "INFO" "Pushover enabled: $PUSHOVER_NOTIFICATION" "$LINENO"
641-
[ -n "$DESKTOP_NOTIFICATION" ] && log_message "INFO" "Desktop notification enabled: $DESKTOP_NOTIFICATION" "$LINENO"
642-
[ -n "$LOG_LEVEL" ] && log_message "INFO" "Log Level: $LOG_LEVEL" "$LINENO"
643-
[ -n "$VERBOSE" ] && log_message "INFO" "Verbose enabled: $VERBOSE" "$LINENO"
644644
}
645645

646646
# ==============================
@@ -658,7 +658,6 @@ show_help() {
658658

659659
# Configuration and Initialization
660660
printf "\nConfiguration and Initialization:\n"
661-
printf " -i, --interval <seconds> Set the interval between checks (default: %d seconds).\n" "${CHECK_INTERVAL:-5}"
662661
printf " -c, --config <config_file> Specify a custom configuration file (default: %s).\n" "${CONFIG_FILE:-~/.config/noirnet.conf}"
663662
printf " -I, --init Initialize the configuration file.\n"
664663
printf " -F, --force-init Force initialize of the configuration file if one exists.\n"
@@ -670,8 +669,8 @@ show_help() {
670669
printf " -C, --clean Delete all cached files.\n"
671670
printf " -k, --cache-dir <path> Specify a custom cache directory.\n"
672671

673-
# Execution Options
674-
printf "\nExecution Options:\n"
672+
# Notification Options
673+
printf "\Notification Options:\n"
675674
printf " -p, --pushover Send Pushover notifications.\n"
676675
printf " -a, --api-token <token> Specify the API token for Pushover notifications.\n"
677676
printf " -u, --user-key <key> Specify the user key for Pushover notifications.\n"
@@ -686,6 +685,7 @@ show_help() {
686685

687686
# Network Check Configuration
688687
printf "\nNetwork Check Configuration:\n"
688+
printf " -i, --interval <seconds> Set the interval between checks (default: %d seconds).\n" "${CHECK_INTERVAL:-5}"
689689
printf " -P, --ping-target <IP> Set a custom ping target (default: %s).\n" "${PING_TARGET:-8.8.8.8}"
690690
printf " -D, --dns-test-domain <domain> Set a custom DNS test domain (default: %s).\n" "${DNS_TEST_DOMAIN:-example.com}"
691691
printf " -T, --timeout <seconds> Set the timeout for ping and DNS tests (default: %d seconds).\n" "${DNS_TEST_TIMEOUT:-5}"
@@ -933,6 +933,7 @@ process_arguments() {
933933
# Network Monitoring Function
934934
# ==============================
935935

936+
# Function: Start the monitoring process
936937
start_monitor() {
937938
local network_down_start dns_down_start
938939
local network_down=false dns_down=false

noirnet.1

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
.TH NOIRNET 1 "November 22, 2024" "1.0.0" "NoirNet Manual"
1+
.TH NOIRNET 1 "November 22, 2024" "Version 1.0.1" "User Commands"
22
.SH NAME
3-
NoirNet \- Monitors internet and DNS access and sends notifications
3+
NoirNet \- Monitors internet and DNS access and sends notifications.
44

55
.SH SYNOPSIS
66
.B noirnet
7-
[\fIoptions\fR]
7+
.RI [ options ]
88

99
.SH DESCRIPTION
1010
.B NoirNet
11-
is a script that monitors the device's internet and DNS access and sends notifications via Pushover and desktop notifications.
11+
is a script designed to monitor the device's internet and DNS access. It logs downtime and sends notifications via desktop or Pushover.
1212

1313
.SH OPTIONS
1414
.TP
@@ -18,37 +18,34 @@ Display this help message.
1818
.B \-V, \-\-version
1919
Display the application version.
2020
.TP
21-
.B \-i, \-\-interval \fIseconds\fR
22-
Set the interval between checks (default: 60 seconds).
23-
.TP
24-
.B \-c, \-\-config \fIconfig_file\fR
25-
Specify a custom configuration file (default: ~/.noirnetrc).
21+
.B \-c, \-\-config \fI<config_file>\fP
22+
Specify a custom configuration file (default: $HOME/.noirnetrc).
2623
.TP
2724
.B \-I, \-\-init
2825
Initialize the configuration file.
2926
.TP
30-
.B \-F, \-\-force-init
31-
Force initialize the configuration file if one exists.
27+
.B \-F, \-\-force\-init
28+
Force initialization of the configuration file if one exists.
3229
.TP
33-
.B \-s, \-\-show-config
30+
.B \-s, \-\-show\-config
3431
Show the configuration settings.
3532
.TP
36-
.B \-S, \-\-show-config-file
33+
.B \-S, \-\-show\-config\-file
3734
Show the configuration file.
3835
.TP
3936
.B \-C, \-\-clean
4037
Delete all cached files.
4138
.TP
42-
.B \-k, \-\-cache-dir \fIpath\fR
39+
.B \-k, \-\-cache\-dir \fI<path>\fP
4340
Specify a custom cache directory.
4441
.TP
4542
.B \-p, \-\-pushover
4643
Send Pushover notifications.
4744
.TP
48-
.B \-a, \-\-api-token \fItoken\fR
45+
.B \-a, \-\-api\-token \fI<token>\fP
4946
Specify the API token for Pushover notifications.
5047
.TP
51-
.B \-u, \-\-user-key \fIkey\fR
48+
.B \-u, \-\-user\-key \fI<key>\fP
5249
Specify the user key for Pushover notifications.
5350
.TP
5451
.B \-d, \-\-desktop
@@ -60,19 +57,22 @@ Enable verbose output.
6057
.B \-l, \-\-log
6158
Log the log file to the screen.
6259
.TP
63-
.B \-o, \-\-output \fIfile\fR
60+
.B \-o, \-\-output \fI<file>\fP
6461
Specify a custom log file location.
6562
.TP
66-
.B \-L, \-\-log-level \fIlevel\fR
63+
.B \-L, \-\-log\-level \fI<level>\fP
6764
Set the log level (FATAL, ERROR, WARN, INFO, DEBUG).
6865
.TP
69-
.B \-P, \-\-ping-target \fIIP\fR
66+
.B \-i, \-\-interval \fI<seconds>\fP
67+
Set the interval between checks (default: 60 seconds).
68+
.TP
69+
.B \-P, \-\-ping\-target \fI<IP>\fP
7070
Set a custom ping target (default: 8.8.8.8).
7171
.TP
72-
.B \-D, \-\-dns-test-domain \fIdomain\fR
72+
.B \-D, \-\-dns\-test\-domain \fI<domain>\fP
7373
Set a custom DNS test domain (default: example.com).
7474
.TP
75-
.B \-T, \-\-timeout \fIseconds\fR
75+
.B \-T, \-\-timeout \fI<seconds>\fP
7676
Set the timeout for ping and DNS tests (default: 5 seconds).
7777
.TP
7878
.B \-r, \-\-start
@@ -90,10 +90,10 @@ Run interactively with default settings:
9090
.B noirnet
9191
.TP
9292
Run interactively with custom targets:
93-
.B noirnet \-\-ping-target 1.1.1.1 \-\-dns-test-domain google.com
93+
.B noirnet \-\-ping\-target 1.1.1.1 \-\-dns\-test\-domain google.com
9494
.TP
9595
Start the service with custom targets:
96-
.B noirnet \-\-ping-target 1.1.1.1 \-\-dns-test-domain google.com \-\-start
96+
.B noirnet \-\-ping\-target 1.1.1.1 \-\-dns\-test\-domain google.com \-\-start
9797
.TP
9898
Check service status:
9999
.B noirnet \-\-status
@@ -107,5 +107,27 @@ John Smith III
107107
.SH LICENSE
108108
MIT License
109109

110+
.SH FILES
111+
.TP
112+
.B $HOME/.noirnetrc
113+
Default configuration file.
114+
.TP
115+
.B /tmp/noirnet_cache
116+
Directory to store all cache files.
117+
.TP
118+
.B /tmp/noirnet_cache/noirnet.log
119+
Default log file location.
120+
.TP
121+
.B /tmp/noirnet_cache/noirnet.pid
122+
Lock file.
123+
.TP
124+
.B /tmp/noirnet_cache/network_downtime.csv
125+
CSV file for network downtime history.
126+
.TP
127+
.B /tmp/noirnet_cache/dns_downtime.csv
128+
CSV file for DNS downtime history.
129+
110130
.SH SEE ALSO
111-
ping(8), nslookup(1), curl(1)
131+
.BR ping (8),
132+
.BR nslookup (1),
133+
.BR curl (1)

0 commit comments

Comments
 (0)