Discussion:
Check device status with Telnet
Stefan Reinke
2012-01-31 07:30:17 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64024#64024

--------------------------------------------------------------
Hi,

I have a remote device, only method to get into the device is to telnet to it. Everything else is blocked, all ICMP traffic as well.

How would I go about monitoring this device (The only thing I want to check is when the device goes down), but I cannot use ping.

Is there anyway I can use telnet to monitor the status of the device for me ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64024#64024]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
luizzmizz
2012-01-31 08:25:26 UTC
Permalink
luizzmizz [http://community.zenoss.org/people/luizzmizz] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/63997#63997

--------------------------------------------------------------
You want to use IpServices:
Model the device with zenoss.nmap/portscan.ipservice. After modelling the device, it will show  (between other discovered services) your telnet as a IP Service component. Here you can enable monitoring of telnet.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63997#63997]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-01-31 08:39:20 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64025#64025

--------------------------------------------------------------
Did as you said and got the following error while try modelling the device:

2012-01-31 10:31:37,385 WARNING zen.PythonClient: Error in zenoss.nmap.IpServiceMap: got stderr: 'Upon execvpe /usr/local/zenoss/zenoss/libexec/nmap [\'/usr/local/zenoss/zenoss/libexec/nmap\', \'-p\', \'1-1024;-sT;--open;-oG\', \'-\'] in environment id 197188844\n:Traceback (most recent call last):\n File "/usr/local/zenoss/python/lib/python2.6/site-packages/Twisted-8.1.0-py2.6-linux-i686.egg/twisted/internet/process.py", line 394, in _fork\n executable, args, environment)\n File "/usr/local/zenoss/python/lib/python2.6/site-packages/Twisted-8.1.0-py2.6-linux-i686.egg/twisted/internet/process.py", line 440, in _execChild\n os.execvpe(executable, args, environment)\n File "/usr/local/zenoss/python/lib/python2.6/os.py", line 353, in execvpe\n _execvpe(file, args, env)\n File "/usr/local/zenos
s/python/lib/python2.6/os.py", line 368, in _execvpe\n func(file, *argrest)\nOSError: [Errno 2] No such file or directory\n'

Any idea what this could mean ?

Thanks for your help btw :)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64025#64025]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-01-31 09:31:16 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64026#64026

--------------------------------------------------------------
I see this error is described here ? (Olrder version though) Am I correct ?

