Plugin return report NULL

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Plugin return report NULL

Post by filipe.avelino1 »

Good afternoon, I developed a plugin in Python to read a value of a presence sensor connected through the serial port with arduino. I used several techniques, the latest version used the pynagios library. I realized that by removing the code that connects the serial port the plugin works normally, but to keep the code snippet in webinterface and returns status WARNING and status NULL. Someone can help me ? Please

Code: Select all

#!/usr/bin/python
import pynagios
import serial
from pynagios import Plugin, Response
valor = 1
class MyCheck(Plugin):
    def check(self):
      #ser = serial.Serial('/dev/ttyACM0',9600,timeout=0)
      #if str(ser.read()) == '1':
      if valor == 1:
	return Response(pynagios.CRITICAL, "Intrusos Detectados")
      else:
	return Response(pynagios.OK, "Sem Ameacas")

if __name__ == "__main__":
    # Instantiate the plugin, check it, and then exit
    MyCheck().check().exit()
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Plugin return report NULL

Post by tmcdonald »

I believe that has to do with your indentation:

http://stackoverflow.com/questions/1226 ... -in-python

Specifically, I think you need to move your "return" statements over in the if and else sections. I am not a python expert, but from what I have read this seems to be the case.

Also, you might like the presentation I did at this year's Nagios World Conference. I did something very similar to what you are doing with Arduinos:

https://www.youtube.com/watch?v=Bt9yUpLrC5w
Former Nagios employee
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Re: Plugin return report NULL

Post by filipe.avelino1 »

I think not, because I run manually and works normally. In this example that I said the passage that communicates with the serial port and I configured the manual value
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Plugin return report NULL

Post by sreinhardt »

Can you give us some examples of this working and not working from the cli, along with the associated exit codes after each run?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Re: Plugin return report NULL

Post by filipe.avelino1 »

Sure,
Not working

Code: Select all

#!/usr/bin/python
import pynagios
import serial
from pynagios import Plugin, Response

class MyCheck(Plugin):
    def check(self):
      ser = serial.Serial('/dev/ttyACM0',9600,timeout=0)
      if str(ser.read()) == '1':
     	return Response(pynagios.CRITICAL, "Intrusos Detectados")
      else:
	return Response(pynagios.OK, "Sem Ameacas")

if __name__ == "__main__":
    # Instantiate the plugin, check it, and then exit
    MyCheck().check().exit()

Code: Select all

[root@tux-mateus plugins]# python tcc2_final.py 
CRIT: Intrusos Detectados
Image attachment
Attachments
erro=nagios.png
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Re: Plugin return report NULL

Post by filipe.avelino1 »

Working, but i set this values manually
See, I commented the code that instantiates the serial port

cli:

Code: Select all

[root@tux-mateus plugins]# python tcc2.py 
OK: Sem Ameacas

Code: Select all

#!/usr/bin/python
import pynagios
import serial
from pynagios import Plugin, Response
valor = 0
class MyCheck(Plugin):
    def check(self):
      #ser = serial.Serial('/dev/ttyACM0',9600,timeout=0)
      #if str(ser.read()) == '1':
      if valor == 1:
	return Response(pynagios.CRITICAL, "Intrusos Detectados")
      else:
	return Response(pynagios.OK, "Sem Ameacas")

if __name__ == "__main__":
    # Instantiate the plugin, check it, and then exit
    MyCheck().check().exit()
Attachments
no-erro-nagios.png
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Plugin return report NULL

Post by tmcdonald »

What are the permissions on the plugin? It seems like it might not have permissions as the nagios user to open the serial pipe.

Can you try to "su nagios" and run it as the nagios user? Then run "echo $?" to see the exit code. I'll be it is 1.
Former Nagios employee
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Re: Plugin return report NULL

Post by filipe.avelino1 »

My permissions
I could not use the su command nagios returns the account is not available at the time. I execute echo $? , return 1
Attachments
permissions-nagios.png
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Plugin return report NULL

Post by tmcdonald »

You might not have the nagios user, but that should show other problems as well. Try running the following:

Code: Select all

grep "nagios" /etc/passwd
chage -l nagios
Former Nagios employee
User avatar
filipe.avelino1
Posts: 6
Joined: Mon Dec 15, 2014 12:31 pm

Re: Plugin return report NULL

Post by filipe.avelino1 »

Return:

Atachament
Attachments
permissions-nagios1.png
Locked