Let say we have the following situation:
- cactihost.your.dom = Server that runs cacti
- queryme.your.dom = Server that you want to make a graph of
- On cactihost.your.dom the Cacti cron job runs as user 'cacti'.
- The Cacti home dir on cactihost.your.dom is /var/www/cacti
On cactihost.your.dom you become root and execute the following:
Code: Select all
# mkdir /var/www/cacti/.ssh
# chown cacti:cacti /var/www/cacti/.ssh
# chmod 700 /var/www/cacti/.ssh
# su cacti
$ ssh-keygen
Enter file in which to save the key (/var/www/cacti/.ssh/id_rsa): [Return]
Enter passphrase (empty for no passphrase): [Return]
Enter same passphrase again: [Return]
$ cat /var/www/cacti/.ssh/id_rsa.pub
Log in as root on queryme.your.dom and execute the following:
Code: Select all
# adduser cactiquery
# su cactiquery
$ mkdir ~/.ssh
$ chmod 700 ~/.ssh
$ echo [Paste the copied text] >>~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
I assume you are still user 'cacti', otherwise do # su cacti
Code: Select all
$ ssh cactiquery@queryme.your.dom -p22 'df -h'
The command should output the disk space status of the queryied server.
If you execute the command again, it should just output the info, and not ask anything.
So now let's create a test script that counts the number of httpd processes running on queryme.your.dom. Make sure you are logged in as 'cactiquery' on queryme.your.dom. Execute:
Code: Select all
$ echo 'echo -n "httpds:"`ps h -C httpd |wc -l`' >~/httpds.sh
$ chmod 700 ~/httpds.sh
$ ~/httpds.sh
Now lets do a last test on cactihost.your.dom, execute as user 'cacti':httpds:8
Code: Select all
$ ssh cactiquery@queryme.your.dom -p22 '~/httpds.sh'
Now it's time to create the Data Input Method in the Cacti Console.
- Click the 'Console' tab on the top of the cacti web interface
- Click 'Data Input Methods'
- Click 'Add' on the top right of the page
- Name: httpd process count (ssh)
- Input type: Script/Command
- Input string:
Code: Select all
ssh cactiquery@<hostname> -p22 '~/httpds.sh'
- Click the create button
- Click the 'Add' link in the Input Fields box
- Field[Input]: hostname
- Friendly name: Hostname
- Special Type Code: hostname
- Click 'create'
- Click the 'Add' link in the Output Fields box
- Field [Output]: httpds
- Friendly Name: Number of httpd processes
- Update RRD File: checked
- Click 'create'
- Click 'save'
Now you can create a Data Template that uses this Data Input Method (as GAUGE), and a Graph Template using that Data Source.
I hope this howto helps someone to build his/her own remote query script and use it in Cacti, without the need of SMTP. Please let me know.