how to get a daily kasten report in your email


Userlevel 3

good day, I wanted to have a daily report, and I wrote this code (warning: I’m a very poor coder, comment and messages are in italian).

When not using OpenShift, replace “oc” commands with “kubectl”

 

#!/bin/sh
#estraggo il nome del cluster
cluster_api_name=$(/usr/local/bin/oc config view --minify -o jsonpath='{.clusters[].name}')

#estraggo il nome dell'ultimo report e lo stampo in yaml
report_name=$(/usr/local/bin/oc get reports -n kasten-io --sort-by={metadata.creationTimestamp} | tail -n 1 | awk '/^scheduled/{print $1}')
/usr/local/bin/oc get reports $report_name -n kasten-io -o yaml > /tmp/lastk10report.yaml

#creo il corpo della mail
/usr/bin/echo -e "Ecco il report per $cluster_api_name:\n" > /tmp/lastk10notcompliant.txt
/usr/local/bin/yq '.spec' /tmp/lastk10report.yaml >> /tmp/lastk10notcompliant.txt
/usr/bin/echo -e "\nEd ecco lo stato delle applicazioni:\n " >> /tmp/lastk10notcompliant.txt
/usr/local/bin/yq '.results.compliance' /tmp/lastk10report.yaml >> /tmp/lastk10notcompliant.txt
/usr/bin/echo -e "\nVisualizzare l'allegato yaml per maggiori dettagli" >> /tmp/lastk10notcompliant.txt

#spedisco e allego lo yaml
/usr/bin/mailx -a /tmp/lastk10report.yaml -s "Rapporto quotidiano Kasten per il cluster $cluster_api_name" user@mail.it < /tmp/lastk10notcompliant.txt

This is a sample mail I’m recieving (after having put the script in cron)

Ecco il report per api-oscp01-xxxxxxx:6443:

 

reportTimestamp: "2023-01-12T06:00:00Z"

statsIntervalDays: 1

statsIntervalEndTimestamp: "2023-01-12T06:00:00Z"

statsIntervalStartTimestamp: "2023-01-11T06:00:00Z"

 

Ed ecco lo stato delle applicazioni:

 

applicationCount: 109

compliantCount: 27

nonCompliantCount: 3

someNonCompliantApps:

  - name: app1

  - name: app2

  - name: app3

unmanagedCount: 79

 

Visualizzare l'allegato yaml per maggiori dettagli


2 comments

Userlevel 7
Badge +22

I see you work on Openshift :) . Very nice. I just tried it on my K3S with adjustments to the script, looks nice thank you

#!/bin/sh
#extract the Cluster name
cluster_api_name=$(kubectl config view --minify -o jsonpath='{.clusters[].name}')

#extract the name of the last report in yaml
report_name=$(kubectl get reports -n kasten-io --sort-by={metadata.creationTimestamp} | tail -n 1 | awk '/^scheduled/{print $1}')
kubectl get reports $report_name -n kasten-io -o yaml > /tmp/lastk10report.yaml

#create the email body
/usr/bin/echo -e "Here is the Cluster Backup Report $cluster_api_name:\n" > /tmp/lastk10notcompliant.txt
/usr/local/bin/yq '.spec' /tmp/lastk10report.yaml >> /tmp/lastk10notcompliant.txt
/usr/bin/echo -e "\nStatus of the Applications:\n " >> /tmp/lastk10notcompliant.txt
/usr/local/bin/yq '.results.compliance' /tmp/lastk10report.yaml >> /tmp/lastk10notcompliant.txt
/usr/bin/echo -e "\nView the yaml file for more details" >> /tmp/lastk10notcompliant.txt

#Enclose and send the yaml file in an email
/usr/bin/mailx -a /tmp/lastk10report.yaml -s "Daily Kasten Backup email report for $cluster_api_name" user@hotmail.com < /tmp/lastk10notcompliant.txt

 

Userlevel 3

in the while, I have modified the script to write down meaningful infos in the mail body for DR sites too. You can find it here if interested:

 

https://github.com/tinto1970/report4k10/blob/main/report4k10

Comment