NAME

dbitemplater - Utility for running a SQL query via DBI and using the output in a template.

SYNOPSIS

dbitemplater [-c <config>|-f <config file>] [-o]

dbitemplater -h/--help

dbitemplater -v/--version

FLAGS

-c $config

A short config file to use.

This will convert it to `/usr/local/etc/dbitemplater/$config.yaml`.

-f $config_file

The full path to the config file to use.

Default: `/usr/local/etc/dbitemplater.yaml`

-o

Print to STDOUT even if a file is specified in the config.

-h / --help

Print the help info.

-v / --version

Print the version info.

CONFIG

Thw following variables are accepted.

- ds :: The DBI connection string to use.

- user :: The user to use for the connection.

- pass :: The pass to use for the connection.

- output :: The file to use to the results to.
    If undef it is printed to STDOUT.

- query :: The SQL query to run.

- header :: The header template to use.

- row :: The template to use for each returned row.

- footer :: The footer template.

The required ones are below.

ds
header
row
footer

The following will be passed to Template->new.

POST_CHOMP
PRE_CHOMP
TRIM
START_TAG
END_TAG

Other variables may be specified, which can be used in the templats as the entire config is passed to the templates under the name config.

For the template variable, header/row/footer, those are assumpted to be a under "/usr/local/etc/dbitemplater/$type/$name". So if the value of "header" is "foo" then the path for that template will be "/usr/local/etc/dbitemplater/header/foo". Although if it contains a slash character, it is assumed to be a full path.

EXAMPLE

Lets say you want to set create a HTML display of LibreNMS alerts you could do like below...

For `/usr/local/etc/dbitemplater.yaml` ...

ds: DBI:mysql:database=librenms;hostname=127.0.0.1
user: librenms
pass: somePassword
query: 'select *,alerts.timestamp AS alert_timestamp,alert_rules.notes AS alert_notes,devices.notes AS device_notes from alerts inner join alert_rules on alerts.rule_id = alert_rules.id inner join devices on alerts.device_id = devices.device_id where alerts.state != 0 order by alerts.timestamp DESC'
header: librenms_alerts
row: librenms_alerts
footer: librenms_alerts
librenms_dev_base: https://librenms.foo.bar/device/

For `/usr/local/etc/dbitemplater/templates/header/librenms_alerts`...

<!DOCTYPE html>
<html>
<body>
<table>
    <tr>
        <th>Alert Name</th>
        <th>Device Hostname</th>
        <th>State</th>
        <th>Status</th>
        <th>Reason</th>
        <th>Timestamp</th>
        <th>Dev Notes</th>
        <th>Alert Notes</th>
    </tr>

For `/usr/local/etc/dbitemplater/templates/row/librenms_alerts`...

<tr>
    <th>[% row.name %]</th>
    <th><a href="[% config.librenms_dev_base %][% row.device_id %]">[% row.hostname %]</a></th>
    <th>[% row.state %]</th>
    <th>[% row.status %]</th>
    <th>[% row.status_reason %]</th>
    <th>[% row.alert_timestamp %]</th>
    <th>[% row.device_notes %]</th>
    <th>[% row.alert_notes %]</th>
</tr>

For `/usr/local/etc/dbitemplater/templates/footer/librenms_alerts` ...

</table>
</body>
</html>