Author Topic: SOLVED: Generate reports and send them by email  (Read 2929 times)

dionv

  • Newbie
  • *
  • Posts: 16
  • Karma: 2
    • View Profile
SOLVED: Generate reports and send them by email
« on: April 11, 2009, 05:17:14 »
Hello,

  I need to automatically generate custom report and also general report (via crontab ?), convert them in pdf and send them by email.
I had a look on the forum and also in the documentation but found nothing ...
Any idea ?

Best regards,

Didier Chabanol
http://www.ives.fr

Took some digging around, but looks like one way that could work is with the htmldoc package, which is generally available through most linux distributions.

With it, you could do something like:

Code: [Select]
wget -O - -p "http://yourserver.com:8080/queuemetrics/qm_rep.do?user=robot&pass=robotpass&queues=q1&period=t1" | htmldoc --webpage --size 11x8.5in -f report.pdf -

Note the dash (-) after the -O (that's O like Oscar, not 0 like zero), and the ending dash by itself, these are required to work properly. The first one tells wget to send its output to stdout, the final one tells htmldoc to read from stdin.

Since the report pages are kind of wide, I used htmldoc's "size" option to set the output to US letter landscape mode.

You could write the command as two separate steps if you wanted:

Code: [Select]
wget -nH -k -K -E -O myreport.html -p "http://yourserver.com:8080/queuemetrics/qm_rep.do?user=robot&pass=robotpass&queues=q1&period=t1"
htmldoc --webpage --size 11x8.5in -f report.pdf report.html

This one should show most of the images (so if you have a company logo in QM, it will still be there in the report), except the bar graph images. For some reason the robot user's reports do not show the bar graphs for me. (The source code of the rendered page has the bar graph image trying to be called from "/img" instead of "/queuemetrics/img" for some reason.)

To send the report as an attachment from the command line (or from within a script), you may want to install mutt or nail (yes, with an 'n'). In my testing, nail seems to work a little better, but I haven't spent much time on it at this point.

Something like this seems to work well, putting it all together:

Code: [Select]
wget -nH -k -K -E -O myreport.html -p "http://myserver.com:8080/queuemetrics/qm_rep.do?user=robot&pass=robotpass&queues=q1&period=t1"
htmldoc --webpage --size 11x8.5in -f myreport.pdf myreport.html
echo "Your daily report is attached as a PDF" | env MAILRC=/dev/null from=qm-server@example.com smtp=mail.example.com nail -n -s "Daily Report" -a myreport.pdf user@privatelabelcc.com

I hope this helps!

DionV

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
SOLVED: Generate reports and send them by email
« Reply #1 on: April 11, 2009, 09:27:48 »
Super cool man! ;-) this will be linked straight from the FAQs.

We'll add a check for the weird /img behaviour.... it will be more likely ../img, meaning "the folder img in the partent directory".



dionv

  • Newbie
  • *
  • Posts: 16
  • Karma: 2
    • View Profile
Re: SOLVED: Generate reports and send them by email
« Reply #2 on: April 12, 2009, 02:16:30 »
Super cool man! ;-) this will be linked straight from the FAQs.

We'll add a check for the weird /img behaviour.... it will be more likely ../img, meaning "the folder img in the partent directory".





Ah, yes, my typo in creating the message. It was late. I double-checked the source page of the rendered page in my browser:

Code: [Select]
<tr class='ST_TR0'>
  <td class='stData' style='width: 250;'> John Smith </td>
  <td class='stData' style='width: 90;'>1</td>

  <td class='stData' style='width: 50;' align='right'> 5.6% </td>
 <td class='stData' style='width: 200;'><img src='../img/shade-histo.gif' height='10' width='200.0'></td>
</tr>

It is, indeed, "../img/"

DionV

QueueMetrics

  • Loway
  • Hero Member
  • *
  • Posts: 2999
  • Karma: 39
    • View Profile
    • QueueMetrics
Re: SOLVED: Generate reports and send them by email
« Reply #3 on: April 14, 2009, 15:19:13 »
You could always create a ../img directory and download the image there :-)