http://dev.zenoss.org/trac/ticket/5238 http://dev.zenoss.org/trac/ticket/5238
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64026#64026]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
luizzmizz
2012-01-31 09:38:13 UTC
Permalink
luizzmizz [http://community.zenoss.org/people/luizzmizz] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/63998#63998

--------------------------------------------------------------
whoah never seen it!

did you try with zenoss.portmap.ipservice?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/63998#63998]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-01-31 09:55:56 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64027#64027

--------------------------------------------------------------
Jip randomly the IP Services came up, even with that error still popping up if I try to model it :p

Thanks man!
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64027#64027]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-01-31 19:42:06 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64065#64065

--------------------------------------------------------------
You can use expect script to automate telnet sessions.  I use that in a command script to pull data out of a device via telnet and can even graph the data, set thresholds...

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64065#64065]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-03 08:07:01 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64183#64183

--------------------------------------------------------------
Hi Themactech,

Anyway you can shed some light on that script?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64183#64183]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-03 12:56:46 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64197#64197

--------------------------------------------------------------
I can do it over the weekend, I am slammed today.  If you don't get anything from me by sunday send an email.

I will dig through my zenpacks that use it and send something out.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64197#64197]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-04 16:54:11 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64250#64250

--------------------------------------------------------------
Ok, first of all, expect is a scripting language and it must be installed.  I include it in all my zenoss builds since it comes in handy on a regular basis.  You can find articles on the web on how to script with expect.  I use ubuntu so I just do 'sudo apt-get install expect'.

Now expect is somewhat dumb, you tell it what to send, what to 'expect' back, what to do next, and so on.

In my case I needed to extract data from a device that is only available via telnet, which sadly occurs frequently.  Since I have a hard time getting properly formatted data from expect script (I am no pro) I dump the whole transaction to file then parse it.

First, I write my expect script, which looks like this:

#!/usr/bin/expect

set TheName [lindex $argv 0]
set ThePass [lindex $argv 1]
set TheIP [lindex $argv 2]

spawn telnet $TheIP
sleep 1
expect "Login:"
send "$TheName\r"
expect "Password:"
send "$ThePass\r"
expect "command'
sleep 1
send "<your command here>\r"
expect "sent"
sleep 1
send "exit\r"

now I will save this in the /libexec folder of my ZenPack as 'pulltelnet'

Then I make a command data source in my ZenPack called GetTelnet, I set the command template to:

${here/ZenPackManager/packs/ZenPacks.<your>.<zenpack>/path}/libexec/trigger ${dev/zWinUser} ${dev/zWinPassword} ${dev/manageIp} ${here/ZenPackManager/packs/ZenPacks.<your>.<zenpack>/path}

** Note that in all cases where I have had to chat it up via telnet with devices, none of them were windows devices, so I use the windows name and password field to hold credentials for these devices.

This will call a shell script called 'trigger' and pass it 4 arguments:  username (in zWinUser), password (in zWinPassword), Device IP (in manageIp), and the path to the ZenPack so I can write files in the right place (using ZenPackManager)

Now I write a shell script called 'trigger' in /libexec of my ZenPack:

#!/bin/bash

TheName=$1
ThePass=$2
TheIP=$3
ThePath=$4

TheData=`expect "$ThePath"/libexec/pulltelnet "$TheName" "$ThePass" "$TheIP" | tee "$ThePath"/tests/""$TheIP"

** The pipe to 'tee' writes the expect transaction to a file named as the IP address of the device in the /tests folder of the zenpack

The rest of my trigger bash script parses the data of the file to extract what I want, assigns it to proper nagios style variables and exits with proper nagios exit value.

I end up with Data Points in Zenoss that were pulled from a telnet session, they will be pulled at every standard polling interval, can be put in graphs, set thresholds to them, etc...

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64250#64250]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-06 08:57:41 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64266#64266

--------------------------------------------------------------
Hi Manual.

Thanks for your input, I will have a look at this during the week!

Regards,
Stefan
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64266#64266]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-09 07:14:58 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64384#64384

--------------------------------------------------------------
Hi Themactech,

I have thought about this, wouldn't this use a lot of data. Logging into the device to get all the required information, to graph data. The problem I have is, this is a dish at a remote site. With very very expensive data costs. The only thing I want to monitor is one tcp service, isn't there a way in zenoss itself to graph the IP Service ? To just check if its still there and then plot it on a graph?

Regards,
Stefan
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64384#64384]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-09 07:36:48 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64400#64400

--------------------------------------------------------------
How about an nmap query?

Sent from my iPhone
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64400#64400]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-09 07:53:43 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64386#64386

--------------------------------------------------------------
How would I go about doing this ?

Sorry for all the Q's :)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64386#64386]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-09 09:45:52 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64390#64390

--------------------------------------------------------------
In the reports I have found one report: Device Availability .

That is precisely what I want, but in a graph. Any ideas ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64390#64390]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-09 18:42:10 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64437#64437

--------------------------------------------------------------
I will look at putting together a proper nmap query this weekend, I can't spare the time today.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64437#64437]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-10 01:19:47 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64420#64420

--------------------------------------------------------------
ok, if you install nmap and do this query (from a command datasource):

nmap -p 23 <your ip address>          (you should use manageIp to pass the value to your script)

you will get this

Host is up (0.00.23s latency)

If you parse this, you can push the latency value into a datapoint and graph it.  You can also set your nagios exit value to be good if 'Host is up' is detected, if not you can set the exit value so it will trigger an alert.

My guess is this would have a very minimal bandwidth footprint on your system.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64420#64420]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-10 01:22:00 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64451#64451

--------------------------------------------------------------
Note the same approach would work for any port, just change the port (23 for telnet) to whatever you need to keep an eye on.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64451#64451]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-10 01:25:04 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64452#64452

--------------------------------------------------------------
If you need to be more thorough do a telnet transaction as I mentioned earlier.  There might be times when your device is on the fritz and yet the port might still be open even though telnet transactions are no longer being processed.  Doing a bogus transaction (like pulling up the help menu) will at least show the device is still responding and not in a frozen state with the port open.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64452#64452]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-10 07:09:02 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64448#64448

--------------------------------------------------------------
Okay I have created the command data point (uptime.data) with command: nmap -PN -p 2003 ${manageIp} .

I tested the command in the linux box and it does get a reply with "Host is up " and latency.

I then created a graph definition and pointed the data point to the graph.

Is that all I have to do ?

Currently the graph is displaying the following: data cur:nan avg:nan max:nan .

I think I am missing something ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64448#64448]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
dpetzel
2012-02-10 07:22:49 UTC
Permalink
dpetzel [http://community.zenoss.org/people/dpetzel] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64449#64449

--------------------------------------------------------------
Post by themactech
If you parse this, you can push the latency value into a datapoint and graph it.
You don't want to simply dump the raw string, but rather you want to parse it an have a nagios style output produced
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64449#64449]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-10 07:41:48 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64469#64469

--------------------------------------------------------------
Ah I misread that, so If I understand correctly now. I need to create a script, run nmap command in the script then also parse it in the script .

And then in Zenoss I create a command data source that points to the script ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64469#64469]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
dpetzel
2012-02-10 07:44:36 UTC
Permalink
dpetzel [http://community.zenoss.org/people/dpetzel] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64470#64470

--------------------------------------------------------------
You might be able to skip the script and pull it all off in gnarly one-liner but yeah you got the right idea. Ensure it spits out in nagios format and you should be good.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64470#64470]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-10 08:08:31 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64471#64471

--------------------------------------------------------------
Any idea on how I can do the one-liner ? I am trying to stay away from scripts and such.

Thanks for the help :)
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64471#64471]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-10 13:04:58 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64474#64474

--------------------------------------------------------------
But scripts are your friends... (pouts)


#!/bin/bash

TheIP=$1

TheRaw=`nmap -PN -p 2003 "$TheIP"`

UpCheck = `echo "$TheRaw" | grep 'Host is up' | wc -l`

PortCheck = `echo "$TheRaw" | grep '2003/tcp' | awk '{print $2}'

Latency = `echo "$TheRaw" | grep 'latency' | awk -F '(' '{print $2}' | awk -F 's' '{print $1}'`

UpCheck will be 1 if 'Host is up' is detected in your nmap output, note that it will show 'Host is up' even if port 2003 is closed, that is why we add PortCheck, otherwise it will be 0

PortCheck will be equal to 'closed' or 'open'

Latency will be equal to your latency response from host

Some logic or math will have to be done, do you want your exit value based on UpCheck or PortCheck?  Latency will have to be multiplied to be an integer, command datasource points need to be integers to be graphed.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64474#64474]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-10 13:25:40 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64475#64475

--------------------------------------------------------------
I think the best exit value would be the UpCheck in my case.

So I geuss it is going to be scripting for me, lol!

Thanks a lot once again Manuel!
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64475#64475]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-10 13:41:14 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64476#64476

--------------------------------------------------------------
As you can see I am not good with scripting :p

So I need to install more packages?

nmap: /usr/local/zenoss/common/lib/libssl.so.0.9.8: no version information available (required by nmap)
nmap: /usr/local/zenoss/common/lib/libcrypto.so.0.9.8: no version information available (required by nmap)
Invalid target host specification:
QUITTING!
uptime.sh: line 7: UpCheck: command not found
uptime.sh: line 11: unexpected EOF while looking for matching ``'
uptime.sh: line 13: syntax error: unexpected end of file
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64476#64476]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-10 15:11:53 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64454#64454

--------------------------------------------------------------
The 'no version information available' is kinda normal, I get it too because Ubuntu took something out of a package that they should not have.  It is trivial and can be ignored.  The real hiccup for you is "invalid target host specification"

How are you running the script?  you have to give it a parameter for the IP so $1 will have a value.

For example, if you named your script:  DoNMAP.sh

you have to run it with "DoNMAP.sh 192.168.0.1" (or your IP), this way the IP address will be put in $TheIP within the script.

I can help you with the scripting, if I am busy with something urgent at the office, it just means it will take longer, but I will assist as best I can.

Also make sure you do not mix the ' and the `, they look awful alike but bash needs them at the right places.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64454#64454]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 06:31:51 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64492#64492

--------------------------------------------------------------
Okay so this is what I have.

In Zenoss I have a data source (uptime) which is a command source, then a data point (data).

If I edit the data source I have changed nothing expect setting the parser to nagios.I do not even know if that is correct?

Then under the data point I have under create command:

cd /bin
uptime.sh ${manageIp}

And then I have a graph that points to the data point.

Now I have played with the script and got everthing to the point it prints out the following:

***@monitor:/bin# bash uptime.sh ??.??.??.??
uptime.sh: line 7: UpCheck: command not found
uptime.sh: line 9: PortCheck: command not found
uptime.sh: line 11: Latency: command not found

Shouldn't there be something that outputs data from the script ? Or is that all the code I need in the script ?

Kind Regards,
Stefan
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64492#64492]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 06:51:10 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64493#64493

--------------------------------------------------------------
Okay got it to run without any errors, but also no output data. So that is probably the next step :)

