mirror of
https://github.com/mtan93/Installomator.git
synced 2026-03-29 22:04:09 +01:00
Isaac logging improvements/fixes
Moved the variable declarations from `functions.sh` to `arguments.sh`. We need the argument parsing before setting the logging level and other variables.
This commit is contained in:
@@ -43,6 +43,38 @@ if [[ $label == "version" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# MARK: Logging
|
||||||
|
log_location="/private/var/log/Installomator.log"
|
||||||
|
|
||||||
|
# Check if we're in debug mode, if so then set logging to DEBUG, otherwise default to INFO
|
||||||
|
# if no log level is specified.
|
||||||
|
if [[ $DEBUG -ne 0 ]]; then
|
||||||
|
LOGGING=DEBUG
|
||||||
|
elif [[ -z $LOGGING ]]; then
|
||||||
|
LOGGING=INFO
|
||||||
|
datadogLoggingLevel=INFO
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Associate logging levels with a numerical value so that we are able to identify what
|
||||||
|
# should be removed. For example if the LOGGING=ERROR only printlog statements with the
|
||||||
|
# level REQ and ERROR will be displayed. LOGGING=DEBUG will show all printlog statements.
|
||||||
|
# If a printlog statement has no level set it's automatically assigned INFO.
|
||||||
|
|
||||||
|
declare -A levels=(DEBUG 0 INFO 1 WARN 2 ERROR 3 REQ 4)
|
||||||
|
|
||||||
|
# If we are able to detect an MDM URL (Jamf Pro) or another identifier for a customer/instance we grab it here, this is useful if we're centrally logging multiple MDM instances.
|
||||||
|
if [[ -f /Library/Preferences/com.jamfsoftware.jamf.plist ]]; then
|
||||||
|
mdmURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)
|
||||||
|
elif [[ -n "$MDMProfileName" ]]; then
|
||||||
|
mdmURL=$(sudo profiles show | grep -A3 "$MDMProfileName" | sed -n -e 's/^.*organization: //p')
|
||||||
|
else
|
||||||
|
mdmURL="Unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate a session key for this run, this is useful to idenify streams when we're centrally logging.
|
||||||
|
SESSION=$RANDOM
|
||||||
|
|
||||||
|
# Mark: START
|
||||||
printlog "################## Start Installomator v. $VERSION, date $VERSIONDATE" REQ
|
printlog "################## Start Installomator v. $VERSION, date $VERSIONDATE" REQ
|
||||||
printlog "################## Version: $VERSION" INFO
|
printlog "################## Version: $VERSION" INFO
|
||||||
printlog "################## Date: $VERSIONDATE" INFO
|
printlog "################## Date: $VERSIONDATE" INFO
|
||||||
|
|||||||
@@ -67,38 +67,6 @@ displaynotification() { # $1: message $2: title
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# MARK: Logging
|
|
||||||
log_location="/private/var/log/Installomator.log"
|
|
||||||
|
|
||||||
# Check if we're in debug mode, if so then set logging to DEBUG, otherwise default to INFO
|
|
||||||
# if no log level is specified.
|
|
||||||
if [[ $DEBUG -ne 0 ]]; then
|
|
||||||
LOGGING=DEBUG
|
|
||||||
elif [[ -z $LOGGING ]]; then
|
|
||||||
LOGGING=INFO
|
|
||||||
datadogLoggingLevel=INFO
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Associate logging levels with a numerical value so that we are able to identify what
|
|
||||||
# should be removed. For example if the LOGGING=ERROR only printlog statements with the
|
|
||||||
# level REQ and ERROR will be displayed. LOGGING=DEBUG will show all printlog statements.
|
|
||||||
# If a printlog statement has no level set it's automatically assigned INFO.
|
|
||||||
|
|
||||||
declare -A levels=(DEBUG 0 INFO 1 WARN 2 ERROR 3 REQ 4)
|
|
||||||
|
|
||||||
# If we are able to detect an MDM URL (Jamf Pro) or another identifier for a customer/instance we grab it here, this is useful if we're centrally logging multiple MDM instances.
|
|
||||||
if [[ -f /Library/Preferences/com.jamfsoftware.jamf.plist ]]; then
|
|
||||||
mdmURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url)
|
|
||||||
elif [[ -n "$MDMProfileName" ]]; then
|
|
||||||
mdmURL=$(sudo profiles show | grep -A3 "$MDMProfileName" | sed -n -e 's/^.*organization: //p')
|
|
||||||
else
|
|
||||||
mdmURL="Unknown"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate a session key for this run, this is useful to idenify streams when we're centrally logging.
|
|
||||||
SESSION=$RANDOM
|
|
||||||
|
|
||||||
printlog(){
|
printlog(){
|
||||||
[ -z "$2" ] && 2=INFO
|
[ -z "$2" ] && 2=INFO
|
||||||
log_message=$1
|
log_message=$1
|
||||||
@@ -106,11 +74,10 @@ printlog(){
|
|||||||
timestamp=$(date +%F\ %T)
|
timestamp=$(date +%F\ %T)
|
||||||
|
|
||||||
# Check to make sure that the log isn't the same as the last, if it is then don't log and increment a timer.
|
# Check to make sure that the log isn't the same as the last, if it is then don't log and increment a timer.
|
||||||
if [[ ${log_message} == ${previous_log_message} ]];then
|
if [[ ${log_message} == ${previous_log_message} ]]; then
|
||||||
let logrepeat=$logrepeat+1
|
let logrepeat=$logrepeat+1
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
previous_log_message=$log_message
|
previous_log_message=$log_message
|
||||||
|
|
||||||
# Once we finally stop getting duplicate logs output the number of times we got a duplicate.
|
# Once we finally stop getting duplicate logs output the number of times we got a duplicate.
|
||||||
@@ -123,7 +90,7 @@ printlog(){
|
|||||||
logrepeat=0
|
logrepeat=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the datadogAPI key value is set and our logging level is greaterthan or equal to our set level
|
# If the datadogAPI key value is set and our logging level is greater than or equal to our set level
|
||||||
# then post to Datadog's HTTPs endpoint.
|
# then post to Datadog's HTTPs endpoint.
|
||||||
if [[ -n $datadogAPI && ${levels[$log_priority]} -ge ${levels[$datadogLoggingLevel]} ]]; then
|
if [[ -n $datadogAPI && ${levels[$log_priority]} -ge ${levels[$datadogLoggingLevel]} ]]; then
|
||||||
while IFS= read -r logmessage; do
|
while IFS= read -r logmessage; do
|
||||||
@@ -143,8 +110,8 @@ printlog(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Used to remove dupplicate lines in large log output, for example from msupdate command
|
# Used to remove dupplicate lines in large log output,
|
||||||
# after it finishes running.
|
# for example from msupdate command after it finishes running.
|
||||||
deduplicatelogs() {
|
deduplicatelogs() {
|
||||||
loginput=${1:-"Log"}
|
loginput=${1:-"Log"}
|
||||||
logoutput=""
|
logoutput=""
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ IGNORE_DND_APPS=""
|
|||||||
#
|
#
|
||||||
### Logging
|
### Logging
|
||||||
# Logging behavior
|
# Logging behavior
|
||||||
LOGGING=""
|
LOGGING="INFO"
|
||||||
# options:
|
# options:
|
||||||
# - DEBUG Everything is logged
|
# - DEBUG Everything is logged
|
||||||
# - INFO (default) normal logging level
|
# - INFO (default) normal logging level
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ fi
|
|||||||
|
|
||||||
printlog "BLOCKING_PROCESS_ACTION=${BLOCKING_PROCESS_ACTION}"
|
printlog "BLOCKING_PROCESS_ACTION=${BLOCKING_PROCESS_ACTION}"
|
||||||
printlog "NOTIFY=${NOTIFY}"
|
printlog "NOTIFY=${NOTIFY}"
|
||||||
|
printlog "LOGGING=${LOGGING}"
|
||||||
|
|
||||||
# Finding LOGO to use in dialogs
|
# Finding LOGO to use in dialogs
|
||||||
case $LOGO in
|
case $LOGO in
|
||||||
@@ -191,7 +192,6 @@ else
|
|||||||
curlDownload=$(curl -v -fsL --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1)
|
curlDownload=$(curl -v -fsL --show-error ${curlOptions} "$downloadURL" -o "$archiveName" 2>&1)
|
||||||
curlDownloadStatus=$(echo $?)
|
curlDownloadStatus=$(echo $?)
|
||||||
deduplicatelogs "$curlDownload"
|
deduplicatelogs "$curlDownload"
|
||||||
printlog "curl output was: $logoutput" DEBUG
|
|
||||||
if [[ $curlDownloadStatus -ne 0 ]]; then
|
if [[ $curlDownloadStatus -ne 0 ]]; then
|
||||||
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
|
#if ! curl --location --fail --silent "$downloadURL" -o "$archiveName"; then
|
||||||
printlog "error downloading $downloadURL"
|
printlog "error downloading $downloadURL"
|
||||||
@@ -204,8 +204,9 @@ else
|
|||||||
displaynotification "$message" "Error installing $name" ERROR
|
displaynotification "$message" "Error installing $name" ERROR
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cleanupAndExit 2 "Error downloading $downloadURL error: $logoutput" ERROR
|
cleanupAndExit 2 "Error downloading $downloadURL error:\n$logoutput" ERROR
|
||||||
fi
|
fi
|
||||||
|
printlog "curl output was:\n$logoutput" DEBUG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# MARK: when user is logged in, and app is running, prompt user to quit app
|
# MARK: when user is logged in, and app is running, prompt user to quit app
|
||||||
|
|||||||
Reference in New Issue
Block a user