Skip to content

Instantly share code, notes, and snippets.

@waa
Last active August 22, 2019 07:06
Show Gist options
  • Save waa/0046ea8f75c46430d4ef84322a978f11 to your computer and use it in GitHub Desktop.
Save waa/0046ea8f75c46430d4ef84322a978f11 to your computer and use it in GitHub Desktop.

Revisions

  1. waa revised this gist Sep 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png?style=centerme)
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  2. waa revised this gist Sep 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png?style=centerme))
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png?style=centerme)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  3. waa revised this gist Sep 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ->![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png)<-
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png?style=centerme))

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  4. waa revised this gist Sep 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png)
    ->![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png)<-

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  5. waa revised this gist Sep 26, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926.png)
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926-a.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  6. waa revised this gist Sep 26, 2017. 3 changed files with 88 additions and 65 deletions.
    84 changes: 46 additions & 38 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923-b.png)
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170926.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
    @@ -10,14 +10,16 @@ It should be opbvious, but you will need a fully functional Bacula (community or
    Copy the **smashing-BaculaStatus.sh** bash shell script to any directory you like. It may be somewhere on the smashing server, on the Bacula Director, or any machine where cron is available. Near the top of this file, edit the variables to match your system. You will need to create a bconsole-smashing.conf file, and the information (password etc) in this file will need to match a console section in the Director's "bacula-dir.conf" config file. (see examples below)

    ### bacula-dir.conf
    Here is a snippet of a Console resource in the bacula-dir.conf file which will restrict our widget to just being able to query the status of the Director and list jobs. After editing the bacula-dir.conf file, type **reload** in bconsole or restart the Director:
    Here is a snippet of a Console resource in the bacula-dir.conf file which will restrict our script/widget to just being able to issue the "list" command. After editing the bacula-dir.conf file, type **reload** in bconsole or restart the Director:
    ```
    Console {
    Name = smashing
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Some pseudo random password
    CatalogACL = MyCatalog # Set this to the name of your Bacula catalog database
    CommandACL = status, list # Only allow "status" and "list" commands
    JobACL = *all* # Allow "status director" command to show all jobs
    CommandACL = list # Only allow "list" command
    JobACL = *all* # Allow "list jobs" command to show all jobs
    ClientACL = *all* # Required for Bacula Enterprise Edition
    FilesetACL = *all* # Required for Bacula Enterprise Edition
    }
    ```
    ### bconsole-smashing.conf
    @@ -36,44 +38,12 @@ Console {
    }
    ```
    ### Testing bconsole connectivity
    At this point, we should be able to connect to the Director with bconsole using the bconsole-smashing.conf configuration file and type the "list jobs" and "status director" commands that the widget will use:
    At this point, we should be able to connect to the Director with bconsole using the bconsole-smashing.conf configuration file and type the "list jobs" "list jobtotals" and "list clients" commands that the widget will use:
    ```
    $ bconsole -c /path/to/bconsole-smashing.conf
    Connecting to Director bacula.example.com:9101
    1000 OK: 103 bacula-dir Version: 9.0.3 (08 August 2017)
    Enter a period to cancel a command.
    * status director
    bacula-dir Version: 9.0.3 (08 August 2017) x86_64-pc-linux-gnu gentoo
    Daemon started 23-Sep-17 13:12, conf reloaded 23-Sep-2017 13:12:52
    Jobs: run=0, running=0 mode=0,0
    Heap: heap=389,120 smbytes=489,382 max_bytes=499,788 bufs=3,324 max_bufs=3,331
    Res: njobs=69 nclients=22 nstores=4 npools=13 ncats=1 nfsets=36 nscheds=12
    Scheduled Jobs:
    Level Type Pri Scheduled Job Name Volume
    ===================================================================================
    Admin Admin 5 23-Sep-17 20:00 UpdateSlots
    Incremental Backup 10 23-Sep-17 20:00 pi c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 jabber c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 dns1 c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 helpdesk c0_0004_0066
    [...]
    Running Jobs:
    Console connected at 23-Sep-17 13:12
    No Jobs running.
    ====
    Terminated Jobs:
    JobId Level Files Bytes Status Finished Name
    ====================================================================
    16833 Incr 20 15.29 M OK 23-Sep-17 01:20 pi
    16834 Admin 0 0 OK 23-Sep-17 01:20 UpdateSlots
    16835 Full 681,136 45.60 G OK 23-Sep-17 04:29 Zimbra8
    16837 Restore 120 6.911 G OK 23-Sep-17 04:46 RestoreCatalog
    [...]
    ```
    And now test the "list jobs" command:
    ```
    *list jobs limit=10
    Automatically selected Catalog: MyCatalog
    Using Catalog "MyCatalog"
    @@ -84,11 +54,49 @@ Using Catalog "MyCatalog"
    | 9,743 | SpeedyMusic | 2016-06-22 20:00:01 | B | I | 0 | 0 | T |
    [...]
    ```

    And now the "list jobtotals" command:
    ```
    *list jobtotals
    +------+------------+---------------+------------------------+
    | jobs | files | bytes | job |
    +------+------------+---------------+------------------------+
    | 24 | 22,886 | 506377942 | upsmon |
    | 2 | 1,247,407 | 169475049168 | Speedy |
    | 159 | 0 | 0 | UpdateSlots |
    | 29 | 19,578,500 | 1296746802362 | Zimbra8 |
    | 33 | 3,680 | 191430895439 | Catalog |
    | 65 | 7,402 | 394530438401 | RestoreCatalog |
    | 30 | 629,553 | 6319028879 | dns1 |
    [...]
    | 10 | 81,558 | 3967342055 | proxmox-a |
    | 1 | 47 | 907607706207 | Proxmox_VM_Backups |
    +------+------------+---------------+------------------------+
    +-------+------------+---------------+
    | jobs | files | bytes |
    +-------+------------+---------------+
    | 1,458 | 29,611,195 | 6526958283636 |
    +-------+------------+---------------+
    ```

    And finally the "list clients" command:
    ```
    *list clients
    +----------+-------------------+---------------+--------------+
    | clientid | name | fileretention | jobretention |
    +----------+-------------------+---------------+--------------+
    | 1 | bacula-fd | 31,536,000 | 31,536,000 |
    | 2 | speedy-fd | 31,536,000 | 31,536,000 |
    | 3 | upsmon | 31,536,000 | 31,536,000 |
    | 6 | zimbra8-fd | 31,536,000 | 31,536,000 |
    [...]
    ```

    ### Dashboard entry
    Add the following to your dashboard.erb file:
    ```
    <li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
    <div data-id="bacula" data-view="Bacula" data-title="Bacula Backups" data-runningjobs="Waiting on update" data totaljobs="Waiting on update" data-firstlast="Waiting on update" data-goodjobs="Waiting on update" data-problemjobs="Waiting on update" data-incompletejobs="Waiting on update" data-adminjobs="Waiting on update" data-verifyjobs="Waiting on update" data-restorejobs="Waiting on update" data-totalfiles="Waiting on update" data-totalbytes="Waiting on update">
    <div data-id="bacula" data-view="Bacula" data-title="Bacula Backups" data-runningjobs="Waiting on update" data totalclients="Waiting on update" data totaljobs="Waiting on update" data-goodjobs="Waiting on update" data-problemjobs="Waiting on update" data-incompletejobs="Waiting on update" data-firstlast="Waiting on update" data-adminjobs="Waiting on update" data-verifyjobs="Waiting on update" data-restorejobs="Waiting on update" data-totalfiles="Waiting on update" data-totalbytes="Waiting on update">
    </div>
    </li>
    ```
    3 changes: 2 additions & 1 deletion bacula-html
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    <h1 class="title" data-bind="title"></h1>
    <hr>
    <h3 data-bind="runningjobs"></h3>
    <h3 data-bind="totalclients"></h3>
    <h3 data-bind="totaljobs"></h3>
    <h3 data-bind="firstlast"></h3>
    <h3 data-bind="goodjobs"></h3>
    <h3 data-bind="problemjobs"></h3>
    <h3 data-bind="incompletejobs"></h3>
    <h3 data-bind="firstlast"></h3>
    <hr>
    <h3 data-bind="adminjobs"></h3>
    <h3 data-bind="verifyjobs"></h3>
    66 changes: 40 additions & 26 deletions smashing-BaculaStatus.sh
    Original file line number Diff line number Diff line change
    @@ -35,15 +35,18 @@
    # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    #
    # ------------------------------------------------------------------------------


    # System variables
    # ----------------
    bc="/usr/sbin/bconsole"
    bcconfig="/path/to/bconsole-smashing.conf"
    http="http" # http or https
    bcconfig="/etc/bacula/bconsole-smashing.conf"
    http="http" # Does smashing server use http or https?
    smashinghost="smashing.example.com"
    smashingport="3030"
    smashingauthtoken="xyz123"
    smashingauthtoken="123xyz"
    smashingwidget="bacula"
    smashingwidgettitle="Bacula Status"


    # --------------------------------------------------
    @@ -53,39 +56,42 @@ smashingwidget="bacula"

    # Get data from Bacula Director
    # -----------------------------
    runningjobs=$(printf "%'d\n" $(echo "status director" \
    | ${bc} -c ${bcconfig} \
    | awk "BEGIN {} /^Running.*/,/^Terminated/ {print}" \
    | grep "^ \+[0-9]" | wc -l))

    totaljobs=$(printf "%'d\n" $(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    firstjob=$(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | head -n 1 | cut -d '|' -f2 | tr -d ' ')
    lastjob=$(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | tail -n 1 | cut -d '|' -f2 | tr -d ' ')
    goodjobs=$(printf "%'d\n" $(echo "list jobs jobstatus=T" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    listjobs=$(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]")
    jobtotals=$(echo "list jobtotals" | ${bc} -c ${bcconfig} | tail -n4 | grep "^| \+[0-9]")
    totalclients=$(echo "list clients" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)

    failedjobs=$(echo "list jobs jobstatus=f" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    abortedjobs=$(echo "list jobs jobstatus=A" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    errorjobs=$(echo "list jobs jobstatus=E" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    diffjobs=$(echo "list jobs jobstatus=D" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    incompletejobs=$(printf "%'d\n" $(echo "list jobs jobstatus=I" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    problemjobs=$(printf "%'d\n" $(echo "${failedjobs} + ${abortedjobs} + ${errorjobs} + ${diffjobs} + ${incompletejobs}" | bc))

    adminjobs=$(printf "%'d\n" $(echo "list jobs jobtype=D" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    verifyjobs=$(printf "%'d\n" $(echo "list jobs jobtype=V" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    restorejobs=$(printf "%'d\n" $(echo "list jobs jobtype=R" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    # Parse the data for each of the variables we want to display
    # -----------------------------------------------------------
    runningjobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "^| \+[0-9]" | grep -v "| [ADEefIT] \+|$" | wc -l))
    totaljobs=$(echo ${jobtotals} | awk '{print $2}')
    firstjob=$(echo "${listjobs}" | head -n 1 | cut -d '|' -f2 | tr -d ' ')
    lastjob=$(echo "${listjobs}" | tail -n 1 | cut -d '|' -f2 | tr -d ' ')
    goodjobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "| T \+|$" | wc -l))
    abortedjobs=$(echo "${listjobs}" | grep "| A \+|$" | wc -l)
    errorjobs=$(echo "${listjobs}" | grep "| E \+|$" | wc -l)
    diffjobs=$(echo "${listjobs}" | grep "| D \+|$" | wc -l)
    failedjobs=$(echo "${listjobs}" | grep "| f \+|$" | wc -l)
    incompletejobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "| I \+|$" | wc -l))
    problemjobs=$(printf "%'d\n" $(echo "${abortedjobs} + ${errorjobs} + ${diffjobs} + ${failedjobs} + ${incompletejobs}" | bc))
    adminjobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "^| \+[0-9]" | grep "[0-9] | D |" | wc -l))
    verifyjobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "^| \+[0-9]" | grep "[0-9] | V |" | wc -l))
    restorejobs=$(printf "%'d\n" $(echo "${listjobs}" | grep "^| \+[0-9]" | grep "[0-9] | R |" | wc -l))
    totalfiles=$(echo "${jobtotals}" | awk '{print $4}')
    totalbytes=$(echo "${jobtotals}" | awk '{print $6}' | numfmt --to=iec --suffix=B)

    totalfiles=$(printf "%'d\n" $(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $13}' | paste -sd+ - | bc))
    totalbytes=$(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $15}' | paste -sd+ - | bc | numfmt --to=iec --suffix=B)

    # Send data to smashing server
    # ----------------------------
    curl -s -d "{ \"auth_token\": \"${smashingauthtoken}\", \
    curl -m 10 -s -d "{ \"auth_token\": \"${smashingauthtoken}\", \
    \"title\": \"${smashingwidgettitle}\", \
    \"runningjobs\": \"Running Jobs: ${runningjobs}\", \
    \"totalclients\": \"Total Clients: ${totalclients}\", \
    \"totaljobs\": \"Total Jobs: ${totaljobs}\", \
    \"firstlast\": \"First/Last: ${firstjob}/${lastjob}\", \
    \"goodjobs\": \"Good Jobs: ${goodjobs}\", \
    \"problemjobs\": \"Problem Jobs: ${problemjobs}\", \
    \"incompletejobs\": \"Incomplete Jobs: ${incompletejobs}\", \
    \"firstlast\": \"First/Last: ${firstjob}/${lastjob}\", \
    \"adminjobs\": \"Admin Jobs: ${adminjobs}\", \
    \"verifyjobs\": \"Verify Jobs: ${verifyjobs}\", \
    \"restorejobs\": \"Restore Jobs: ${restorejobs}\", \
    @@ -110,8 +116,16 @@ ${http}://${smashinghost}:${smashingport}/widgets/${smashingwidget}
    #
    # 20170923 - Initial release
    #
    # 20170925 - Re-write script so that only three bconsole calls are made, and 'bc'
    # is no longer necessary to perform any math.
    # - Added $smashingwidgettitle variable to allow setting the title from
    # the script.
    # - Rearranged the order of the output a little. Changed in the
    # widgets/bacula/bacula.html file too.
    # - Added a $totalclients variable to report.
    # - Set 10 second timeout on curl command
    # -------------------------------------------------------------------------------


    # I like small tabs. Use :set list in vim to see tabbing etc
    # vim: set tabstop=2:softtabstop=2:shiftwidth=2 #
    # vim: set tabstop=2:softtabstop=2:shiftwidth=2 #
  7. waa revised this gist Sep 24, 2017. 2 changed files with 2 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923-a.png)
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923-b.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
    1 change: 1 addition & 0 deletions bacula-html
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@
    <h3 data-bind="verifyjobs"></h3>
    <h3 data-bind="restorejobs"></h3>
    <hr>
    <center>Total Files & Bytes</center>
    <h3 data-bind="totalfiles"></h3>
    <h3 data-bind="totalbytes"></h3>

  8. waa revised this gist Sep 24, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923.png)
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923-a.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  9. waa revised this gist Sep 24, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  10. waa revised this gist Sep 24, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.
  11. waa revised this gist Sep 24, 2017. No changes.
  12. waa revised this gist Sep 24, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion smashing-BaculaStatus.sh
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,7 @@ verifyjobs=$(printf "%'d\n" $(echo "list jobs jobtype=V" | ${bc} -c ${bcconfig}
    restorejobs=$(printf "%'d\n" $(echo "list jobs jobtype=R" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))

    totalfiles=$(printf "%'d\n" $(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $13}' | paste -sd+ - | bc))
    totalbytes=$(printf "%'d\n" $(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $15}' | paste -sd+ - | bc))
    totalbytes=$(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $15}' | paste -sd+ - | bc | numfmt --to=iec --suffix=B)

    # Send data to smashing server
    # ----------------------------
  13. waa revised this gist Sep 23, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions smashing-BaculaStatus.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```
    #!/bin/bash
    #
    # smashing-BaculaStatus.sh
    @@ -115,5 +114,4 @@ ${http}://${smashinghost}:${smashingport}/widgets/${smashingwidget}


    # I like small tabs. Use :set list in vim to see tabbing etc
    # vim: set tabstop=2:softtabstop=2:shiftwidth=2 #
    ```
    # vim: set tabstop=2:softtabstop=2:shiftwidth=2 #
  14. waa revised this gist Sep 23, 2017. No changes.
  15. waa revised this gist Sep 23, 2017. 4 changed files with 40 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -84,6 +84,15 @@ Using Catalog "MyCatalog"
    | 9,743 | SpeedyMusic | 2016-06-22 20:00:01 | B | I | 0 | 0 | T |
    [...]
    ```
    ### Dashboard entry
    Add the following to your dashboard.erb file:
    ```
    <li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
    <div data-id="bacula" data-view="Bacula" data-title="Bacula Backups" data-runningjobs="Waiting on update" data totaljobs="Waiting on update" data-firstlast="Waiting on update" data-goodjobs="Waiting on update" data-problemjobs="Waiting on update" data-incompletejobs="Waiting on update" data-adminjobs="Waiting on update" data-verifyjobs="Waiting on update" data-restorejobs="Waiting on update" data-totalfiles="Waiting on update" data-totalbytes="Waiting on update">
    </div>
    </li>
    ```

    ### Widget files
    - Copy the bacula.coffee, bacula.html, and bacula.scss to **widgets/bacula**
    - Copy the smashing-BaculaStatus.sh script somehere, and set it executable:
    17 changes: 17 additions & 0 deletions bacula-html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <h1 class="title" data-bind="title"></h1>
    <hr>
    <h3 data-bind="runningjobs"></h3>
    <h3 data-bind="totaljobs"></h3>
    <h3 data-bind="firstlast"></h3>
    <h3 data-bind="goodjobs"></h3>
    <h3 data-bind="problemjobs"></h3>
    <h3 data-bind="incompletejobs"></h3>
    <hr>
    <h3 data-bind="adminjobs"></h3>
    <h3 data-bind="verifyjobs"></h3>
    <h3 data-bind="restorejobs"></h3>
    <hr>
    <h3 data-bind="totalfiles"></h3>
    <h3 data-bind="totalbytes"></h3>

    <p class="updated-at" data-bind="updatedAtMessage"></p>
    10 changes: 10 additions & 0 deletions bacula.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    class Dashing.Bacula extends Dashing.Widget

    ready: ->
    # This is fired when the widget is done being rendered

    onData: (data) ->
    # Handle incoming data
    # You can access the html node of this widget with `@node`
    # Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
    # $(@node).fadeOut().fadeIn()
    4 changes: 4 additions & 0 deletions bacula.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    .widget-bacula {
    background: #ca1108;
    font-size: 30px;
    }
  16. waa revised this gist Sep 23, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions smashing-BaculaStatus.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ```bash
    ```
    #!/bin/bash
    #
    # smashing-BaculaStatus.sh
    @@ -109,7 +109,7 @@ ${http}://${smashinghost}:${smashingport}/widgets/${smashingwidget}
    # ----------------------------
    #
    #
    # 20170924 - Initial release
    # 20170923 - Initial release
    #
    # -------------------------------------------------------------------------------
  17. waa revised this gist Sep 23, 2017. 1 changed file with 119 additions and 0 deletions.
    119 changes: 119 additions & 0 deletions smashing-BaculaStatus.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    ```bash
    #!/bin/bash
    #
    # smashing-BaculaStatus.sh
    #
    # ------------------------------------------------------------------------------
    #
    # waa - 20170923 - Initial release. Full changlog at bottom of script
    #
    # ------------------------------------------------------------------------------
    #
    # Copyright (c) 2017, William A. Arlofski waa-at-revpol-dot-com
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are
    # met:
    #
    # 1. Redistributions of source code must retain the above copyright
    # notice, this list of conditions and the following disclaimer.
    #
    # 2. Redistributions in binary form must reproduce the above copyright
    # notice, this list of conditions and the following disclaimer in the
    # documentation and/or other materials provided with the distribution.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    #
    # ------------------------------------------------------------------------------
    # System variables
    # ----------------
    bc="/usr/sbin/bconsole"
    bcconfig="/path/to/bconsole-smashing.conf"
    http="http" # http or https
    smashinghost="smashing.example.com"
    smashingport="3030"
    smashingauthtoken="xyz123"
    smashingwidget="bacula"
    # --------------------------------------------------
    # Nothing should need to be modified below this line
    # --------------------------------------------------
    # Get data from Bacula Director
    # -----------------------------
    runningjobs=$(printf "%'d\n" $(echo "status director" \
    | ${bc} -c ${bcconfig} \
    | awk "BEGIN {} /^Running.*/,/^Terminated/ {print}" \
    | grep "^ \+[0-9]" | wc -l))
    totaljobs=$(printf "%'d\n" $(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    firstjob=$(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | head -n 1 | cut -d '|' -f2 | tr -d ' ')
    lastjob=$(echo "list jobs" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | tail -n 1 | cut -d '|' -f2 | tr -d ' ')
    goodjobs=$(printf "%'d\n" $(echo "list jobs jobstatus=T" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    failedjobs=$(echo "list jobs jobstatus=f" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    abortedjobs=$(echo "list jobs jobstatus=A" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    errorjobs=$(echo "list jobs jobstatus=E" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    diffjobs=$(echo "list jobs jobstatus=D" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l)
    incompletejobs=$(printf "%'d\n" $(echo "list jobs jobstatus=I" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    problemjobs=$(printf "%'d\n" $(echo "${failedjobs} + ${abortedjobs} + ${errorjobs} + ${diffjobs} + ${incompletejobs}" | bc))
    adminjobs=$(printf "%'d\n" $(echo "list jobs jobtype=D" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    verifyjobs=$(printf "%'d\n" $(echo "list jobs jobtype=V" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    restorejobs=$(printf "%'d\n" $(echo "list jobs jobtype=R" | ${bc} -c ${bcconfig} | grep "^| \+[0-9]" | wc -l))
    totalfiles=$(printf "%'d\n" $(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $13}' | paste -sd+ - | bc))
    totalbytes=$(printf "%'d\n" $(echo "list jobs jobtype=B" | ${bc} -c ${bcconfig} | tr -d , | grep "^| \+[0-9]" | awk '{print $15}' | paste -sd+ - | bc))
    # Send data to smashing server
    # ----------------------------
    curl -s -d "{ \"auth_token\": \"${smashingauthtoken}\", \
    \"runningjobs\": \"Running Jobs: ${runningjobs}\", \
    \"totaljobs\": \"Total Jobs: ${totaljobs}\", \
    \"firstlast\": \"First/Last: ${firstjob}/${lastjob}\", \
    \"goodjobs\": \"Good Jobs: ${goodjobs}\", \
    \"problemjobs\": \"Problem Jobs: ${problemjobs}\", \
    \"incompletejobs\": \"Incomplete Jobs: ${incompletejobs}\", \
    \"adminjobs\": \"Admin Jobs: ${adminjobs}\", \
    \"verifyjobs\": \"Verify Jobs: ${verifyjobs}\", \
    \"restorejobs\": \"Restore Jobs: ${restorejobs}\", \
    \"totalfiles\": \"Files: ${totalfiles}\", \
    \"totalbytes\": \"Bytes: ${totalbytes}\" }" \
    ${http}://${smashinghost}:${smashingport}/widgets/${smashingwidget}
    # -------------
    # End of script
    # -------------
    # ----------
    # Change Log
    # ----------
    # ----------------------------
    # William A. Arlofski
    # Reverse Polarity, LLC
    # [email protected]
    # http://www.revpol.com/bacula
    # ----------------------------
    #
    #
    # 20170924 - Initial release
    #
    # -------------------------------------------------------------------------------
    # I like small tabs. Use :set list in vim to see tabbing etc
    # vim: set tabstop=2:softtabstop=2:shiftwidth=2 #
    ```
  18. waa revised this gist Sep 23, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -87,7 +87,7 @@ Using Catalog "MyCatalog"
    ### Widget files
    - Copy the bacula.coffee, bacula.html, and bacula.scss to **widgets/bacula**
    - Copy the smashing-BaculaStatus.sh script somehere, and set it executable:
    - # chmod +x smashing-BaculaStatus.sh
    - \# chmod +x smashing-BaculaStatus.sh
    - Edit the system variables at the top of the smashing-BaculaStatus.sh script

    ### cron job
  19. waa revised this gist Sep 23, 2017. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashbo
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.

    ## Installation
    Copy the **smashing-BaculaStatus.sh** bash shell script to any directory you like. It may be somewhere on the smashing server, on the Bacula Director, or any machine where cron is available. Near the top of this file, edit the variables to match your system. You will need to create a bconsole.conf file, and the information (password etc) in this file will need to match a console section in the Director's "bacula-dir.conf" config file. (see examples below)
    Copy the **smashing-BaculaStatus.sh** bash shell script to any directory you like. It may be somewhere on the smashing server, on the Bacula Director, or any machine where cron is available. Near the top of this file, edit the variables to match your system. You will need to create a bconsole-smashing.conf file, and the information (password etc) in this file will need to match a console section in the Director's "bacula-dir.conf" config file. (see examples below)

    ### bacula-dir.conf
    Here is a snippet of a Console resource in the bacula-dir.conf file which will restrict our widget to just being able to query the status of the Director and list jobs. After editing the bacula-dir.conf file, type **reload** in bconsole or restart the Director:
    @@ -32,7 +32,7 @@ Director {
    Console {
    Name = smashing # Must match the name of the Console in the bacula-dir.conf
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Must match the Console's Password in the bacula-dir.conf above
    Director = bacula-dir # Must match the Name of the Director above
    Director = bacula-dir # Must match the Name of the Director in this file just above
    }
    ```
    ### Testing bconsole connectivity
    @@ -85,7 +85,7 @@ Using Catalog "MyCatalog"
    [...]
    ```
    ### Widget files
    - Copy the bacula.coffee, bacula.html, and bacula.scss to /widgets/bacula
    - Copy the bacula.coffee, bacula.html, and bacula.scss to **widgets/bacula**
    - Copy the smashing-BaculaStatus.sh script somehere, and set it executable:
    - # chmod +x smashing-BaculaStatus.sh
    - Edit the system variables at the top of the smashing-BaculaStatus.sh script
    @@ -96,5 +96,4 @@ Using Catalog "MyCatalog"
    */30 * * * * /path/to/smashing-BaculaStatus.sh # Of course, use the correct path here :)
    ```
    ### Enjoy!
    Please let me know if there is something terrribly wrong with this widget. It is my first one, and I am sure it can use some enhancements, or fixes.

    Please let me know if there is something terrribly wrong with this widget. It is my first one, and I am sure it can use some enhancements, or fixes.
  20. waa revised this gist Sep 23, 2017. 1 changed file with 18 additions and 7 deletions.
    25 changes: 18 additions & 7 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -23,15 +23,15 @@ Console {
    ### bconsole-smashing.conf
    ```
    Director {
    Name = bacula-dir # Set this to the name of your Bacula director
    DIRport = 9101
    address = bacula.example.com # IP address or FQDN of your Bacula Director
    Password = "" # Not used, so it may be blank
    Name = bacula-dir # Set this to the name of your Bacula director
    DIRport = 9101
    Address = bacula.example.com # IP address or FQDN of your Bacula Director
    Password = "" # Not used, so it may be blank
    }
    Console {
    Name = smashing # Must match the name of the Console in the bacula-dir.conf
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Must match the Console's Password in the bacula-dir.conf above
    Name = smashing # Must match the name of the Console in the bacula-dir.conf
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Must match the Console's Password in the bacula-dir.conf above
    Director = bacula-dir # Must match the Name of the Director above
    }
    ```
    @@ -71,7 +71,9 @@ Terminated Jobs:
    16835 Full 681,136 45.60 G OK 23-Sep-17 04:29 Zimbra8
    16837 Restore 120 6.911 G OK 23-Sep-17 04:46 RestoreCatalog
    [...]
    ```
    And now test the "list jobs" command:
    ```
    *list jobs limit=10
    Automatically selected Catalog: MyCatalog
    Using Catalog "MyCatalog"
    @@ -87,3 +89,12 @@ Using Catalog "MyCatalog"
    - Copy the smashing-BaculaStatus.sh script somehere, and set it executable:
    - # chmod +x smashing-BaculaStatus.sh
    - Edit the system variables at the top of the smashing-BaculaStatus.sh script

    ### cron job
    - Add the following line you your cron scheduler. This example will run the script every 30 minutes:
    ```
    */30 * * * * /path/to/smashing-BaculaStatus.sh # Of course, use the correct path here :)
    ```
    ### Enjoy!
    Please let me know if there is something terrribly wrong with this widget. It is my first one, and I am sure it can use some enhancements, or fixes.

  21. waa created this gist Sep 23, 2017.
    89 changes: 89 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,89 @@
    This is a widget for the [Smashing](https://github.com/Smashing/smashing) dashboard. It displays quite a bit of statistics about your [Bacula](https://www.bacula.org) backup server environment.

    ## Preview
    ![](http://www.revpol.com/images/smashingBaculaWidget-20170923.png)

    ## Prerequisites
    It should be opbvious, but you will need a fully functional Bacula (community or enterprise edition) installation. This widget makes use of the Bacula command line tool called **bconsole** to query the Director for information, then sends the data to the Smashing server via **curl**.

    ## Installation
    Copy the **smashing-BaculaStatus.sh** bash shell script to any directory you like. It may be somewhere on the smashing server, on the Bacula Director, or any machine where cron is available. Near the top of this file, edit the variables to match your system. You will need to create a bconsole.conf file, and the information (password etc) in this file will need to match a console section in the Director's "bacula-dir.conf" config file. (see examples below)

    ### bacula-dir.conf
    Here is a snippet of a Console resource in the bacula-dir.conf file which will restrict our widget to just being able to query the status of the Director and list jobs. After editing the bacula-dir.conf file, type **reload** in bconsole or restart the Director:
    ```
    Console {
    Name = smashing
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Some pseudo random password
    CatalogACL = MyCatalog # Set this to the name of your Bacula catalog database
    CommandACL = status, list # Only allow "status" and "list" commands
    JobACL = *all* # Allow "status director" command to show all jobs
    }
    ```
    ### bconsole-smashing.conf
    ```
    Director {
    Name = bacula-dir # Set this to the name of your Bacula director
    DIRport = 9101
    address = bacula.example.com # IP address or FQDN of your Bacula Director
    Password = "" # Not used, so it may be blank
    }
    Console {
    Name = smashing # Must match the name of the Console in the bacula-dir.conf
    Password = "dpvCLchbz0I4/tf5HAB8sN0z" # Must match the Console's Password in the bacula-dir.conf above
    Director = bacula-dir # Must match the Name of the Director above
    }
    ```
    ### Testing bconsole connectivity
    At this point, we should be able to connect to the Director with bconsole using the bconsole-smashing.conf configuration file and type the "list jobs" and "status director" commands that the widget will use:
    ```
    $ bconsole -c /path/to/bconsole-smashing.conf
    Connecting to Director bacula.example.com:9101
    1000 OK: 103 bacula-dir Version: 9.0.3 (08 August 2017)
    Enter a period to cancel a command.
    * status director
    bacula-dir Version: 9.0.3 (08 August 2017) x86_64-pc-linux-gnu gentoo
    Daemon started 23-Sep-17 13:12, conf reloaded 23-Sep-2017 13:12:52
    Jobs: run=0, running=0 mode=0,0
    Heap: heap=389,120 smbytes=489,382 max_bytes=499,788 bufs=3,324 max_bufs=3,331
    Res: njobs=69 nclients=22 nstores=4 npools=13 ncats=1 nfsets=36 nscheds=12
    Scheduled Jobs:
    Level Type Pri Scheduled Job Name Volume
    ===================================================================================
    Admin Admin 5 23-Sep-17 20:00 UpdateSlots
    Incremental Backup 10 23-Sep-17 20:00 pi c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 jabber c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 dns1 c0_0004_0066
    Incremental Backup 10 23-Sep-17 20:00 helpdesk c0_0004_0066
    [...]
    Running Jobs:
    Console connected at 23-Sep-17 13:12
    No Jobs running.
    ====
    Terminated Jobs:
    JobId Level Files Bytes Status Finished Name
    ====================================================================
    16833 Incr 20 15.29 M OK 23-Sep-17 01:20 pi
    16834 Admin 0 0 OK 23-Sep-17 01:20 UpdateSlots
    16835 Full 681,136 45.60 G OK 23-Sep-17 04:29 Zimbra8
    16837 Restore 120 6.911 G OK 23-Sep-17 04:46 RestoreCatalog
    [...]
    *list jobs limit=10
    Automatically selected Catalog: MyCatalog
    Using Catalog "MyCatalog"
    +-------+-------------+---------------------+------+-------+----------+----------+-----------+
    | jobid | name | starttime | type | level | jobfiles | jobbytes | jobstatus |
    +-------+-------------+---------------------+------+-------+----------+----------+-----------+
    | 9,730 | SpeedyVMs | 2016-06-21 20:00:00 | B | I | 0 | 0 | T |
    | 9,743 | SpeedyMusic | 2016-06-22 20:00:01 | B | I | 0 | 0 | T |
    [...]
    ```
    ### Widget files
    - Copy the bacula.coffee, bacula.html, and bacula.scss to /widgets/bacula
    - Copy the smashing-BaculaStatus.sh script somehere, and set it executable:
    - # chmod +x smashing-BaculaStatus.sh
    - Edit the system variables at the top of the smashing-BaculaStatus.sh script