mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-07 09:42:46 +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
|
||||
# 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
|
||||
echo "This command must be run as root"
|
||||
@@ -39,7 +37,7 @@ declare -a container_state_list=()
|
||||
|
||||
declare -a expected_container_list=()
|
||||
|
||||
# {% raw %}
|
||||
#
|
||||
|
||||
compare_lists() {
|
||||
local found=0
|
||||
@@ -68,13 +66,17 @@ compare_lists() {
|
||||
done
|
||||
}
|
||||
|
||||
# {% endraw %}
|
||||
#
|
||||
|
||||
create_expected_container_list() {
|
||||
{% for item in container_list -%}
|
||||
expected_container_list+=("{{ item }}")
|
||||
{% endfor -%}
|
||||
}
|
||||
expected_container_list+=("so-curator")
|
||||
expected_container_list+=("so-elasticsearch")
|
||||
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() {
|
||||
systemctl is-active --quiet docker
|
||||
@@ -93,7 +95,7 @@ populate_container_lists() {
|
||||
for line in "${docker_raw_list[@]}"; do
|
||||
container_name="$( echo $line | sed -e 's/Name:\(.*\),State:\(.*\)/\1/' )" # Get value in the first search group (container names)
|
||||
container_state="$( echo $line | sed -e 's/Name:\(.*\),State:\(.*\)/\2/' )" # Get value in the second search group (container states)
|
||||
|
||||
|
||||
temp_container_name_list+=( "${container_name}" )
|
||||
temp_container_state_list+=( "${container_state}" )
|
||||
done
|
||||
@@ -122,7 +124,7 @@ parse_status() {
|
||||
printf $ERROR_STRING && return 1
|
||||
}
|
||||
|
||||
# {% raw %}
|
||||
#
|
||||
|
||||
print_line() {
|
||||
local service_name=${1}
|
||||
@@ -149,33 +151,78 @@ print_line() {
|
||||
printf "%s \n" " ]"
|
||||
}
|
||||
|
||||
main() {
|
||||
local focus_color="\e[1;34m"
|
||||
printf "\n"
|
||||
printf "${focus_color}%b\e[0m" "Checking Docker status\n\n"
|
||||
non_term_print_line() {
|
||||
local service_name=${1}
|
||||
local service_state="$( parse_status ${2} )"
|
||||
|
||||
systemctl is-active --quiet docker
|
||||
if [[ $? = 0 ]]; then
|
||||
print_line "Docker" "running"
|
||||
else
|
||||
print_line "Docker" "exited"
|
||||
fi
|
||||
local PADDING_CONSTANT=10
|
||||
|
||||
populate_container_lists
|
||||
|
||||
printf "\n"
|
||||
printf "${focus_color}%b\e[0m" "Checking container statuses\n\n"
|
||||
|
||||
local num_containers=${#container_name_list[@]}
|
||||
|
||||
for i in $(seq 0 $(($num_containers - 1 ))); do
|
||||
print_line ${container_name_list[$i]} ${container_state_list[$i]}
|
||||
printf " $service_name "
|
||||
for i in $(seq 0 $(( 40 - $PADDING_CONSTANT - ${#service_name} - ${#service_state} ))); do
|
||||
printf "-"
|
||||
done
|
||||
|
||||
printf "\n"
|
||||
printf " [ "
|
||||
printf "$service_state"
|
||||
printf "%s \n" " ]"
|
||||
}
|
||||
|
||||
# {% endraw %}
|
||||
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"
|
||||
printf "\n"
|
||||
printf "${focus_color}%b\e[0m" "Checking Docker status\n\n"
|
||||
|
||||
systemctl is-active --quiet docker
|
||||
if [[ $? = 0 ]]; then
|
||||
print_line "Docker" "running"
|
||||
else
|
||||
print_line "Docker" "exited"
|
||||
fi
|
||||
|
||||
populate_container_lists
|
||||
|
||||
printf "\n"
|
||||
printf "${focus_color}%b\e[0m" "Checking container statuses\n\n"
|
||||
|
||||
local num_containers=${#container_name_list[@]}
|
||||
|
||||
for i in $(seq 0 $(($num_containers - 1 ))); do
|
||||
print_line ${container_name_list[$i]} ${container_state_list[$i]}
|
||||
done
|
||||
|
||||
printf "\n"
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
|
||||
main
|
||||
main
|
||||
Reference in New Issue
Block a user