SHARE
TWEET

Untitled

a guest Jan 24th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. #
  3. #Get OS Release information and output it in prometheus text format to be ingested
  4. #
  5. #Currently supports:
  6. # - Any Linux Distro with /etc/os-release file (most modern Linux Distros)
  7.  
  8. #node_release_info
  9. node_release_info="node_release_info{} 0"
  10.  
  11. if [[ -f "/etc/os-release" ]]; then
  12.         #The following fields are not gathered as they do not provide any useful information
  13.         #ANSI_COLOR=,HOME_URL=, DOCUMENTATION_URL=, SUPPORT_URL=, BUG_REPORT_URL=, PRIVACY_POLICY_URL=,LOGO=
  14.  
  15.         #Read file into array
  16.         IFS=$'\r\n' GLOBIGNORE='*' command eval 'node_release=($(cat /etc/os-release))'
  17.  
  18.         #Regex fields for parsing file/array
  19.         NAME_REGEX="^NAME=.*"
  20.         VERSION_REGEX="^VERSION=.*"
  21.         ID_REGEX="^ID=.*"
  22.         ID_LIKE_REGEX="^ID_LIKE=.*"
  23.         VERSION_CODENAME_REGEX="^VERSION_CODENAME=.*"
  24.         VERSION_ID_REGEX="^VERSION_ID=.*"
  25.         PRETTY_NAME_REGEX="^PRETTY_NAME=.*"
  26.         CPE_NAME_REGEX="^CPE_NAME=.*"
  27.         BUILD_ID_REGEX="^BUILD_ID=.*"
  28.         VARIENT_REGEX="^VARIENT=.*"
  29.         VARIENT_ID_REGEX="^VARIENT_ID=.*"
  30.  
  31.         #Loop through file/array
  32.         for i in "${node_release[@]}"
  33.         do
  34.                 if [[ "$i" =~ $NAME_REGEX ]]; then
  35.                         IFS="=" read _ name <<< $i
  36.                         IFS='"' read _ name <<< $name
  37.                 elif [[ "$i" =~ $VERSION_REGEX ]]; then
  38.                         IFS="=" read _ version <<< $i
  39.                         IFS='"' read _ version <<< $version
  40.                 elif [[ "$i" =~ $ID_REGEX ]]; then
  41.                         IFS="=" read _ id <<< $i
  42.                         IFS='"' read _ id <<< $id
  43.                 elif [[ "$i" =~ $ID_LIKE_REGEX ]]; then
  44.                         IFS="=" read _ id_like <<< $i
  45.                         IFS='"' read _ id_like <<< $id_like
  46.                 elif [[ "$i" =~ $VERSION_CODENAME_REGEX ]]; then
  47.                         IFS="=" read _ version_codename <<< $i
  48.                         IFS='"' read _ version_codename <<< $version_codename
  49.                 elif [[ "$i" =~ $VERSION_ID_REGEX ]]; then
  50.                         IFS="=" read _ version_id <<< $i
  51.                         IFS='"' read _ version_id <<< $version_id
  52.                 elif [[ "$i" =~ $PRETTY_NAME_REGEX ]]; then
  53.                         IFS="=" read _ pretty_name <<< $i
  54.                         IFS='"' read _ pretty_name <<< $pretty_name
  55.                 elif [[ "$i" =~ $CPE_NAME_REGEX ]]; then
  56.                         IFS="=" read _ cpe_name <<< $i
  57.                         IFS='"' read _ cpe_name <<< $cpe_name
  58.                 elif [[ "$i" =~ $BUILD_ID_REGEX ]]; then
  59.                         IFS="=" read _ build_id <<< $i
  60.                         IFS='"' read _ build_id <<< $build_id
  61.                 elif [[ "$i" =~ $VARIENT_REGEX ]]; then
  62.                         IFS="=" read _ varient <<< $i
  63.                         IFS='"' read _ varient <<< $varient
  64.                 elif [[ "$i" =~ $VARIENT_ID_REGEX ]]; then
  65.                         IFS="=" read _ varient_id <<< $i
  66.                         IFS='"' read _ varient_id <<< $varient_id
  67.                 fi
  68.         done
  69.  
  70.         #build node release string
  71.         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"
  72. fi
  73.  
  74. echo "# HELP node_release_info Labeled OS information as provided by the OS specific release file."
  75. echo "# TYPE node_release_info gauge"
  76. echo $node_release_info
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top