***@monitor:/bin# bash uptime.sh ??.??.??.??
***@monitor:/bin#
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64493#64493]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 09:20:57 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64494#64494

--------------------------------------------------------------
Okay I updated my script, so that it reports a 1 value when the port is detected as open.

Ignore all the echo's, was just some testing.

#!/bin/bash


TheIP=$1
Up=0
Open="open"


TheRaw=`nmap -PN -p 2003 "$TheIP"`


UpCheck=`echo "$TheRaw" | grep 'Host is up' | wc -l`


PortCheck=`echo "$TheRaw" | grep '2003/tcp' | awk '{print $2}'`


Latency=`echo "$TheRaw" | grep 'latency' | awk -F '(' '{print $2}' | awk -F 's' '{print $1}'`


echo "Up: $Up"
echo "UpCheck: $UpCheck"
echo "PortCheck: $PortCheck"
echo "Latency: $Latency"


if [ $PortCheck = $Open ];
then
        Up=1
fi


data=$Up


echo "test: $data"


echo "Up after update: $Up"


Now I need to get this data into a graph :) And I have no idea how to get that going, where to point the value etc.

Without you, I would have not gotten this far. ta :D
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64494#64494]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 12:13:15 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64495#64495

--------------------------------------------------------------
Okay, I looked through the forums and found this and replaced with my value:

