mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-08 10:12:53 +01:00
so-status module
This commit is contained in:
4
salt/_modules/so.py
Normal file
4
salt/_modules/so.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!py
|
||||||
|
|
||||||
|
def status():
|
||||||
|
return __salt__['cmd.run']('/sbin/so-status')
|
||||||
@@ -14,8 +14,6 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
{%- from 'common/maps/so-status.map.jinja' import docker with context %}
|
|
||||||
{%- set container_list = docker['containers'] | sort | unique %}
|
|
||||||
|
|
||||||
if ! [ "$(id -u)" = 0 ]; then
|
if ! [ "$(id -u)" = 0 ]; then
|
||||||
echo "This command must be run as root"
|
echo "This command must be run as root"
|
||||||
@@ -39,7 +37,7 @@ declare -a container_state_list=()
|
|||||||
|
|
||||||
declare -a expected_container_list=()
|
declare -a expected_container_list=()
|
||||||
|
|
||||||
# {% raw %}
|
#
|
||||||
|
|
||||||
compare_lists() {
|
compare_lists() {
|
||||||
local found=0
|
local found=0
|
||||||
@@ -68,13 +66,17 @@ compare_lists() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# {% endraw %}
|
#
|
||||||
|
|
||||||
create_expected_container_list() {
|
create_expected_container_list() {
|
||||||
{% for item in container_list -%}
|
expected_container_list+=("so-curator")
|
||||||
expected_container_list+=("{{ item }}")
|
expected_container_list+=("so-elasticsearch")
|
||||||
{% endfor -%}
|
expected_container_list+=("so-filebeat")
|
||||||
}
|
expected_container_list+=("so-logstash")
|
||||||
|
expected_container_list+=("so-nginx")
|
||||||
|
expected_container_list+=("so-telegraf")
|
||||||
|
expected_container_list+=("so-wazuh")
|
||||||
|
}
|
||||||
|
|
||||||
populate_container_lists() {
|
populate_container_lists() {
|
||||||
systemctl is-active --quiet docker
|
systemctl is-active --quiet docker
|
||||||
@@ -122,7 +124,7 @@ parse_status() {
|
|||||||
printf $ERROR_STRING && return 1
|
printf $ERROR_STRING && return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# {% raw %}
|
#
|
||||||
|
|
||||||
print_line() {
|
print_line() {
|
||||||
local service_name=${1}
|
local service_name=${1}
|
||||||
@@ -149,7 +151,51 @@ print_line() {
|
|||||||
printf "%s \n" " ]"
|
printf "%s \n" " ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
non_term_print_line() {
|
||||||
|
local service_name=${1}
|
||||||
|
local service_state="$( parse_status ${2} )"
|
||||||
|
|
||||||
|
local PADDING_CONSTANT=10
|
||||||
|
|
||||||
|
printf " $service_name "
|
||||||
|
for i in $(seq 0 $(( 40 - $PADDING_CONSTANT - ${#service_name} - ${#service_state} ))); do
|
||||||
|
printf "-"
|
||||||
|
done
|
||||||
|
printf " [ "
|
||||||
|
printf "$service_state"
|
||||||
|
printf "%s \n" " ]"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
||||||
|
# if running from salt
|
||||||
|
if [ "$TERM" == 'dumb' ]; then
|
||||||
|
printf "\n"
|
||||||
|
printf "Checking Docker status\n\n"
|
||||||
|
|
||||||
|
systemctl is-active --quiet docker
|
||||||
|
if [[ $? = 0 ]]; then
|
||||||
|
non_term_print_line "Docker" "running"
|
||||||
|
else
|
||||||
|
non_term_print_line "Docker" "exited"
|
||||||
|
fi
|
||||||
|
|
||||||
|
populate_container_lists
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
printf "Checking container statuses\n\n"
|
||||||
|
|
||||||
|
local num_containers=${#container_name_list[@]}
|
||||||
|
|
||||||
|
for i in $(seq 0 $(($num_containers - 1 ))); do
|
||||||
|
non_term_print_line ${container_name_list[$i]} ${container_state_list[$i]}
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
# else if running from a terminal
|
||||||
|
else
|
||||||
|
|
||||||
local focus_color="\e[1;34m"
|
local focus_color="\e[1;34m"
|
||||||
printf "\n"
|
printf "\n"
|
||||||
printf "${focus_color}%b\e[0m" "Checking Docker status\n\n"
|
printf "${focus_color}%b\e[0m" "Checking Docker status\n\n"
|
||||||
@@ -173,9 +219,10 @@ main() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# {% endraw %}
|
#
|
||||||
|
|
||||||
|
|
||||||
main
|
main
|
||||||
Reference in New Issue
Block a user