Giter Site home page Giter Site logo

Comments (6)

Jacksaur avatar Jacksaur commented on May 27, 2024 1

Ah, christ. That's embarassing. I forgot that the main script handled regctl automatically.
dc_brief outputs exactly as I desire with your suggested edits. Thanks for putting up with me fellas.

from dockcheck.

mag37 avatar mag37 commented on May 27, 2024

I'm not entirely sure what your wished output should look like. But in the extras directory there's a file called dc_brief.sh, with some modifications that might give you the result you need?

I'll gladly try to help you out.

Maybe this is a start? Wont show progress, just the list of containers with updates available when done.

#!/usr/bin/env bash
### If not in PATH, set full path. Else just "regctl"
regbin="regctl"
### options to allow exclude:
while getopts "e:" options; do
  case "${options}" in
    e) Exclude=${OPTARG} ;;
    *) exit 0 ;;
  esac
done
shift "$((OPTIND-1))"
### Create array of excludes
IFS=',' read -r -a Excludes <<< "$Exclude" ; unset IFS
SearchName="$1"
for i in $(docker ps --filter "name=$SearchName" --format '{{.Names}}') ; do
  for e in "${Excludes[@]}" ; do [[ "$i" == "$e" ]] && continue 2 ; done
  RepoUrl=$(docker inspect "$i" --format='{{.Config.Image}}')
  LocalHash=$(docker image inspect "$RepoUrl" --format '{{.RepoDigests}}')
  ### Checking for errors while setting the variable:
  if RegHash=$($regbin image digest --list "$RepoUrl" 2>/dev/null) ; then
    if [[ "$LocalHash" = *"$RegHash"* ]] ; then NoUpdates+=("$i"); else GotUpdates+=("$i"); fi
  else
    GotErrors+=("$i")
  fi
done
### Sort arrays alphabetically
IFS=$'\n'
NoUpdates=($(sort <<<"${NoUpdates[*]}"))
GotUpdates=($(sort <<<"${GotUpdates[*]}"))
GotErrors=($(sort <<<"${GotErrors[*]}"))
unset IFS

if [[ -n ${GotUpdates[*]} ]] ; then
   printf "%s\n" "${GotUpdates[@]}"
fi

Or you could write them to a file if you'd like, just replace the last bit printf "%s\n" "${GotUpdates[@]}" with printf "%s\n" "${GotUpdates[@]}" > FileName.txt

from dockcheck.

yoyoma2 avatar yoyoma2 commented on May 27, 2024

Couldn't he use notify_generic.sh and tweak it to print exactly what he wants in an easy to grep form?

from dockcheck.

Jacksaur avatar Jacksaur commented on May 27, 2024

In truth, I didn't notice the Extras folder entirely :V
I'm not extremely well versed in Linux still, so apologies for the vagueness of my request. I use Telegraf to collect metrics which it then pushes to my Grafana dashboard. It has an option to run scripts and send their output as metrics, and I'd only need the amount of containers with updates available for what I want to display. So an ideal output would literally just be the number of containers with updates available, and nothing else at all, for easier parsing.

DC_Brief seems like it'd be the easiest option for this, but it doesn't seem to work on my system. Just outputs the containers that cannot update due to errors, and nothing after that. I tried your provided script as well, but that didn't output anything at all.

Renaming notify_generic to just notify.sh doesn't seem to apply it properly for me either, it never prints anything more than Dockcheck does.

from dockcheck.

yoyoma2 avatar yoyoma2 commented on May 27, 2024

Renaming notify_generic to just notify.sh doesn't seem to apply it properly for me either, it never prints anything more than Dockcheck does.

Don't forget the -i to turn on information notification. If you have no outdated containers the notification doesn't get called at all.

sudo dockcheck.sh -n -s -i

Generic notification addon:
The following 1 docker containers on TestHost need to be updated:
pihole-nightly

I tweaked the print statement to include the number of outdated containers as follows. If you improve the notify_generic.sh file the dev may merge your changes.
printf "\nThe following ${#Updates[@]} docker containers on %s need to be updated:\n%s\n" "$FromHost" "$UpdToString"

from dockcheck.

mag37 avatar mag37 commented on May 27, 2024

DC_Brief seems like it'd be the easiest option for this, but it doesn't seem to work on my system. Just outputs the containers that cannot update due to errors, and nothing after that. I tried your provided script as well, but that didn't output anything at all.

Well that sounds like it's probably due to not editing the regbin="regctl" line. Which has to correspond to the regctl-binary - either by full path, alias or that the binary is in placed $PATH
So for example if you've pasted the text above to a script called dcb.sh and placed the regctl binary in the same path, just edit the script to say regbin=./regctl or preferably full path /path/to/file/regctl.

Renaming notify_generic to just notify.sh doesn't seem to apply it properly for me either, it never prints anything more than Dockcheck does.

Odd - even when you run the script with the flags -ni as @yoyoma2 suggested?

Also if I understand you correctly you'd just like the number of containers as a plain number as the result?
Like

./dcb.sh
5

If you use the notify.sh you would still get the output of the script, so that's not very clean. But could be done with just pasting this code in a new file called notify.sh and running the regular script with -ni flags

send_notification() {
  Updates=("$@")
  UpdCount="${#Updates[@]}"
  printf "\n%s\n" "$UpdCount"

But to just get the number as an output, I'd use what I pasted above (a modification of the dc_brief.sh) and just add a #-sign to the array printed.
So on the 2nd to last row it would be: printf "%s\n" "${#GotUpdates[@]}"
(after you've sorted the regbin-bit).

from dockcheck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.