TheResult="Datasource|Datapoint1="$Up
echo $TheResult
exit $ExitVal

I then deleted my datapoint and added Datapoint1 under my data source that has the following information:

Parser:
Nagios

Command Template:
/bin/uptime.sh ${dev/manageIp}

So I can insert a test ip and everything works, but I assume it executes under the zenoss user and not root.

Under root, it pulls the correct value (using the terminal), but once I change to the zenoss user it always gives the value 0.

Any idea what this can be ? Trying to keep you up to date with my progress once you return :p
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64495#64495]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 14:22:51 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64512#64512

--------------------------------------------------------------
***@monitor:/bin$ nmap -v -sS -PN -p 2003 ??.??.??.??

nmap: /usr/local/zenoss/common/lib/libssl.so.0.9.8: no version information available (required by nmap)
nmap: /usr/local/zenoss/common/lib/libcrypto.so.0.9.8: no version information available (required by nmap)

You requested a scan type which requires root privileges.

So this is where I got to. And that is the scan type needed to check the data I want to, do you know where I can change the privileges fo the scan type ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64512#64512]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-13 14:35:25 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64504#64504

--------------------------------------------------------------
the -sS tag requires root, use only the tags you need, also more tags mean more bandwidth in the scan, which you are trying to avoid.  Use the least amount of tags that you need to get the data required.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64504#64504]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-13 14:47:10 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64513#64513

--------------------------------------------------------------
Is there anyway I can use -sS, because that is the only wat to get data back from the device. Tag -sT reports the device down/port closed which it is not. So I will need to force -sS, but it requires root privilages.

Any ideas ?
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64513#64513]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-13 14:55:25 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64506#64506

--------------------------------------------------------------
Does a simple nmap -p 2003 <ip address> work?

On my test machine, the above command gives me the open/close status of port 2003.

If not, you can start playing with the sudoer file, there are ways to tell a user that he can use this or that application with sudo privileges, but that is a whole chapter in itself.

Another option would be for you to run a script as a cron job every 5 minutes, this way you could have it run with root privileges, and have that script write the output to a file, then your command datasource would just read the file data.  Would not be very elegant but sould work if you absolutely need root privileges and don't want to dive in the sudoer file modification.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64506#64506]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-14 06:11:34 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64516#64516

--------------------------------------------------------------
Without the -PN, it reports the device as offline. With -PN (Always online) I can see if the port is open or filtered, so I do need that unfortunatly.

I geuss it is off to the sudoer file, but isn't there a way to incoperate the sudo command when it executes the command template ?

I have tried adding it in the command template, but that doesn't seem to work.
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64516#64516]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-14 07:46:15 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64517#64517

--------------------------------------------------------------
I have this under my sudoers file:



# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset


# Host alias specification


# User alias specification


User_Alias     ADMINS = zenoss


# Cmnd alias specification


zenoss ALL = NOPASSWD: /bin/nmap, /usr/share/nmap, /usr/lib/nmap


# User privilege specification
root    ALL=(ALL:ALL) ALL
%zenoss  ALL=(ALL:ALL) ALL


# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
zenoss ALL = NOPASSWD: ALL
ADMINS ALL = NOPASSWD: ALL


# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

Still I get:

You requested a scan type which requires root privileges.
QUITTING!

