Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- #Get OS Release information and output it in prometheus text format to be ingested
- #
- #Currently supports:
- # - Any Linux Distro with /etc/os-release file (most modern Linux Distros)
- #node_release_info
- node_release_info="node_release_info{} 0"
- if [[ -f "/etc/os-release" ]]; then
- #The following fields are not gathered as they do not provide any useful information
- #ANSI_COLOR=,HOME_URL=, DOCUMENTATION_URL=, SUPPORT_URL=, BUG_REPORT_URL=, PRIVACY_POLICY_URL=,LOGO=
- #Read file into array
- IFS=$'\r\n' GLOBIGNORE='*' command eval 'node_release=($(cat /etc/os-release))'
- #Regex fields for parsing file/array
- NAME_REGEX="^NAME=.*"
- VERSION_REGEX="^VERSION=.*"
- ID_REGEX="^ID=.*"
- ID_LIKE_REGEX="^ID_LIKE=.*"
- VERSION_CODENAME_REGEX="^VERSION_CODENAME=.*"
- VERSION_ID_REGEX="^VERSION_ID=.*"
- PRETTY_NAME_REGEX="^PRETTY_NAME=.*"
- CPE_NAME_REGEX="^CPE_NAME=.*"
- BUILD_ID_REGEX="^BUILD_ID=.*"
- VARIENT_REGEX="^VARIENT=.*"
- VARIENT_ID_REGEX="^VARIENT_ID=.*"
- #Loop through file/array
- for i in "${node_release[@]}"
- do
- if [[ "$i" =~ $NAME_REGEX ]]; then
- IFS="=" read _ name <<< $i
- IFS='"' read _ name <<< $name
- elif [[ "$i" =~ $VERSION_REGEX ]]; then
- IFS="=" read _ version <<< $i
- IFS='"' read _ version <<< $version
- elif [[ "$i" =~ $ID_REGEX ]]; then
- IFS="=" read _ id <<< $i
- IFS='"' read _ id <<< $id
- elif [[ "$i" =~ $ID_LIKE_REGEX ]]; then
- IFS="=" read _ id_like <<< $i
- IFS='"' read _ id_like <<< $id_like
- elif [[ "$i" =~ $VERSION_CODENAME_REGEX ]]; then
- IFS="=" read _ version_codename <<< $i
- IFS='"' read _ version_codename <<< $version_codename
- elif [[ "$i" =~ $VERSION_ID_REGEX ]]; then
- IFS="=" read _ version_id <<< $i
- IFS='"' read _ version_id <<< $version_id
- elif [[ "$i" =~ $PRETTY_NAME_REGEX ]]; then
- IFS="=" read _ pretty_name <<< $i
- IFS='"' read _ pretty_name <<< $pretty_name
- elif [[ "$i" =~ $CPE_NAME_REGEX ]]; then
- IFS="=" read _ cpe_name <<< $i
- IFS='"' read _ cpe_name <<< $cpe_name
- elif [[ "$i" =~ $BUILD_ID_REGEX ]]; then
- IFS="=" read _ build_id <<< $i
- IFS='"' read _ build_id <<< $build_id
- elif [[ "$i" =~ $VARIENT_REGEX ]]; then
- IFS="=" read _ varient <<< $i
- IFS='"' read _ varient <<< $varient
- elif [[ "$i" =~ $VARIENT_ID_REGEX ]]; then
- IFS="=" read _ varient_id <<< $i
- IFS='"' read _ varient_id <<< $varient_id
- fi
- done
- #build node release string
- node_release_info="node_release_info{name=\"${name}\",version=\"${version}\",id=\"${id}\",id_like=\"${id_like}\",version_codename=\"${version_codename}\",version_id=\"${version_id}\",pretty_name=\"${pretty_name}\",cpe_name=\"${cpe_name}\",build_id=\"${build_id}\",varient=\"${varient}\",varient_id=\"${varient_id}\"} 1"
- fi
- echo "# HELP node_release_info Labeled OS information as provided by the OS specific release file."
- echo "# TYPE node_release_info gauge"
- echo $node_release_info
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement