Skip to content

Commit

Permalink
Merge pull request #117 from angelabriel/PED-2560
Browse files Browse the repository at this point in the history
add supportconfig plugin (jsc#PED-2560)
  • Loading branch information
stefanotorresi authored Apr 9, 2024
2 parents bf6cd7c + 41c29b1 commit 2caa33b
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# spec file for package prometheus-hanadb_exporter
#
# Copyright (c) 2022 SUSE LLC
# Copyright (c) 2022-2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
Expand Down Expand Up @@ -77,6 +77,7 @@ install -D -m 644 daemon/%{shortname}@.service %{buildroot}%{_unitdir}/%{name}@.
install -D -m 0644 config.json.example %{buildroot}%{_docdir}/%{name}/config.json.example
install -D -m 0644 metrics.json %{buildroot}%{_docdir}/%{name}/metrics.json
install -D -m 0644 logging_config.ini %{buildroot}%{_docdir}/%{name}/logging_config.ini
install -D -m 755 supportconfig-hanadb_exporter %{buildroot}%{_prefix}/lib/supportconfig/plugins/%{shortname}

%post
%service_add_post %{name}@.service
Expand Down Expand Up @@ -117,5 +118,8 @@ pytest tests
%{_docdir}/%{name}/metrics.json
%{_docdir}/%{name}/logging_config.ini
%{_unitdir}/%{name}@.service
%dir %{_prefix}/lib/supportconfig
%dir %{_prefix}/lib/supportconfig/plugins
%{_prefix}/lib/supportconfig/plugins/%{shortname}

%changelog
108 changes: 108 additions & 0 deletions supportconfig-hanadb_exporter
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash
set -u

# supportconfig plugin for hanadb_exporter
#
# v1.0
#
# February 2024 v1.0 first release

SVER='1.0.0'
TITLE="SUSE supportconfig plugin for hanadb_exporter"

function display_package_info() {
echo -e "\n#==[ Command ]======================================#"
echo -e "# rpm -qi ${1}"
rpm -qi "${1}"

echo -e "\n#==[ Command ]======================================#"
echo -e "# rpm -V ${1}"
rpm -V "${1}"
}

function display_file_stat() {
echo -e "\n#==[ File ]===========================#"
echo -e "# ls -ld ${1} ; stat ${1} \n"

if [ -e "${1}" ] ; then
ls -ld "${1}"
echo
stat "${1}"
else
echo "${1} does not exist!"
fi
}

function display_file() {
echo -e "\n#==[ File Content ]===========================#"
echo -e "# cat ${1}"

if [ -e "${1}" ] ; then
cat "${1}"
else
echo "${1} does not exist!"
fi
}

function display_systemd_status() {
echo -e "\n#==[ Command ]======================================#"
echo -e "# systemctl status ${1}"

systemctl status ''"${1}"'' 2>&1
}

function display_cmd() {
ORG_CMDLINE="${@}"
CMDBIN=${ORG_CMDLINE%% *}
FULLCMD=$(\which $CMDBIN 2>/dev/null | awk '{print $1}')
echo -e "\n#==[ Command ]======================================#"
if [ -x "$FULLCMD" ]; then
CMDLINE=$(echo $ORG_CMDLINE | sed -e "s!${CMDBIN}!${FULLCMD}!")
echo -e "# $CMDLINE"
echo "$CMDLINE" | bash
else
echo -e "# $ORG_CMDLINE"
echo "Command not found or not executable"
fi
}

function display_log() {
local file
echo -e "\n#==[ Log Files ]====================================#"
for file in "${@}" ; do
echo -e "\n# ${file}"
SKIP_FILE=$(echo ${file} | egrep "tbz$|bz2$|gz$|zip$")
if [ -n "$SKIP_FILE" ]; then
echo -e "skipping..."
continue
fi
cat "${file}"
echo -e "######"
done
}

# ---- Main ----
echo -e "Supportconfig Plugin for $TITLE, v${SVER}"

display_package_info prometheus-hanadb_exporter
# use 'pattern' for systemctl status cmd
display_systemd_status "*hanadb_exporter*"

for file in /usr/etc/hanadb_exporter/* /etc/hanadb_exporter/*; do
[ -e "${file}" ] && { display_file_stat "${file}" ; display_file "${file}" ; echo ; }
done

# default log file
display_log /var/log/hanadb_exporter*
# get logfile name from config file
if [ -f /etc/hanadb_exporter/config.json ]; then
logfile_from_config=$(sed -n 's%[[:blank:]]*"log_file":[[:blank:]]*"\(.*\)"%\1%p' /etc/hanadb_exporter/config.json)
[[ "$logfile_from_config" != "/var/log/hanadb_exporter.log" ]] && [ -f "$logfile_from_config" ] && display_log $logfile_from_config
fi
# log entries from syslog
display_cmd "grep -E -i 'hanadb_exporter\[.*\]:' /var/log/messages"

display_cmd "ss -tulpan | grep exporter"

# Bye.
exit 0

0 comments on commit 2caa33b

Please sign in to comment.