|
This sample script code is provided in <Report Tool installation folder>\cucmreport.bat. This script implements the following features:
•Generate (nightly) CUCM configuration reports
•Copy the files
•Send a notification email if something fails.
•Send a successful notification email. Because the reports can be quite large, attaching the generated file is not recommended.
REM UPLINX Report Tool - Example 1.2 - Generate CUCM Report with email REM PLEASE NOTE THAT THIS SCRIPT IS NOT SUPPORTED and provided as is. We provide custom scripting - please contact us with your detailed specification to provide a quote. REM Please see user guide > Example 1.2 how to use this script
@echo off setlocal EnableDelayedExpansion set starttime=%DATE% %TIME% echo !starttime!
REM Set here your MAIL SERVER details - if you leave this empty no email notification will be sent set mailserver="" set mailuser=user@domain.com set mailpassword=passw0rd set mailto=alerts@domain.com set mailfrom=script@domain.com
REM Set here your CUCM details - set ip empty to "" to not generate this report set cucm_ip="10.5.1.60" set cucm_user="admin" set cucm_pswd="bla,123"
REM Set here the report title ie name of the CUCM cluster set reporttitle=Sydney
REM Please note - any settings not available or not set in this script will be taken from the specified Report Tool Profile - as there is no profile used here REM the default profile is used REM *** MUST DO: No timestamp option in profile (Start GUI, tick No timestamp,close application) REM Disable Word, CHM, Excel generation unless required
REM set the web root folder here - this should match the virtual folder of IIS etc set webroot=C:\inetpub\wwwroot\test echo webroot=!webroot! REM this is a temp folder to generate the report before publishing to web server set outpath=C:\mytemp\reports echo outpath=!outpath! REM This is a file to store the last report file name for incremental comparison of reports set fnlastreport=lastreport.txt REM This is a file to store the pre - last report file name for incremental comparison of reports set fnlastlastreport=lastlastreport.txt REM Create the outpath folder if it does not exist if not exist !outpath!\NUL md !outpath!
set datestamp=%date:~-4,4%%date:~-7,2%%date:~-10,2% echo datestamp=!datestamp!
set timestamp=%time:~0,2%%time:~3,2%%time:~6,2% if "%timestamp:~0,1%" == " " set timestamp=0%timestamp:~1,5% echo timestamp=%timestamp%
echo reporttitle=%reporttitle% REM - This is always the same - do not change set reportdir=!outpath!\Report_For_%reporttitle% echo reportdir=!reportdir!
REM change to home directory of Report Tool - this might be different if non-standard install set binpath="C:\Program Files (x86)\UPLINX Report Tool\" REM delete any files in the report folder rd /S /Q !outpath! md !outpath!
:CUCM if [%cucm_ip%] ==[""] ( echo No CUCM IP address is set - ommitting CUCM report generation goto:eof ) Echo *** GENERATE CUCM REPORT at %DATE% %TIME% *** REM change the IP user and password of CUCM %binpath%ReportTool.exe /outpath !outpath! /cucm_ip %cucm_ip% /cucm_user %cucm_user% /cucm_password %cucm_pswd% /cucm_report %reporttitle% set endtime=%DATE% %TIME% echo Errorlevel is %errorlevel% set reporterr=%errorlevel% echo reporterr is %reporterr% if not %reporterr%==0 ( echo Something went wrong set body="CUCM report FAILED from !starttime! to !endtime!" if NOT [%mailserver%] ==[""] ( blat.exe -to %mailto% -f %mailfrom% -server %mailserver% -u %mailuser% -pw %mailpassword% -subject "CUCM report FAILED from !starttime! to !endtime!" -body !body! ) exit /b 1 goto:eof )
echo *** CUCM report is good REM COPY the output folder to web server echo reportdir= !reportdir! set CUCMreportdirHTML=!reportdir!\CUCM\html echo CUCMreportdirHTML=!CUCMreportdirHTML! set CUCMreportFileHTML=!CUCMreportdirHTML!\CUCM_Report_%reporttitle%.htm echo CUCMreportFileHTML=!CUCMreportFileHTML! set destfolder=!webroot! echo destfolder=!destfolder! set destfile=!destfolder!\CUCM_Report_%reporttitle%_!datestamp!_!timestamp!.htm echo destfile=!destfile!
Rem Copy the tree image icons to webroot xcopy !CUCMreportdirHTML!\icons\*.* !webroot!\icons\ /S /Y /Q REM copy the report file to the webroot with new timestamps IF EXIST !CUCMreportFileHTML! ( copy !CUCMreportFileHTML! !destfile! /Y ) else ( echo Expecting Generated file with name !CUCMreportFileHTML! but NOT FOUND echo Have you disabled the time stamps in Report Tool required goto:eof )
REM If there was a lastreport generated before - save it in last last report file IF EXIST !fnlastreport! ( copy !fnlastreport! !fnlastlastreport! ) REM Write the report name to the textfile for next comparison echo !destfile!>!fnlastreport!
if NOT [%mailserver%] ==[""] ( Echo Send the email notification - This requires BLAT.exe in path set body="CUCM report generated successfully from !starttime! to !endtime! <BR> Direct Link: <a href="http://localhost/test/CUCM_Report_%reporttitle%_!datestamp!_!timestamp!.htm">Latest</a>" blat.exe -to %mailto% -f %mailfrom% -server %mailserver% -u %mailuser% -pw %mailpassword% -subject "CUCM report generated from !starttime! to !endtime!" -body !body! )
|
|