iop2go
1 Nickel

Re: A different way to create and email avamar reports.

Interesting thread for sure, as reports ARE a nightmare as soon as you need something a little custom.

The way I do it is, I wrote a script that interrogate the postgress database (you'll need to be creative with SQL queries here), and email the results to the concerned administrators.

Here is a prototype in python that fetch MSSQL plugin backups exceptions. Warning, this is very ALPHA, non-optimized and ugly code, but hopefully you'll get the idea:

#!/usr/bin/python

import pdb

import psycopg2

from smtplib import SMTP

import datetime

#pdb.set_trace()

def sendreport(message_text):

    smtp = SMTP()

    smtp.connect('smtp.server.local', 25)

    from_addr = "Avamar grid <xxxx@.local>"

    to_addr = "admin@local.net"

    subj = "Avamar SQL Backup Exceptions"

    date = datetime.datetime.now().strftime( "%d/%m/%Y %H:%M" )

    msg = "From: %s\nTo: %s\nSubject: %s\nDate: %s\n\n%s" % ( from_addr, to_addr, subj, date, message_text )

    smtp.sendmail(from_addr, to_addr, msg)

    smtp.quit()

try:

        conn = psycopg2.connect('host=avamar_utility_node_ip port=5555 dbname=mcdb user=viewuser password=viewuser1')

        print "Connected to Database"

except:

        print "No Connection"

#cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)

cur = conn.cursor()

#pdb.set_trace()

try:

    cur.execute("select client_name,domain,recorded_date,plugin_name,status_code FROM v_activities WHERE recorded_date_time > current_timestamp - interval '24 hours' AND plugin_name='Windows SQL'")

    rows = cur.fetchall()

    message_text = '\nServeur\t\t\t\tResultat'

    message_text += '\n--------\t\t\t\t\t--------'

    for row in rows:

        if (row[4] == 30000):

            result='Completed with succes.'

        elif (row[4] == 30005):

            result='Completed with exceptions.'

        elif (row[4] == 30999):

            result='Backup in error!'

        print "Serveur: " + row[0] + "  Resultat: " + result

        message_text += "\n" + row[0] + "\t\t" + result

    print "msg: \n" + message_text

except:

        print "Not Working"

sendreport(message_text)

0 Kudos