How to use bash and ssh as data input method

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
tcherkon
Posts: 2
Joined: Thu Aug 27, 2015 1:48 pm
Location: Toronto, Canada

How to use bash and ssh as data input method

Post by tcherkon »

Hi everyone,

I think this is very simple issue which can be easily resolved, but still I couldn't find the answer.

I want to build a graph based on a bash script output.
So I have 2 bash scripts that generate exactly the same output. Cacti can perfectly build a graph based on the script #1. But for script #2 Cacti poller generates an error message.
What is the reason for that?

SCRIPT #1 (the one that works)
------------------------------------
Script:
#!/bin/sh
echo 'kbps1:10 kbps10:10 kbps30:10'
Script output:
root@host:/usr/share/cacti/site/scripts# ./test.sh 10.1.1.1
kbps1:10 kbps10:10 kbps30:10
SCRIPT #2 (the one that doesn't work)
------------------------------------------
(This is a simple script that uses ssh to get some statistics from a FortiGate)
Script:
#!/bin/sh
ssh -i /home/user/.ssh/id_rsa -l user -q $1 < /usr/share/cacti/site/scripts/script.fg | grep network | awk '{printf "kbps1:" int($7) " kbps10:" int($12) " kbps30:" int($17) "\n"}'
Script output:
root@host:/usr/share/cacti/site/scripts# ./fg_network.sh 10.1.1.1
kbps1:341 kbps10:336 kbps30:323
File 'script.fg' contains some FortiGate commands.

The output looks exactly the same as for the script #1. But the Cacti poller complains that the result of the script is invalid:
08/27/2015 01:30:02 PM - CMDPHP: Poller[0] Host[2] DS[137] WARNING: Result from CMD not valid. Partial Result: U
08/27/2015 01:30:02 PM - CMDPHP: Poller[0] Host[2] DS[137] CMD: /usr/share/cacti/site/scripts/fg_network.sh 10.1.1.1, output: U
08/27/2015 01:30:02 PM - CMDPHP: Poller[0] DEVEL: SQL Exec: "insert into poller_output (local_data_id, rrd_name, time, output) values (137, '', '2015-08-27 13:30:02', 'U')"
PS. I've completed all steps from the Cacti troubleshooting manual but that didn't help.

Thank you in advance!
tcherkon
Posts: 2
Joined: Thu Aug 27, 2015 1:48 pm
Location: Toronto, Canada

Re: How to use bash and ssh as data input method

Post by tcherkon »

The issue is resolved. The reason was that I was testing script as root, but when cacti user ran the script that resulted in some errors.
I needed to make ssh private key and ssh 'known hosts' file readable by cacti.
Everything works now.
Posting this just in case anyone interested.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest