carstein.seeberg

NAS Script: Generate PDF from QoS report and send email with PDF attachment

Discussion created by carstein.seeberg on Sep 13, 2008
Latest reply on Apr 15, 2011 by chris.naude

This package contains a set of utilities nas-bin.zip (that also can be downloaded - www.blat.net and www.verypdf.com ) that converts html-files to pdf and the CLI-mailer 'blat'.  This zip file should be unzipped and recide in nas/bin, please note that the htmltools is a demo version (hence the watermark).  The following script will take a qos report and convert it to pdf and send it with blat.  I have used this in some scripts that generates an email based on certain trigger situations.

Enjoy,

-- Sitespecific Configuration
report_dir = "C:\\program files\\nimbus\\probes\\slm\\report_engine\\Reports"
temp_dir   = "\\temp"
mail_server= "odin.nimsoft.no"       -- change this !!
mail_sender= "emailgtw@nimsoft.no"   -- change this !!

--
-- Note: the qos_report_path "Carsteins QoS Reports/Network Reports/nimsoft-gtw/lastday.html"
--          maps to the actual filepath: C:\Program Files\NimBUS\probes\slm\report_engine\Reports\Carsteins QoS Reports\Network Reports\nimsoft-gtw\lastday.html
--
-- MailQoSReportAsPDF (recipient,subject,body,qos_report_path)
--
function MailQoSReportAsPDF (mail_recipient, mail_subject, mail_body, qos_report_path)
   local path, tmp, mbody, tpdf

   if mail_recipient == nil or mail_subject == nil or mail_body == nil or qos_report_path == nil then
      error "MailQoSReportAsPDF: expecting recipient, subject, body and qos-report-path."
   end

   now   = timestamp.now()
   mbody = temp_dir .. "\\mbdy" .. now ..".tmp"
   tpdf  = temp_dir .. "\\mbdy" .. now ..".pdf"
 
   file.create (mbody, mail_body)

   -- Send as email using 'blat' instead of using action.email (cannot attach documents)
   mailer = "bin\\blat " .. mbody .." -server "..mail_server.." -f "..mail_sender.." -to "..mail_recipient.." -subject \""..mail_subject.."\""

   path = report_dir .. "\\" .. string.gsub(qos_report_path,"/","\\")

   -- Generate pdf-file from HTML
   action.command ("bin\\htmltools \""..path.."\" "..tpdf)
   action.command (mailer .. " -attach " .. tpdf)
   -- cleanup temporary files
   file.delete (mbody)
   file.delete (tpdf)

   print ("Mail is generated and sent...")
end

MailQoSReportAsPDF ("case@nimsoft.no","Testmail from case","This is my body","Carsteins QoS Reports/Network Reports/nimsoft-gtw/lastday.html")


Outcomes