SshChecker.py only works for IPv4

Bug #1046221 reported by Anders Mundt Due
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Network Administration Visualized
Fix Released
Medium
Morten Brekkevold

Bug Description

If your host needs to be checked on IPv6 and not IPv4, NAV cannot do SSH Check due to SshChecker.py using:

    def execute(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(self.getAddress())

Following patch will make it be oportunistick and pick any available protocol, perhaps there should be an option to select what protocol should be used for a certain address family instead of it being this simple.

diff --git a/SshChecker.py b/SshChecker.py
index 261a488..d208190 100644
--- a/SshChecker.py
+++ b/SshChecker.py
@@ -26,9 +26,14 @@ class SshChecker(AbstractChecker):
     def __init__(self, service, **kwargs):
         AbstractChecker.__init__(self, "ssh", service, port=22, **kwargs)
     def execute(self):
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ (s_hostname,s_port)=self.getAddress()
+ addrinfolist = socket.getaddrinfo(s_hostname,s_port,0,0,socket.IPPROTO_TCP,0)
+ for hostsel in addrinfolist:
+ (s_family,s_socktype,s_proto,s_canonname,s_sockaddr) = hostsel
+ if s_family in [socket.AF_INET,socket.AF_INET6]: break
+ s = socket.socket(s_family, socket.SOCK_STREAM)
         s.settimeout(self.getTimeout())
- s.connect(self.getAddress())
+ s.connect(s_sockaddr)
         f = s.makefile('r+')
         version = f.readline().strip()
         try:

Changed in nav:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Hi Anders - we do recognize that this is in deed a defect, but your patch was garbled by Launchpad, since you just pasted it into the description field. Please upload the patch as an attachment to a comment instead.

Changed in nav:
status: Triaged → Confirmed
assignee: nobody → Morten Brekkevold (mbrekkevold)
Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Nevermind; I decided to check the e-mail notice Launchpad sent me, and the formatting remains intact there. Testing your patch now (and attaching it to this comment for future reference).

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Tested and found ok, accepted patch here: http://nav.uninett.no/hg/stable/rev/a0fe815437b7

BUT, the code for the SshChecker code in total was butt-ugly and had multiple pylint violations, so I did some cleaning here, afterwards: http://nav.uninett.no/hg/stable/rev/b0983a8145fe

Changed in nav:
status: Confirmed → Fix Committed
Changed in nav:
milestone: none → 3.12.1
Changed in nav:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.