Prepare a self-written script and include the data in CACTI

I’m using cacti to keep track of Inbound and Outbound Traffic, Load on the Linux Server, Ping-Time to my webserver in the internet, etc. But I also use it for other everyday usages, like „How many users are on my TS3-Server?“ or „How much power does my desktop system consume?“

For these type of questions, I’ve written some scripts which output a single information. These scripts can be written in different languages, like perl or php, but I prefer writing them directly in bash.

Here’s an example which keeps track of how many users are on my TeamSpeak 3 Server at any given time:

#!/bin/bash
PASSWORD="yourpassword"
TS3HOSTNAME="localhost"
arr=($(echo "use sid=1
login client_login_name=serveradmin client_login_password=${PASSWORD}
serverinfo" | nc ${TS3HOSTNAME} 10011 | grep virtualserver_clientsonline))
for ((i=0; i<${#arr[@]}; i++))
do
        if [[ ${arr[${i}]} == virtualserver_clientsonline* ]]; then
                now=$(sed 's/virtualserver_clientsonline=//' <<< ${arr[${i}]})
                let "now -= 1"
                echo "now:${now}"
                break
        fi
done

The output is simply „now:3“, when three users were logged in at that time. As our connect to the TS3-server also counts, we must decrease the number of clients (let "now -= 1").

When the script works as expected, put it into the CACTI-scripts-directory:

/usr/share/cacti/site/scripts

And make sure that it is executable by the cacti user (i.e. make it executable for everyone):

root@host:/usr/share/cacti/site/scripts# ls -lA ts3.sh
-rwxr-xr-x 1 root root 388 Sep 26 11:22 ts3.sh

Now log into your cacti, switch to the console-tab and follow these steps:

  1. Data Input Methods: Add a new one, reference to the script (Input Type: Script/Command) with this Input String: /bin/bash /scripts/ts3.sh
    Make sure to add all „Output fields“ as well, these are the data that’s coming from your script. In the example of TS3-Users above, this would me „now“.
  2. Data Template: Choose as „Data Input Method“ the just added Data Input Method. As „Data Source Item“ create ALL which are relevant for this graph, choose the fields which were created in step 1 accordingly as Output Field.
  3. Graph Template: Create all necessary graphs. Remember that you can easily peek at other graphs which values might be useful: The Graph itself („AREA“) and the printed values below („GPRINT“).
  4. Data Sources: Add our Data Template as a Data Source. Remember to SAVE.
  5. Graph Management: –> ADD, the newly created Data Sources are available now.
  6. Devices: Associated Graph Templates: Add the new template (from 4) to the device

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.