Project

General

Profile

« Previous | Next » 

Revision f0a87b44

Added by Benoît PECCATTE about 6 years ago

Fixes #12053: Add a \"rudder agent history\" command

View differences:

share/commands/agent-history
#!/bin/sh
# @description read log of old agent runs
# @man This command will output historic logs of agent runs.
# @man +
# @man *Options*:
# @man +
# @man *-c*: show history without color output
# @man +
# @man *-n*: show maximum n lines of history
# @man +
. "${BASEDIR}/../lib/common.sh"
. "${BASEDIR}/../lib/cfengine_parsing.sh"
BASE_PATH="/var/rudder/cfengine-community/outputs"
# Display 25 lines by default
max=25
while getopts "cn:" opt; do
case $opt in
c)
clear_colors
;;
n)
max="${OPTARG}"
;;
esac
done
for file in $(ls -1 ${BASE_PATH}/cf* | sort | tail -n ${max})
do
if type stat >/dev/null 2>/dev/null
then
endtime=$(stat -c "%Y" "${file}")
else
endtime=$(/opt/rudder/bin/perl -e'@a=stat $ARGV[0]; print $a[9]' "${file}")
fi
eval ${PRETTY} -v no_report=1 -v short_summary=1 -v endtime=${endtime} < "${file}"
done
share/lib/reports.awk
end_run = 0;
padding_dash = "--------------------------------------------------------------------------------";
padding = "################################################################################";
"date +%s.%N" | getline starttime;
broken_date = 0
"date +%s -d 2018-01-01 2>/dev/null" | getline fixed_date
if(fixed_date != 1514761200) {
broken_date=1
}
if(broken_date) {
"date +%s" | getline starttime;
} else {
"date +%s.%N" | getline starttime;
}
# needed to be able to call the same command a second time
close("date +%s.%N");
}
......
}
}
# not output at all, for summary mode
if (no_report) {
if (!original_time) {
if (match(r[9], /##/)) { # match the first ##
original_time = substr(r[9],0,RSTART-1)
"date +%s.%N -d \"" original_time "\" 2>/dev/null" | getline original_time_s;
}
}
}
if (summary_only) {
# for raw mode
if (summary_only && !no_report) {
print $0;
}
......
broken_reports++;
}
if (info) {
if (info && !no_report) {
print darkgreen $0 normal;
}
next
......
# Wait for the StartRun to display the config id
if (key == "StartRun") {
printf "%s\n\n", message;
if(!no_report) {
printf "%s\n\n", message;
}
next
}
if (key == "EndRun") {
......
{
if (component == "start")
{
printf "Start execution with config [%s]\n\n", key;
if(!no_report) {
printf "Start execution with config [%s]\n\n", key;
}
next
}
if (component == "end")
......
key = "";
}
if(no_report) {
next
}
#### 5/ Display reports
{
if (!summary_only) {
......
}
} else {
if (!header_printed) {
printf "%s", white;
printf "%s", white;
header_printed = 1;
if (multihost) {
......
if (full_strings) {
printf "%-7.7s ", "Mode";
} else {
} else {
printf "%-1.1s| ", "Mode";
}
}
printf "%-13.13s %-25.25s %-25.25s %-18.18s %s%s\n", "State", "Technique", "Component", "Key", "Message", normal;
printf "%-13.13s %-25.25s %-25.25s %-18.18s %s%s\n", "State", "Technique", "Component", "Key", "Message", normal;
}
......
END {
#### 6/ End of the run, time to compute result and display summary
"date +%s.%N" | getline endtime;
# Print a single line of summary
if (short_summary) {
if(broken_date) {
duration=0
} else {
duration=endtime-original_time_s
}
printf "%s (%3.0fs) ", original_time, duration
printf "%sEnforce%s: %s%3d%s compliant, %s%3d%s repaired, %s%3d%s N/A, %s%3d%s errors ", dgreen, normal, green, enforce_compliant, normal, yellow, enforce_repaired, normal, green, enforce_notapplicable, normal, red, enforce_error, normal
printf "%sAudit%s: %s%3d%s compliant, %s%3d%s non-compliant, %s%3d%s N/A, %s%3d%s errors\n", dblue, normal, green, audit_compliant, normal, magenta, audit_noncompliant, normal, green, audit_notapplicable, normal, red, audit_error, normal
exit 0
}
if(broken_date) {
"date +%s" | getline endtime;
} else {
"date +%s.%N" | getline endtime;
}
# Check if agent run finished correctly
if (!end_run && full_compliance) {

Also available in: Unified diff