cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Daily report - add datetime to report name

hiep_bui
Participant

Hello,

We are using NAM 2018 and we have some scheduled reports that send pdf reports to some users on daily basis.

Is there a way to add datetime to report name or file name?

Thanks,

Hiep


3 REPLIES 3

I am very interested in that as well. I am not yet familiar with improvements in that area in NAM18, but for what it's worth, we have set up extended reporting handling through the config of the tasks scheduling mechanism (tasks-nnn -*.xml, e.g. tasks-500-SchedRpt-Synth.xml). See: https://www.dynatrace.com/support/doc/nam/cas-and...

In the schedule definition we let the CAS:

  1. Generate (save) a report on a scheduled day and time
  2. Mail the report
  3. Run a script, that saves the report in a folder on a central share to safe keep the reports for historical and reference purposes (folder in \<Path-to-Share\<reporting folder>\<application>\<year>\<month>)

Using the script function you could add functionality that is not covered by the normal engine, like file (name) manipulation, storing on share or ftp server.

If necessary, happy to share some examples.


hiep_bui
Participant

Hello Frans,

Could you share your examples?

What I did to modify report file name (file name only, not the report name) and send reports:

- Schedule a task with Dynatrace (tasks-nn-....) to generate report and save it to report server.

- Schedule a task with Windows Task scheduler to modify the report file name and send it. (I used a powershell script to send email)

Thanks,

Hiep.



Hi Hiep,



The task to run the script that changes the file name and send it, could also be directly ran from the tasks-definition. Benefit, you can re-run the task from CAS task scheduling mechanism.


The tasks config we have is somewhat similar to what is found in the link above.




A Monthly report example, for application Test:



<?xml version="1.0" encoding="utf-8"?>
<tasks>
<!--
Test application
-->
<task ID="MO_PdfMail_Test" name="MonthlyOverview-PdfMail_Test" periodType="MONTH" period="1" timeLine="SERVER" offsetTime="00:04:05" timeout="00:10">
<command ID="1">
<class>adlex.delta.scheduler.command.SaveReportCommand</class>
<param>/LSSaveAs?lsAction=Saveas&format=pdf&lsEntryName=Monthly+Overview+Application+Service+Management+-+Scheduled&FILTER_bgParent=Test</param>
<param>{delta.root}{file.separator}SchedRpt{file.separator}Monthly_Transaction_Overview_Test.pdf</param>
</command>
<command ID="2">
<class>adlex.delta.scheduler.command.SMTPCommand</class>
<param>{delta.root}{file.separator}SchedRpt{file.separator}Monthly_Transaction_Overview_Test.pdf</param>
<param>dl-testers@test.com, reports@test.com</param>
<param>Monthly Report Test</param>
<param>text/plain</param>
</command>
<command ID="3">
<class>adlex.delta.scheduler.command.ShellCommand</class>
<param>cmd.exe</param>
<param>/q /c</param>
<param>D:\Scripts\PDF-Share.cmd</param>
<param>Test</param>
</command>
</task>


In the above example the task has 3 command sections:



  1. Save the report

  2. Mail the report

  3. Run a CMD script to place the report onto a central share



    In your case the 2nd command probably should be omitted.




    The 3rd command should call your script (CMD or Powershell) that saves the report with the name you want (including the day/date), and mail it.





Example of our PDF-Share.cmd script below.


It stores the monthly report file on a local folder on the server, and on a central share.


Data manipulations are on the folder names, but ought to be possible on filename as well.






REM @ECHO OFF
REM Move/copy the pdf documents created from the CAS server
REM to a share where users can access the PDF-documents.
REM
REM Parameter is the first characters of the files to be transferred
REM i.e. Month for all Month_*.pdf files
REM
ECHO Starting
DATE /T
Set SrcSrv=hostname.test.com
set SrcDir="D:\Program Files\Dynatrace\CAS\SchedRpt"
set DestDir="D:\DATA\APM\REPORTS"
set DestDirCUSTOMER="X:\MCS"
set LogDir=%DestDir%
set ScriptDir="D:\Scripts\BatchCMD"
REM Extract MonthYear from date
REM
rem echo.Date : %date%
rem echo.Weekday: %date:~0,3%
rem echo.Month : %date:~4,2%
rem echo.Day : %date:~7,2%
rem echo.Year : %date:~10,4%
set MonthHiCheck=%date:~4,1%
if %MonthHiCheck% equ 1 (
set Month=%date:~4,2%
) else (
set Month=%date:~5,1%
)
set Year=%date:~10,4%
set /a Year = %Year% + 0
set /a Month = %Month% + 0
if %Month% equ 1 (
set /a Year = %Year% - 1
set /a Month = 12
) else (
set /a Year = %Year% - 0
set /a Month = %Month% - 1
)
for /f "tokens=%Month%" %%1 in (
"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do (
set MonthAlpha=%%1
)
set MonthA=0%Month%
if %Month% equ 10 (
set MonthA=10
)
if %Month% equ 11 (
set MonthA=11
)
if %Month% equ 12 (
set MonthA=12
)
REM Replace Space in ApplicationName by _
REM Replace ( or ) in ApplicationName by <nothing> in ParamMSC
set NoQuote=%1%
set ParamAppl=%NoQuote:"=%
set ParamMSC=%ParamAppl: =_%
set ParamMSC=%ParamMSC:(=%
set ParamMSC=%ParamMSC:)=%
ECHO %ParamMSC% %ParamAppl% %Month% %Year%
if dummy equ dummy%ParamMSC% goto exit
REM if %COMPUTERNAME%==notonthisserver goto exit
NET USE X: \\test.com\shared\reports\APM /user:cas_user@test.com S0mePassW0rd!
REM Set ReportDirectory
set DestDir=%DestDir%\%ParamMSC%
ECHO Checking Report Dir %DestDir%
if NOT EXIST %DestDir% (
ECHO Making it..
mkdir %DestDir%
)
pushd %DestDir%
set DestDir=%DestDir%\%Year%-%MonthAlpha%
ECHO Checking Report Dir %DestDir%
if NOT EXIST %DestDir% (
ECHO Making it...
mkdir %DestDir%
)
popd
REM Set ReportDirectory
set DestDirCUSTOMER=%DestDirCUSTOMER%\%ParamMSC%
ECHO Checking Report Dir %DestDirCUSTOMER%
if NOT EXIST %DestDirCUSTOMER% (
ECHO Making it..
mkdir %DestDirCUSTOMER%
)
pushd %DestDirCUSTOMER%
set DestDirCUSTOMER=%DestDirCUSTOMER%\%Year%-%MonthAlpha%
ECHO Checking Report Dir %DestDirCUSTOMER%
if NOT EXIST %DestDirCUSTOMER% (
ECHO Making it...
mkdir %DestDirCUSTOMER%
)
popd
REM Copy file to share
pushd %LogDir%
echo Copy %LogDir% %SrcDir% %DestDir% %ParamMSC% %ParamAppl% %ScriptDir% >> C:\temp\%Year%.log
echo Parameters %DestDir% %ParamMSC% > %Year%-%MonthAlpha%-%ParamMSC%.log
REM Place "'s around ParamAppl
robocopy %SrcDir% %DestDir% "*%ParamAppl%*.pdf" /copy:DAT /r:3 /w:3 >> %Year%-%MonthAlpha%-%ParamMSC%.log
robocopy %SrcDir% %DestDirCUSTOMER% "*%ParamAppl%*.pdf" /copy:DAT /r:3 /w:3 >> C:\temp\%Year%.log
popd
net use X: /delete
:exit
echo Exitted...
ECHO ON