Skip to content

Instantly share code, notes, and snippets.

@leighb2282
Created September 11, 2023 04:36
Show Gist options
  • Select an option

  • Save leighb2282/5935ad14011a1e293f880e7725cee750 to your computer and use it in GitHub Desktop.

Select an option

Save leighb2282/5935ad14011a1e293f880e7725cee750 to your computer and use it in GitHub Desktop.
script to email ops a list of nodes needing attention
#!/bin/bash
# Script to mail ops@ regarding in production, active but in maintenance nodes
apilink=""
recip=""
dated=$(date '+%m-%d-%y')
data_cache="/home/monitoring/scripts/mailer/data"
#grab data
node_data=$(curl -ks -d "expression=%26intersect%28@nodes.node_production.1,@nodes.node_status.active,@nodes.node_maintenance.1%29" $apilink | sed 's/node/"\n"/g; s/"//g; s/}//g; s/]//g' | awk -F'[:|,]' '{print $2}' | grep bitgravity)
node_count=$(echo $node_data | wc -w)
echo $node_data > $data_cache/$dated.tmp
sed -e 's/ /\n/g' $data_cache/$dated.tmp > $data_cache/$dated
rm $data_cache/$dated.tmp
datedp=$(ls -lt $data_cache | grep -v "$dated\|total\|mailer\|nodes\|diff" | head -1| awk '{print $9}')
diff $data_cache/$datedp $data_cache/$dated > $data_cache/diffs
grep '<' $data_cache/diffs > $data_cache/nodes_removed
grep '>' $data_cache/diffs > $data_cache/nodes_added
echo "Nodes Removed from list since $datedp" > $data_cache/mailer_$dated
cat "$data_cache/nodes_removed" >> $data_cache/mailer_$dated
echo "" >> $data_cache/mailer_$dated
echo "Nodes Added to list since $datedp" >> $data_cache/mailer_$dated
cat "$data_cache/nodes_added" >> $data_cache/mailer_$dated
echo "" >> $data_cache/mailer_$dated
echo "Todays ($dated) Full Node list" >> $data_cache/mailer_$dated
cat "$data_cache/$dated" >> $data_cache/mailer_$dated
subj="$node_count In-Production Active nodes in Maintenance on $dated"
cat "$data_cache/mailer_$dated" | mail -s "$subj" "$recip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment