Start a Conversation

Unsolved

This post is more than 5 years old

2011

December 6th, 2013 11:00

A different way to create and email avamar reports.

A different way  to create and email avamar reports.

Hello All,

Reporting in avamar always in my nightmares. I usually use avamar cli mccli and some other tools on avamar. But an automated emaling always has been problem for me . Today i tried somtehing else and wolla it worked perfectly .Now i want to share this with you.

First we need some tools for this . I belive that almost all of us familiar with them.

Here we go ,

  1. Windows Server ( I did this in my customer env. And they mostly have windows. I used win 2008 server)
  2. We need winscp ( If you are not already  have)
  3. Winrar (again if you are not already have)

First i connect avamar with winscp. Then ,

I save the session information ,1.png

Warning : This action may have security issues. So do it with your own risk.

After that i create some scripts . I will try to explain them below. Basically i create 3 windows batch you can merge them or split whatever you want.

  1. My first script is created with winscp commands,

In first line i am changing folder to be able to run winscp commands,

cd "c:\Program Files (x86)\WinSCP"

winscp /console /command "open avamar" "call /usr/local/avamar/bin/./replcnt.sh > /home/Reports/replication_log.txt"

In above line winscp conencts the avamar with saved user name and password. After connected it runs “call”command and the replication report script.

winscp /console /command "open avamar" "call capacity.sh > /home/Reports/capacity_log.txt" "exit"

I added the the what ever i need.

winscp /console /command "open avamar" "call status.dpn > /home/Reports/status_dpn.txt" "exit"

winscp /console /command "open avamar" "call dpnctl status > /home/Reports/dpnctl_status.txt" "exit"

winscp /console /command "open avamar" "cd /home/Reports" "get *.txt E:\Reports\ " "exit"

and the last line is connecting avamar and goes to my report folder and copying all txt files to my windows server.

And here is the output files

2.png

3.png

Ok good now we have our reports on our windows server what is next ?

I need to keep them with date format so here is second batch . It renames our files with date format.

set HR=%time:~0,2%

    set HR=%Hr: =0%

    set HR=%HR: =%

    rename e:\Reports\capacity_log.txt capacity_log_results_%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%.txt

rename e:\Reports\dpnctl_status.txt dpnctl_results_%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%.txt

    rename e:\Reports\status_dpn.txt status_results_%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%.txt

    rename e:\Reports\replication_log.txt replication_log_results_%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%.txt

And here is the output.

4.png

Now we have reports that renamed with dates.

And this time i need to zipped these files. This time i use winrar. This is the third batch file.

First i set home env. For winrar then change the directory to my reports directory

set path="C:\Program Files\WinRAR\";%path%

cd e:\Reports

rar a -r e:\Reports\reports.rar E:\reports\*.txt e:\Reports\Reports.rar

5.png

Its all done . Now we just need to schedule these batch files with windows task scheduler.

6.png

And email them again with task scheduler.

7.png

And it works .

8.png

I hope it is usefull for everybody who uses Avamar. Have nice works.

Ahmet Keçeciler

215 Posts

December 9th, 2013 13:00

This is great info. appreciate the detail.

However, why could you not have performed these various commands and renaming etc. on the Utility node then email them directly from it?

The process could be scheduled using the Linux CRON.

This would eliminate the need to interact with a Windows host but if for some reason they are actually needed on Windows a single winscp could be used to retrieve it.

54 Posts

December 10th, 2013 11:00

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 "

    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)

2K Posts

December 10th, 2013 12:00

why could you not have performed these various commands and renaming etc. on the Utility node then email them directly from it?

As an intermediate option, have you looked into "plink" or its more GUI-friendly cousin TortoisePlink.exe? The plink utility can be used to run SSH commands on remote hosts and it's a lot more lightweight than WinSCP.

For the security conscious, I would recommend setting up passwordless authentication from the Windows host to the utility node. While this is not officially supported, it does work and it's far more secure than saving login credentials. This does require you to keep the private key secured.

December 12th, 2013 01:00

Hello,

First off all thank you for your replies .

I actually did this for my customers who are not familiar with linux systems. And all af them want to control this system without trying to use avamar cli or linux bash. So why i did it with using windows instead of linux. Also Other comments are absuletly true about saving connection credantials. Our customers in my country are needs diffirent things, they want to some reports with email but but dont want struggle and learn new things. So this is my easiest way to do this. With this way they can control scripts schedules without interacting with avamar. Because of that i renamed the article " Different Way ..." I know there is a alot of way to accomplish that what we want ... Also my best concept is K.I.S ( Keep It Simple)

No Events found!

Top