Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor and major updates #4

Merged
merged 8 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 47 additions & 36 deletions gateways/base/module-toggler.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash

# Network Interface Monitor Module
# Module Toggler
# Executd from the Gateways
# Monitors network activity on specific interface(s)
# Report and update status of modules
# Usage: Run when needed

########## HEADER ##########

module_name=general # status_update is a part of general
Expand All @@ -19,72 +18,84 @@ echo "########## START ##########"

########## BODY ##########

# Set up some colors for user-friendly display
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Function to get all modules without the "general" module
get_filtered_modules() {
local modules=($(yq eval 'keys | .[]' $config_file))
local filtered_modules=()
for module in "${modules[@]}"; do
if [ "$module" != "general" ]; then
filtered_modules+=("$module")
fi
done
echo "${filtered_modules[@]}"
}

# Using the above function to get the filtered list
filtered_modules=($(get_filtered_modules))

# Function to display modules and their status
display_modules_status() {
echo "Modules and their current status:"
modules=($(yq eval 'keys | .[]' $config_file))
for idx in "${!modules[@]}"; do
if [ "${modules[$idx]}" == "general" ]; then
status=$(yq e ".general.gateway_maintenance_mode" $config_file)
echo "$((idx+1)). ${modules[$idx]} (maintenance_mode): $status"
else
status=$(yq e ".${modules[$idx]}.enabled" $config_file)
echo "$((idx+1)). ${modules[$idx]}: $status"
fi
max_index_length=${#filtered_modules[@]}
for idx in "${!filtered_modules[@]}"; do
formatted_idx=$(printf "%${max_index_length}s" "$((idx+1))")
status=$(yq e ".${filtered_modules[$idx]}.is_enabled" $config_file)
status_text_colored=$( [ "$status" == "true" ] && echo "${GREEN}[+] enabled${NC}" || echo "${RED}[-] disabled${NC}" )
echo -e "$formatted_idx. ${filtered_modules[$idx]}: $status_text_colored"
done
}

# Function to toggle the status of a module
toggle_module_status() {
local opt="$1"
local opt_idx="$1"
local opt="${filtered_modules[$opt_idx]}"
local current_status

if [ "$opt" == "general" ]; then
current_status=$(get_config_value "general" "gateway_maintenance_mode")
if [ "$current_status" == "true" ]; then
yq eval ".${opt}.gateway_maintenance_mode = false" -i $config_file
echo "Set ${opt}'s gateway_maintenance_mode to false."
else
yq eval ".${opt}.gateway_maintenance_mode = true" -i $config_file
echo "Set ${opt}'s gateway_maintenance_mode to true."
fi
current_status=$(get_config_value "$opt" "is_enabled")
if [ "$current_status" == "true" ]; then
yq eval ".${opt}.is_enabled = false" -i $config_file
echo
echo "${opt} disabled."
else
current_status=$(get_config_value "$opt" "enabled")
if [ "$current_status" == "true" ]; then
yq eval ".${opt}.enabled = false" -i $config_file
echo "Set ${opt} to false."
else
yq eval ".${opt}.enabled = true" -i $config_file
echo "Set ${opt} to true."
fi
yq eval ".${opt}.is_enabled = true" -i $config_file
echo
echo "${opt} enabled."
fi
}

# Display modules and their status
echo
display_modules_status
echo

# Get user selection
echo "Select modules to toggle its status (e.g., 1 3 6) or enter 'q' to exit without changes:"
echo -e "Choose one or more modules (e.g., 1, 3, 6) to toggle their status (enable/disable), or type 'q' to exit without making any changes:"
read -a selections

for selected in "${selections[@]}"; do
# Exit if user chooses the exit option
if [ "$selected" == "q" ]; then
echo
echo "Exiting without changes."

# Validate user input
elif [ "$selected" -lt 1 ] || [ "$selected" -gt "${#modules[@]}" ]; then
elif [ "$selected" -lt 1 ] || [ "$selected" -gt "${#filtered_modules[@]}" ]; then
echo
echo "Invalid selection: $selected. Exiting without changes."

else
idx=$((selected-1))
toggle_module_status "${modules[$idx]}"
toggle_module_status "$idx"
fi
done

# After toggling the status, display and log the final status
echo
echo "Final Status:"
display_modules_status 2>&1 | tee $general_data_dir/$general_git_logs_branch/$general_module_toggler_log_file
echo

########## FOOTER ##########

Expand Down
78 changes: 39 additions & 39 deletions gateways/base/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export general_log_file=$(yq e '.general.log_file' $config_file)
export general_gateway_name=$(yq e '.general.gateway_name' $config_file)
export general_gateway_location=$(yq e '.general.gateway_location' $config_file)
export general_gateway_power_mode=$(yq e '.general.gateway_power_mode' $config_file)
export general_gateway_maintenance_mode=$(yq e '.general.gateway_maintenance_mode' $config_file)
export general_data_dir=$(yq e '.general.data_dir' $config_file)
export general_apps_dir=$(yq e '.general.apps_dir' $config_file)
export general_datalogger_data_dir=$(yq e '.general.datalogger_data_dir' $config_file)
Expand All @@ -21,42 +20,43 @@ export general_git_logs_branch=$(yq e '.general.git_logs_branch' $config_file)
export general_module_toggler_log_file=$(yq e '.general.module_toggler_log_file' $config_file)

# Scheduler
export scheduler_enabled=$(yq e '.scheduler.enabled' $config_file)
export scheduler_log_file=$(yq e '.scheduler.log_file' $config_file)
export scheduler_shutdown_delay_after_reboot=$(yq e '.scheduler.shutdown_delay_after_reboot' $config_file)
export scheduler_shutdown_time=$(yq e '.scheduler.shutdown_time' $config_file)
export shutdown_scheduler_is_enabled=$(yq e '.shutdown_scheduler.is_enabled' $config_file)
export shutdown_scheduler_log_file=$(yq e '.shutdown_scheduler.log_file' $config_file)
export shutdown_scheduler_post_reboot_delay_minutes=$(yq e '.shutdown_scheduler.post_reboot_delay_minutes' $config_file)
export shutdown_scheduler_shutdown_time=$(yq e '.shutdown_scheduler.shutdown_time' $config_file)

# Startup Notifier
export startup_notifier_enabled=$(yq e '.startup_notifier.enabled' $config_file)
export startup_notifier_is_enabled=$(yq e '.startup_notifier.is_enabled' $config_file)
export startup_notifier_log_file=$(yq e '.startup_notifier.log_file' $config_file)
export startup_notifier_local_repo_dir=$(yq e '.startup_notifier.local_repo_dir' $config_file)
export startup_notifier_git_repo=$(yq e '.startup_notifier.git_repo' $config_file)
export startup_notifier_git_branch=$(yq e '.startup_notifier.git_branch' $config_file)

# Status Monitor
export status_monitor_enabled=$(yq e '.status_monitor.enabled' $config_file)
export status_monitor_is_enabled=$(yq e '.status_monitor.is_enabled' $config_file)
export status_monitor_log_file=$(yq e '.status_monitor.log_file' $config_file)

# Git Push
export git_push_enabled=$(yq e '.git_push.enabled' $config_file)
export git_push_is_enabled=$(yq e '.git_push.is_enabled' $config_file)
export git_push_log_file=$(yq e '.git_push.log_file' $config_file)
export git_push_directories=$(yq e '.git_push.directories[]' $config_file)

# Git Garbage Collector
export git_garbage_collector_enabled=$(yq e '.git_garbage_collector.enabled' $config_file)
export git_garbage_collector_is_enabled=$(yq e '.git_garbage_collector.is_enabled' $config_file)
export git_garbage_collector_log_file=$(yq e '.git_garbage_collector.log_file' $config_file)
export git_garbage_collector_directories=$(yq e '.git_garbage_collector.directories[]' $config_file)

# Health Checks IO
export health_checks_io_enabled=$(yq e '.health_checks_io.enabled' $config_file)
export health_checks_io_is_enabled=$(yq e '.health_checks_io.is_enabled' $config_file)
export health_checks_io_log_file=$(yq e '.health_checks_io.log_file' $config_file)
export health_checks_io_ping_url=$(yq e '.health_checks_io.ping_url' $config_file)
export health_checks_io_max_time=$(yq e '.health_checks_io.max_time' $config_file)
export health_checks_io_retry=$(yq e '.health_checks_io.retry' $config_file)

# Reverse SSH
export reverse_ssh_enabled=$(yq e '.reverse_ssh.enabled' $config_file)
export reverse_ssh_is_enabled=$(yq e '.reverse_ssh.is_enabled' $config_file)
export reverse_ssh_log_file=$(yq e '.reverse_ssh.log_file' $config_file)
export reverse_ssh_autossh_log_file=$(yq e '.reverse_ssh.autossh_log_file' $config_file)
export reverse_ssh_local_port=$(yq e '.reverse_ssh.local_port' $config_file)
export reverse_ssh_base_port=$(yq e '.reverse_ssh.base_port' $config_file)
export reverse_ssh_remote_port=$(yq e '.reverse_ssh.remote_port' $config_file)
Expand All @@ -67,51 +67,51 @@ export reverse_ssh_ServerAliveInterval=$(yq e '.reverse_ssh.ServerAliveInterval'
export reverse_ssh_ServerAliveCountMax=$(yq e '.reverse_ssh.ServerAliveCountMax' $config_file)

# Datalogger Mock Data Generator
export datalogger_mock_data_generator_enabled=$(yq e '.datalogger_mock_data_generator.enabled' $config_file)
export datalogger_mock_data_generator_is_enabled=$(yq e '.datalogger_mock_data_generator.is_enabled' $config_file)
export datalogger_mock_data_generator_log_file=$(yq e '.datalogger_mock_data_generator.log_file' $config_file)
export datalogger_mock_data_generator_data_file=$(yq e '.datalogger_mock_data_generator.data_file' $config_file)
export datalogger_mock_data_generator_interval=$(yq e '.datalogger_mock_data_generator.interval' $config_file)

# Network Interface Monitor
export network_interface_monitor_enabled=$(yq e '.network_interface_monitor.enabled' $config_file)
export network_interface_monitor_is_enabled=$(yq e '.network_interface_monitor.is_enabled' $config_file)
export network_interface_monitor_log_file=$(yq e '.network_interface_monitor.log_file' $config_file)
export network_interface_monitor_log_rotation_interval=$(yq e '.network_interface_monitor.log_rotation_interval' $config_file)
export network_interface_monitor_interfaces=$(yq e '.network_interface_monitor.interfaces[]' $config_file)

# LED Monitor
export led_monitor_enabled=$(yq e '.led_monitor.enabled' $config_file)
export led_monitor_is_enabled=$(yq e '.led_monitor.is_enabled' $config_file)
export led_monitor_log_file=$(yq e '.led_monitor.log_file' $config_file)

# LoRa
export lora_enabled=$(yq e '.lora.enabled' $config_file)
export lora_log_file=$(yq e '.lora.log_file' $config_file)
export lora_mode=$(yq e '.lora.mode' $config_file)
export lora_serial_interface=$(yq e '.lora.serial_interface' $config_file)
export lora_lora_interface=$(yq e '.lora.lora_interface' $config_file)
export lora_evio_interface=$(yq e '.lora.evio_interface' $config_file)
export lora_switch_interface=$(yq e '.lora.switch_interface' $config_file)
export lora_node_ip=$(yq e '.lora.node_ip' $config_file)
export lora_switch_ip=$(yq e '.lora.switch_ip' $config_file)
export lora_baud_rate=$(yq e '.lora.baud_rate' $config_file)
export lora_mtu=$(yq e '.lora.mtu' $config_file)
export lora_rate=$(yq e '.lora.rate' $config_file)
export lora_burst=$(yq e '.lora.burst' $config_file)
export lora_latency=$(yq e '.lora.latency' $config_file)
export lora_ingress_policing_rate=$(yq e '.lora.ingress_policing_rate' $config_file)
export lora_ingress_policing_burst=$(yq e '.lora.ingress_policing_burst' $config_file)

# Nebula
export nebula_enabled=$(yq e '.nebula.enabled' $config_file)
export nebula_log_file=$(yq e '.nebula.log_file' $config_file)
# LoRa Radio
export lora_radio_is_enabled=$(yq e '.lora_radio.is_enabled' $config_file)
export lora_radio_log_file=$(yq e '.lora_radio.log_file' $config_file)
export lora_radio_mode=$(yq e '.lora_radio.mode' $config_file)
export lora_radio_serial_interface=$(yq e '.lora_radio.serial_interface' $config_file)
export lora_radio_lora_interface=$(yq e '.lora_radio.lora_interface' $config_file)
export lora_radio_evio_interface=$(yq e '.lora_radio.evio_interface' $config_file)
export lora_radio_switch_interface=$(yq e '.lora_radio.switch_interface' $config_file)
export lora_radio_node_ip=$(yq e '.lora_radio.node_ip' $config_file)
export lora_radio_switch_ip=$(yq e '.lora_radio.switch_ip' $config_file)
export lora_radio_baud_rate=$(yq e '.lora_radio.baud_rate' $config_file)
export lora_radio_mtu=$(yq e '.lora_radio.mtu' $config_file)
export lora_radio_rate=$(yq e '.lora_radio.rate' $config_file)
export lora_radio_burst=$(yq e '.lora_radio.burst' $config_file)
export lora_radio_latency=$(yq e '.lora_radio.latency' $config_file)
export lora_radio_ingress_policing_rate=$(yq e '.lora_radio.ingress_policing_rate' $config_file)
export lora_radio_ingress_policing_burst=$(yq e '.lora_radio.ingress_policing_burst' $config_file)

# Nebula Overlay Network
export nebula_overlay_network_is_enabled=$(yq e '.nebula_overlay_network.is_enabled' $config_file)
export nebula_overlay_network_log_file=$(yq e '.nebula_overlay_network.log_file' $config_file)

########## DEFINE FUNCTIONS ##########

# Check if module is enabled
# Check if module is is_enabled
check_if_enabled() {
module_enabled_var="${1}_enabled"
module_is_enabled_var="${1}_is_enabled"

if [ "${!module_enabled_var}" != "true" ]; then
echo "Module $1 is not enabled. Exiting..."
if [ "${!module_is_enabled_var}" != "true" ]; then
echo "Module $1 is not is_enabled. Exiting..."
exit 0
fi
}
Expand Down
69 changes: 47 additions & 22 deletions gateways/config-files/annie/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
general:
log_file: general.log
gateway_name: annie
gateway_location: ccre-dam
gateway_power_mode: ac # "ac" or "battery"
Expand All @@ -9,48 +10,50 @@ general:
git_repo: [email protected]:FLARE-forecast/CCRE-data.git
git_data_branch: ccre-dam-data
git_logs_branch: annie-logs
module_toggler_log_file: module-toggler.log

scheduler:
enabled: true
log_file: scheduler.log
shutdown_delay_after_reboot: 30 # Shutdown delay after reboot in minutes
shutdown_time: 00:10 # Exact time for shutdown
shutdown_scheduler:
is_enabled: true
log_file: shutdown-scheduler.log
post_reboot_delay_minutes: 30 # Delay in minutes after reboot before scheduling a shutdown when on battery
shutdown_time: 00:10 # HH:MM format, the exact time to schedule a shutdown when on AC power

startup_notifier:
enabled: true
is_enabled: true
log_file: startup-notifier.log
local_repo_dir: startup-notifier
git_repo: [email protected]:FLARE-forecast/CCRE-data.git
git_branch: main

status_monitor:
enabled: true
is_enabled: true
log_file: status-monitor.log

git_push:
enabled: true
is_enabled: true
log_file: git-push.log
directories:
- /data/ccre-dam-data
- /data/annie-logs
- /data/ccre-dam-data
- /data/annie-logs

git_garbage_collector:
enabled: true
is_enabled: true
log_file: git-garbage-collector.log
directories:
- /data/ccre-dam-data
- /data/annie-logs
- /data/ccre-dam-data
- /data/annie-logs

health_checks_io:
enabled: true
is_enabled: true
log_file: health-checks-io.log
ping_url: https://hc-ping.com/796de728-9e18-4133-a810-397a275d2ae2
max_time: 60
retry: 5

reverse_ssh:
enabled: true
is_enabled: true
log_file: reverse-ssh.log
autossh_log_file: autossh.log
local_port: 60006
base_port: 61000
remote_port: 22
Expand All @@ -61,21 +64,43 @@ reverse_ssh:
ServerAliveCountMax: 3

datalogger_mock_data_generator:
enabled: false
is_enabled: false
log_file: datalogger-mock-data-generator.log
data_file: datalogger-mock-data.csv
interval: 10 # Frequency of generating data in minutes

network_interface_monitor:
enabled: false
is_enabled: false
log_file: network-interface-monitor.log
log_rotation_interval: 86400 # Frequency of log rotation in seconds
interfaces:
- name: enp2s0
log_file: enp2s0.log
- name: nebula1
log_file: nebula1.log
- name: enp2s0
log_file_directory: enp2s0 # To store .pcap files
- name: nebula1
log_file_directory: nebula1 # To store .pcap files

led_monitor: # Not working with newer Linux kernels
enabled: false
is_enabled: false
log_file: led-monitor.log

lora_radio:
is_enabled: false
log_file: lora-radio.log
mode: pendant # "evio" or "noevio" or "pendant"
serial_interface: ttyUSB0
lora_interface: tnc0
evio_interface: appCIBR6
switch_interface: enp1s0
node_ip: 10.10.101.2/24 # ip/netmask
switch_ip: 10.10.101.1/24 # ip/netmask, IP address of the gateway on the other side of the LoRa link
baud_rate: 115200
mtu: 400 # bytes
rate: 20 # kbit
burst: 32 # kbit
latency: 400 # ms
ingress_policing_rate: 10 #kbit
ingress_policing_burst: 10 #kbit

nebula_overlay_network:
is_enabled: true
log_file: nebula-overlay-network.log
Loading