0

We're experiencing some strange issues with Nagios. We wrote a script in Python which uses paramiko, httplib and re. When we comment out the code that is written to use paramiko the script returns OK in Nagios. When we uncomment the script the status just returns (null).

This is our code

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#ssh.connect(self.get('hostname'),int(self.get('port')),self.get('username'),allow_agent=True)
ssh.connect('192.168.56.102' , 22 , 'oracle' ,allow_agent=True)
link = '127.0.0.1:4848'
stdin,stdout,stderr = ssh.exec_command('wget --no-proxy ' + link + ' 2>&1 | grep -i "failed\|error"')
result = stdout.readlines()
result = " ".join(result)

if result == "":
    return MonitoringResult(MonitoringResult.OK,'Webservice up')
else:
    return MonitoringResult(MonitoringResult.CRITICAL,'Webservice down %s' % result)

So when we comment out the part above

if result =="":

and add result="" above the if, it will just return 'Webservice up' in Nagios. When we enable the code above the if it will just return (null). Is there a conflict with paramiko or something?

When running the code in terminal it just returns the correct status but it doesn't show when implemented in Nagios

Nicholas
  • 1,189
  • 4
  • 20
  • 40

1 Answers1

0

I found that although nagios runs as effective user "nagios" it is using the environment settings for user "root" and not able to read the root private key to make the connection.

Adding key_filename='/nagiosuserhomedir/.ssh/id_dsa' to the options for ssh.connect() solved this same problem for me (pass the private key for nagios user explicitly in the code).

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
zog
  • 1