-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
executable file
·85 lines (76 loc) · 2 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# @brief dreport plugins functions.
#
# This file is part of the CLI project.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2021 YADRO
#
# @author: Alexander Soldatov <[email protected]>
# @author: Alexander Filippov <[email protected]>
# @brief output command result to stdout
# @param command
function add_cmd_output()
{
eval "${1}" | cat
}
# @brief output file content to stdout
# @param file fullname
function add_copy_file()
{
local file_name="$1"
if [[ -f $file_name ]]; then
cat "$file_name"
elif [[ -d $file_name ]]; then
if compgen -G "$file_name/host_*.log.gz" &>/dev/null; then
zcat "$file_name"/host_*.log.gz
elif compgen -G "$file_name/system*.journal" &>/dev/null; then
echo "Journald raw files are binary and cannot be displayed!"
echo "Use 'health log show journalpretty' instead"
else
echo "Nothing to display!"
fi
else
echo "Not a log: ${file_name}"
fi
}
# @brief Copy the symbolic link file to the dreport packaging,
# if it is in the user allowed dump size limit.
# @param $1 symbolic link file name
# @param $2 Plugin description used for logging.
function add_copy_sym_link_file()
{
add_copy_file "$(realpath "${1}")" "${2}"
}
# @brief log the error message
# @param error message
function log_error()
{
echo "$($TIME_STAMP) ERROR: " "$@"
}
# @brief log warning message
# @param warning message
function log_warning()
{
# `verbose` comes from the caller (dreport), calm shellcheck about it
# shellcheck disable=SC2154
if ((verbose == TRUE)); then
echo "$($TIME_STAMP) WARNING: " "$@"
fi
}
# @brief log info message
# @param info message
function log_info()
{
# `verbose` comes from the caller (dreport), calm shellcheck about it
# shellcheck disable=SC2154
if ((verbose == TRUE)); then
echo "$($TIME_STAMP) INFO: " "$@"
fi
}
# @brief log mmary message
# @param message
function log_summary()
{
echo "$($TIME_STAMP) " "$@"
}