nxshell gives Request timed out

Started by Borgso, July 29, 2015, 09:45:05 AM

Previous topic - Next topic

Borgso

I have a nxshell script that takes linux formated hosts (/etc/hosts) list and adds it as nodes.
When after running it ok 2 times i get "Request timed out" on 3th run.
Then i need to wait xx minutes before i get it to work again.

Do the script open a connection and then not closing it proper so i need to wait for some timeout?

Script:
#!/usr/bin/python
#
# 2015-07-29 - EspenGB - Working 1.2.17
# Usage:
# $0 hostname
# * Ex: $0 node.netxms.tld

# $0 hostfile(/etc/hostname)
# * Ex: $0 /etc/hosts

# $0 hostname/hostfile containerId
# * Ex: $0 /etc/hosts 1234

import sys, socket, os, string, re

if len(sys.argv) < 2:
    print >>sys.stderr, 'Usage: ' + sys.argv[0] + ' <file/host> [<containerId>]'
    sys.exit(1)
   
name = sys.argv[1]

def addNode(name):
    try:
        test = socket.inet_aton(name)
        host_ip = name
    except socket.error:
        try:
            host_ip = socket.gethostbyname(name)
        except socket.error:
            host_ip = "0.0.0.0"

    if sys.argv[2]:
containerId = int(sys.argv[2])
    else:
        if sys.argv[0] == "nxshell_test":
            containerId = int(5636)
        else:
            containerId = int(5636)
    flags = NXCObjectCreationData.CF_DISABLE_NXCP | \
            NXCObjectCreationData.CF_DISABLE_SNMP
   
    cd = NXCObjectCreationData(objects.GenericObject.OBJECT_NODE, name, containerId);
    cd.setCreationFlags(flags);
    cd.setPrimaryName(host_ip) # Create node with IP address
    nodeId = session.createObject(cd)
    print " * Added {0} to containerID: {1}".format(name, containerId)
   
def is_valid_ip(ip):
    m = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip)
    return bool(m) and all(map(lambda n: 0 <= int(n) <= 255, m.groups()))

if os.path.isfile(name):
    print "File found: "
    for names in open(name).readlines():
hostnames = re.split(r'\s+', names)
host_ip = hostnames[0].strip()
host_name = hostnames[1].strip()
if is_valid_ip(host_ip):
    print "Add: '" + host_ip + "' '" + host_name + "'"
            addNode(host_name.strip());
else:
    print "Add: " + name.strip()
    addNode(name.strip());

Victor Kirhenshtein

Hi,

event if connection is not closed properly connection limit is way bigger than 2. What is in server log (on debug level 6 or higher) when you try to connect for 3rd time?

Best regards,
Victor