diff options
author | Michael Boelen <michael.boelen@cisofy.com> | 2019-07-14 16:12:25 +0300 |
---|---|---|
committer | Michael Boelen <michael.boelen@cisofy.com> | 2019-07-14 16:12:25 +0300 |
commit | c074c81897d1b5c4ef60447971a8d25505681bd8 (patch) | |
tree | d51c784d1706f5a6dcad6bac47109bca1ae06a97 /include/functions | |
parent | ced78b52b0f757821b88d9a0c04bcf9a1f83b914 (diff) |
Initial work on GetReportData function
Diffstat (limited to 'include/functions')
-rw-r--r-- | include/functions | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/include/functions b/include/functions index 794abcc4..c8f689e7 100644 --- a/include/functions +++ b/include/functions @@ -52,6 +52,7 @@ # FileIsEmpty Check if a file is empty # FileIsReadable Check if a file is readable or directory accessible # GetHostID Retrieve an unique ID for this host +# GetReportData Request data from report # HasData Checks for data in variable # InsertSection Insert a section block # InsertPluginSection Insert a section block for plugins @@ -1176,6 +1177,47 @@ fi } + + ################################################################################ + # Name : GetReportData() + # Description : Request data from report + # Returns : Data (when matches were found) + # Exit code: True (0) or False (1) when search was cancelled + ################################################################################ + + GetReportData() { + KEY="" + VALID_CHARS="[:alnum:]/:;\-,\._\[\]\n " + if [ $# -eq 0 ]; then ExitFatal "No parameters provided to GetReportData() function"; fi + + while [ $# -ge 1 ]; do + case $1 in + --key) + shift + KEY="$1" + ;; + --valid-chars) + shift + VALID_CHARS="$1" + ;; + *) + ExitFatal "Invalid option provided to GetReportData() function" + ;; + esac + # Go to next parameter + shift + done + + if [ "${REPORTFILE}" = "/dev/null" ]; then + return 1 + else + ${AWKBINARY} -v pattern="^${KEY}" -F= '$1 ~ pattern {print $2}' ${REPORTFILE} | ${TRBINARY} -cd "${VALID_CHARS}" | ${TRBINARY} '[:blank:]' '__space__' + + fi + return 0 + } + + ################################################################################ # Name : HasData() # Description : Check for a filled variable |