Reporting

Trigger a PDF via the command line

vincesesto
Communicator

Hello,

I would like to create a script that would trigger a pdf creation of a dashboard. I understand how to create a pdf and send via a saved search, but I would like to use a script to perform the same function.

I am having a little trouble understanding how the pdf renderer works and cannot find any documentation that would describe how to do this...Does anyone have any ideas?

Regards Vince

shivakso
New Member

This is a useful solution for anyone trying to trigger a Splunk dashboard PDF from a script. The important part is that the _ScheduledView__mypdf saved search contains the PDF and dashboard settings, while the REST API request triggers the saved search.

I would also recommend using a dedicated Splunk user instead of the admin account for automation. This makes the setup safer and avoids problems if the administrator account changes later.

For troubleshooting, check the saved search name, dashboard view, REST endpoint, user permissions, and PDF delivery settings. If the dashboard contains many charts or panels, PDF rendering may also take some extra time.

These Splunk discussions may help with related issues:

https://community.splunk.com/t5/Reporting/bd-p/splunk-reporting

https://community.splunk.com/t5/tag/pdf/tg-p/board-id/splunk-reporting

https://community.splunk.com/t5/Reporting/Trigger-a-PDF-via-the-command-line/m-p/147464

Overall, the scheduled-view plus REST API approach is a simple way to trigger dashboard PDF generation from a shell script or automation workflow.

0 Karma

shrtando
New Member

Hi,
I have exactly same requirement where create a dashboard and schedule PDF delivery for that.
I am new to splunk REST API concepts. Can you please explain the script mentioned here
what is PDF Trigger here? Is it an alert with name whatever_alert?
what is ScheduledView_mypdf, it also looks like an alert ?

Where is whatever_alert used in the script?
!/bin/bash
curl -k -u admin:password https://localhost:8089/servicesNS/admin/search/saved/searches/_ScheduledView__mypdf/dispatch -d trigger_actions=1
How does splunk server know that whatever_alert needs to be called for this ScheduledView_mypdf?

I need to do all these using Splunk Java SDK. Any step by step instruction on how to do this will be appreciated. Thanks in advance!

0 Karma

Kyle_Jackson
Explorer

This works!

PDF TRIGGER

[whatever_alert]
action.script = 1
action.script.filename = whatever_pdf_trigger.sh
cron_schedule = */10 * * * *
dispatch.earliest_time = -2m@m
dispatch.latest_time = now
displayview = flashtimeline
enableSched = 1
counttype = number of events
relation = greater than
quantity = 0
search = index=ops | head 2

PDF

[_ScheduledView__mypdf]
action.email = 1
action.email.maxtime = 60m
action.email.paperorientation = portrait
action.email.papersize = letter
action.email.pdfview = mypdf
action.email.sendpdf = 1
action.email.to = [email protected]
action.email.ttl = 10
cron_schedule = */5 * * * *
description = scheduled search for view name=mypdf
dispatch.earliest_time = 1
dispatch.latest_time = 2
enableSched = 0
is_visible = 0
search = | noop

Script:

!/bin/bash
curl -k -u admin:password https://localhost:8089/servicesNS/admin/search/saved/searches/_ScheduledView__mypdf/dispatch -d trigger_actions=1

josemanm12
Engager

Could you share the script ?

0 Karma

Kyle_Jackson
Explorer

If that user expires because they leave the company, then what? Is there a caveat to using admin?

0 Karma

chris
Motivator

It might be a good idea to use a different user than admin. If you do the url changes to:
https://localhost:8089/servicesNS/my_user/search/saved/searches/_ScheduledView__mypdf/dispatch -d trigger_actions=1

0 Karma

wlouisharris
New Member

Very nice - this works great.

0 Karma

vincesesto
Communicator

one more try to see if anyone has any ideas?

0 Karma

vincesesto
Communicator

Sorry, just to clarify this a bit further, the view I have set up is complex and has a lot of graphs, etc. So it is not something that I can run as a search and then use sendemail. I am wanting to generate the pdf from the html page and then forward this pdf onto an email address, similar to using a scheduled search but I need to be able to trigger it from a script

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...