And that is the only scan technique that works :(
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64517#64517]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-14 09:29:18 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64518#64518

--------------------------------------------------------------
Okay, so I am almost at the end. When I run the command like this, everything works:

bash -x uptime.sh ??.??.??.??

***@monitor:/usr/local/zenoss/zenoss$ bash -x uptime.sh ??.??.??.??
+ TheIP=??.??.??.??
+ Up=0
+ Open=open
++ sudo nmap -PN -p 2003 ??.??.??.??
+ TheRaw='
Starting Nmap 5.21 ( http://nmap.org http://nmap.org ) at 2012-02-14 11:22 SAST
Nmap scan report for ??.??.??.?? (??.??.??.??)
Host is up (1.3s latency).
PORT     STATE SERVICE
2003/tcp open  finger


Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds'
+ echo
++ echo '
Starting Nmap 5.21 ( http://nmap.org http://nmap.org ) at 2012-02-14 11:22 SAST
Nmap scan report for ??.??.??.?? (??.??.??.??)
Host is up (1.3s latency).
PORT     STATE SERVICE
2003/tcp open  finger


Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds'
++ grep 'Host is up'
++ wc -l
+ UpCheck=1
++ echo '
Starting Nmap 5.21 ( http://nmap.org http://nmap.org ) at 2012-02-14 11:22 SAST
Nmap scan report for ??.??.??.?? (??.??.??.??)
Host is up (1.3s latency).
PORT     STATE SERVICE
2003/tcp open  finger


Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds'
++ grep 2003/tcp
++ awk '{print $2}'
+ PortCheck=open
++ echo '
Starting Nmap 5.21 ( http://nmap.org http://nmap.org ) at 2012-02-14 11:22 SAST
Nmap scan report for ??.??.??.?? (??.??.??.??)
Host is up (1.3s latency).
PORT     STATE SERVICE
2003/tcp open  finger


Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds'
++ grep latency
++ awk -F '(' '{print $2}'
++ awk -F s '{print $1}'
+ Latency=1.3
+ echo 'Up: 0'
Up: 0
+ echo 'UpCheck: 1'
UpCheck: 1
+ echo 'PortCheck: open'
PortCheck: open
+ echo 'Latency: 1.3'
Latency: 1.3
+ '[' open = open ']'
+ Up=1
+ echo 'test: '
test:
+ echo 'Up after update: 1'
Up after update: 1
+ TheResult='Datasource|Datapoint1=1'
+ echo 'Datasource|Datapoint1=1'
Datasource|Datapoint1=1
+ exit


But when I run the script on its own with this command, I get this:

***@monitor:/usr/local/zenoss/zenoss$ uptime.sh ??.??.??.??
nmap: /usr/local/zenoss/common/lib/libssl.so.0.9.8: no version information available (required by nmap)
nmap: /usr/local/zenoss/common/lib/libcrypto.so.0.9.8: no version information available (required by nmap)
Up: 0
UpCheck: 1
PortCheck: filtered
Latency:
test:
Up after update: 0
Datasource|Datapoint1=0

And that is with the same IP. My brain doesn't understand this weirdness
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64518#64518]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Stefan Reinke
2012-02-14 12:03:49 UTC
Permalink
Stefan Reinke [http://community.zenoss.org/people/Stefan] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64519#64519

--------------------------------------------------------------
Everything is working now!

Thanks for all your help Manuel ! :D
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64519#64519]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
themactech
2012-02-13 14:41:05 UTC
Permalink
themactech [http://community.zenoss.org/people/themactech] created the discussion

"Re: Check device status with Telnet"

To view the discussion, visit: http://community.zenoss.org/message/64505#64505

--------------------------------------------------------------
If all you want is your exit value and your portcheck datapoint, you can make it easier to get with:

ExitVal=`echo "$TheRaw" | grep '2003/tcp' | grep 'close' | wc -l`

PortVal=`echo "$TheRaw" | grep '2003/tcp' | grep 'open' | wc -l`

ExitVal will be zero if the port is open, one if the port is closed, so that works great for an exit value
PortVal will be 1 of the port is open and zero if the port is closed, so that will graph well

You won't have to put a threshold, just set your command datasource severity to what you want, the exit value will trigger that severity and alert.

Manuel
--------------------------------------------------------------

Reply to this message by replying to this email -or- go to the discussion on Zenoss Community
[http://community.zenoss.org/message/64505#64505]

Start a new discussion in zenoss-users by email
[discussions-community-forums-zenoss--***@community.zenoss.org] -or- at Zenoss Community
[http://community.zenoss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2003]
Loading...