Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - BlackMamba

#1
General Support / Reports
July 11, 2013, 01:57:51 PM
Hi to all!
I'm trying to understand how Reports work and i followed step by step this guide just to start.
The part "Steps to teach your server to generate reports" goes right or, at least, I don't get any error but then, when I try to generate a report, I get a compilation error. The output I get is:

XXX@YYY:~/Reports# "/usr/bin/java" -cp "/opt/netxms/java-lib/report-generator.jar" org.netxms.report.Generator "/etc/netxmsd.conf" "/opt/xml-reports/daily.jrxml" "/opt/reports/daily.output"
Error: Could not find or load main class org.netxms.report.Generator

What am I doing wrong? Could someone suggest me a solution?
#2
IT WORKS!!

I just had to set the flag "Allow the execution as a program" in the script->proprieties->permissions table!

Here are some tips for a configuration working on Xubuntu (or Debian based) and a perl script:
1) To set up the External Parameter follow this post. Remember the poll->configuration passage!
2) Once you set up your External Parameter, be sure that the script is allowed to run as a program (either by GUI or shell) and that your script starts with #!/usr/bin/perl.
3) Set up your DCI remembering that ending your script with "print 1;" will return an int and "print "ok";" will return a string.
4) Check always the right paths and if everything has the "sudo" permissions if you have to execute root operations.
5) It's possible to create multiple ExternalParameterShellExec. Just repeat the (1) point by appending the new parameters and then you can set up the DCI.
#3
Yes, I did.
Once edited the the agent configuration file, I configure the DCI for ProvaExternal, as you can see in the attachments ParameterSelection, ExternalParameterDCIProperties and DCIExternalParameter. I also run the agent in debug mode, attachments ExternalParameterDebug is bash's output I obtain. As I expected, the request is processed in the right way, but the script doesn't run.
In this post it's written:
Quote
Pay attention that in bash the value is returned using echo which in perl, this value is returned by printing out to the standard output. Do not use exit or return.

Pay attention... starting your script by /usr/bin/perl my_mon_script.pl will not call a bash... while ./my_mon_script.pl does! Taouw... as Homer says
I didn't understand well this two lines! If I want a return state I should use a print? If yes, will it be processed as a int or as a string? For example this two codes:
1) #!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;
print "ok";


2)
#!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;
print 0;

will be processed in the same way?
I'm on Xubuntu so I have to start my script using "#!/usr/bin/perl". But the post says I should start my script with ./NAME_OF_THE_FILE.pl? Should I set file's permissions to be executed as a program?
#4
Hi to all.
After configuring in the right way the ExternalParameterShellExec, here, I decided to run a test script and to collect the script's result using a DCI.
So, in my Data Collection Configuration I can set ProvaExternal as DCI collected by NetXMS Agent but the data type expected is different from the one I expect to obtain from the script (the script should return an int but Data Type in NetXMS is set as String). Anyway, this isn't the main issue. My script is written in perl. It should write a string on an hypothetical log file (already created) and, once the the file is closed, it should return an int but, opening the log file, I understood that nothing is written on the file. The standalone script works, I've tested it. My agent configuration file is:

MasterServers = XXX, YYY
EnableSubagentAutoload = yes
LogFile = /var/log/nxagentd.log
FileStore = /tmp
ListenAddress = 0.0.0.0
EnableActions = yes
SubAgent=portcheck.nsm

ExternalParameterShellExec=ProvaExternal:/PATH/WriteLog.pl


Instead, the script WriteLog.pl (now I'm trying without return value) is:

#!/usr/bin/perl
use Time::localtime;

open(LOG,">>", "/PATH/hdsl_monitoring_script.log");
print LOG ctime().":start test \n";
close LOG;

Still nothing written in "hdsl_monitoring_script.log". Any suggestions? What is going wrong?
#5
It worked! Thank you Alex! It was so easy, but here is explained without "=". I suggest you to modify that sticky topic, if it's possible, because it's really useful!
Thanks again!
#6
Hi to all!
I'm trying to set up the ExternalParameterShellExec in my NetXMS, but I'm having some issues in accomplish my goal. Before you ask, I already read this post and I followed the instructions in it, but I need help anyway.
First of all, I'm working on a test system, set up in this way:
1) A virtual machine, where NetXMS server and agent are installed.
2) A phisical local machine, where NetXMS consolle and agent are installed.
Just to test the ExternalParameterShellExec, I want to create a parameter in the phisical machine (2) which executes a Perl script. This script is very simple and executes a ls on the virtual machine using ssh. This is my perl script's code:

#!/usr/bin/perl

use Net::SSH::Perl;

my $host = "IP";
my $usr = "USER";
my $pwd = "PASSWORD";
my $ssh = Net::SSH::Perl->new($host);
my $command ="ls -l";
$ssh->login($usr,$pwd);
print+($ssh->cmd($command))[0], "\n";
__END__

This script works, I've tested it running it directly from unix shell in the local machine (2). So, as written in this post, i set up the local machine's agent to execute this script. Agent's config file is:

MasterServers = XXX, YYY
EnableSubagentAutoload = yes
LogFile = /var/log/nxagentd.log
FileStore = /tmp
ListenAddress = 0.0.0.0
EnableActions = yes
SubAgent=portcheck.nsm

ExternalParameterShellExec ProvaExternal:/PATH/ProvaSSH.pl

I execute the node's poll and then, in DCI, I expect to find ProvaExternal as parameter provided by the agent. But I can't find ProvaExternal anywhere in the DCI. What's the issue here? What am I doing wrong?

Thanks in advance for the help!
#7
General Support / Re: nxShell and jython
June 14, 2013, 12:01:30 PM
After this suggestion by Victor for a similar task, I solved the problem also in this script. The working code is:

#coding: utf-8

import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String

class XXX4:
def YYY(self):
listaNodi = []
listaNodi = session.getAllObjects()
          datiFile = open("PATH/Lettura.csv").readlines()
for nodo in listaNodi:
IPnodo = str(nodo.getPrimaryIP())
for riga in datiFile:
print "___________starts for on riga_____________\n"
print "riga: "+riga
for parola in riga.split():
print "parola: "+parola
if IPnodo ==parola:
print "Verified IPnodo = parola"
time.sleep(10)
for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
print "starts interface for "
interfaceName = interface.getObjectName()
ID = interface.getObjectId()
print "interfaceName: "+interfaceName
for parola1 in riga.split():
print "parola1: "+parola1
if interfaceName == parola1:
print "Verified interfaceName=parola1"
for parola2 in riga.split():
EndUserInfo = parola2
print "EndUserInfo after for: "+EndUserInfo
modificatore = NXCObjectModificationData(ID)
modifica = HashMap() # CHANGE 2
modifica.put("End user Info",EndUserInfo)
modificatore.setCustomAttributes(modifica)
                                                                        session.modifyObject(modificatore)
                                                                        time.sleep(10)

G = XXX4()
G.YYY()
#8
Thank you Victor! With one answer you solved two problems! Just in case anyone has the same problem I'll post the working code as example of both script:


# coding: utf-8

class SetPrimaryName:
def out(self):
i=0
PrimaryNames = open("PATH/TO/FILE/PRIMARYNAME.TXT").readlines()
for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY.TXT").readlines():
nodo = session.findObjectByName(nome.strip())
primaryName = PrimaryNames[i]
if nodo:
nodeID =nodo.getObjectId()
print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
modificatore = NXCObjectModificationData(nodeID)
modificatore.setPrimaryName(primaryName)
session.modifyObject(modificatore)
i+=1
spn = SetPrimaryName()
spn.out()


If you want to set custom attributes in already existing nodes, or if you want another example, you can find the script here.
#9
Hi to all!

I'm trying to create a script for nxShell which will allow me to set the primary name of some hosts in my network. Both primary name to set and hostnames to be modified are stored in two files. I created this script:

# coding: utf-8

class SetPrimaryName:
def out(self):
i=0
PrimaryNames = open("/PATH/TO/FILE/PRIMARYNAME").readlines()
for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY").readlines():
nodo = session.findObjectByName(nome.strip())
primaryName = PrimaryNames[i]
if nodo:
nodeID =nodo.getObjectId()
print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
modificatore = NXCObjectModificationData(nodeID)
print
modificatore.setPrimaryName(primaryName)
i+=1
spn = SetPrimaryName()
spn.out()


Everything works fine but nothing happens in NetXMS and the primary name of the selected hosts stays the same. Am I doing something wrong? My doubt is focused on "modificatore", because it's the second time I try to modify data already stored in NetXMS (does anyone remember my still unresolved problem posted here? ) but I'm unable to accomplish this goal.
Thanks in advance for the support!
#10
General Support / Re: nxShell and jython
June 03, 2013, 11:14:58 AM
Thank you Alex, but I'm still unable to set the custom attributes on the interface. I updated a little my script, because I have to read from a single file written in a certain way, and then I put your suggestions in it. The reading of the file works in the proper way and I don't get any error running the script, but the custom attributes are empty anyway. Here is my code:
#coding: utf-8

import csv
import time
from java.util import HashMap # CHANGE 1
from java.lang import String

class XXX4:
def YYY(self):
listaNodi = []
listaNodi = session.getAllObjects()
          datiFile = open("PATH/Lettura.csv").readlines()
for nodo in listaNodi:
IPnodo = str(nodo.getPrimaryIP())
for riga in datiFile:
print "___________starts for on riga_____________\n"
print "riga: "+riga
for parola in riga.split():
print "parola: "+parola
if IPnodo ==parola:
print "Verified IPnodo = parola"
time.sleep(10)
for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
print "starts interface for "
interfaceName = interface.getObjectName()
ID = interface.getObjectId()
print "interfaceName: "+interfaceName
for parola1 in riga.split():
print "parola1: "+parola1
if interfaceName == parola1:
print "Verified interfaceName=parola1"
for parola2 in riga.split():
EndUserInfo = parola2
print "EndUserInfo after for: "+EndUserInfo
modificatore = NXCObjectModificationData(ID)
modifica = HashMap() # CHANGE 2
modifica.put("End user Info",EndUserInfo)
modificatore.setCustomAttributes(modifica)
time.sleep(10)

G = XXX4()
G.YYY()


Any suggestion?

EDIT: I found out something interesting. I modified the script and my last lines of it now are:
                                                               for parola2 in riga.split():
EndUserInfo = str(parola2)
print "EndUserInfo dopo cilclo for: "+EndUserInfo
modificatore = NXCObjectModificationData(ID)
"""modifica = HashMap() # CHANGE 2
modifica.put("End User Info",EndUserInfo)
print "modifica: "+str(modifica)
modificatore.setCustomAttributes(modifica)"""
customAttributes = modificatore.getCustomAttributes()
print "customAttributes: "+str(customAttributes)
#customAttributes.put("End User Info",EndUserInfo)
#modificatore.setCustomAttributes(customAttributes)

My thought was that, instead of creating a new HasMap, I could get the existing one, supposed to be empty, and use the put metod on it. But the command   print "customAttributes: "+str(customAttributes) returns "none", which is the same result I get using the solution you suggested. Also, if I try to run customAttributes.put("End User Info",EndUserInfo) on the terminal I get:

customAttributes.put("End User Info",EndUserInfo)
AttributeError: 'NoneType' object has no attribute 'put'

It seems like modificatore.getCustomAttributes() is not a Map<String,String> object.
Help!
#11
General Support / nxShell and jython[Solved]
May 29, 2013, 02:15:06 PM
Hi to all!

I'm sorry if this is the wrong section, but I didn't know where I had to open this topic!

I'm starting using nxShell just how it is suggested in the wiki. I'm trying to create a script which will let me set a custom attribute (End User Info) on some interfaces in some map's nodes. My problem is the setting of the modification data. I understood that I should use a Map imported from java.util, but I'm new in python programming so I'm having problem in setting the Constructor of the Map in the right way. Once I run the script I get a "java.lang.ArrayIndexOutOfBoundsException: -3". Here is my code:

# coding: utf-8
import csv
import time
from java.util import Map
from java.lang import String
class XXX:
def YYY(self):
listaNodi = []
listaNodi = session.getAllObjects()
for nodo in listaNodi:
IPlista = nodo.getPrimaryIP()
#print "IPlista: "+str(IPlista)
for infoIP in open("RIGHT/PATH/IP.txt").readlines():
#print "infoIP: "+infoIP
#time.sleep(0.2)
if str(IPlista) == infoIP:
for interface in nodo.getAllChilds(objects.GenericObject.OBJECT_INTERFACE):
ID = interface.getObjectId()
IDinterfaccia=str(ID)
#print "IDinterfaccia: "+IDinterfaccia
for interfaccia in open("RIGHT/PATH/INTERFACCIA.TXT").readlines():
#print "interfaccia: "+str(interfaccia)
if IDinterfaccia == interfaccia:
print "Sono in IDinterfaccia == interfaccia"
info = open("RIGHT/PATH/EndUserInfo.txt").readlines()
#print "info: "+str(info)
modificatore = NXCObjectModificationData(ID)
#print "modificatore: "+str(modificatore)
Map<String,String> modifica = """new""" Map() # I SUPPOSE THE MISTAKE IS HERE!!!
modifica.put("End user Info",info)
#print "modifica: "+str(modifica)
modificatore = setCustomAttributes(modifica)
g = XXX()
g.YYY()

Could anyone help me to understand where is my mistake?
Thanks in advance!
#12
General Support / Re: Monitoring FTP daemon
May 22, 2013, 10:28:31 AM
Quote from: Victor Kirhenshtein on May 21, 2013, 10:02:19 PM
Hi!

You can use portcheck subagent to check that network service is actually responds. There is short documentation: http://wiki.netxms.org/wiki/Subagent:PortCheck. There are no FTP support, so you can only check that TCP connection can be established.

Yes, I did something similar. I just used ServiceCheck.Custom(IPserverFTP, 21) and the threshold is "=0". So, till I get 0 by the agent, the port 21 is open and then the service is up; once I get 1 the service is down and the alarm is raised.

Quote from: Victor Kirhenshtein on May 21, 2013, 10:02:19 PM
Another option is to define external parameter on one of the agents to connect and check FTP server. It could be something like this:


ExternalParameter = FTP.Status(*):echo quit | nc -q1 $1 21 | grep '^220 .*' | wc -l


After you add this line to nxagentd.conf and restart agent, it will provide new paraneter FTP.Status, which will take server DNS name or IP address as argument, and return 1 if 220 got in response, and 0 otherwise.

Best regards,
Victor

This solution is much smarter and works with the same logic of the first one. So, I'm twice happy: my ideas where right and I obtain also a better solution. Many thanks Victor!
#13
General Support / Re: Monitoring FTP daemon
May 21, 2013, 05:56:23 PM
I did it!
The answer to my question (1) is: Process.Count(vsftpd). Then I set the threshold to "=0" so the agent verifies the process count and if the daemon is stopped (or down for any reason) the DCI has 0 as value and the alarm is raised. I know that it isn't a very smart solution, but at least it works!
Unfortunately I didn't figure out a easier way. If someone would like to answer to my question (2), he is welcome!

Now I have another question. I'd like to verify not only that the daemon is running, but also that the service is working. To do this, I need to connect somehow to the FTP server and verify the reply I obtain after a login attempt. Or just read the answer of the connection attempt. Is it possible to do something like that using NetXMS, possibly using the agent in the local machine (the one where I also have the FTP daemon running)?
#14
General Support / Monitoring FTP daemon[Solved]
May 21, 2013, 01:43:42 PM
Hello everybody!

I'm a new NetXMS user (very noob) and I'm sorry if the question has been already made, but I was unable to find an answer.

My goal is to monitor a FTP daemon (in particular, I'm using vsftpd) using NetXMS. My configuration is:

a) NetXMS server+agent installed on a virtual machine with Debian and only with the command line
b) NetXMS agent installed on a local machine (Xubuntu) where I have my FTP daemon installed and which I use to connect to the NetXMS client through web interface or Management Console.

I have this strange configuration only because I'm testing my skills, and I'm trying to "learn" NetXMS.

So, I've tried to monitor the FTP daemon using similar passages of this tutorial http://wiki.netxms.org/wiki/How_to_send_e-mail_notification_when_disk_space_is_low but I haven't been able to set up the right value on Data-Parameter in the general voice of the DCI.
Now my questions are:
1) What should I put on the Parameter voice in the DCI configuration window?
2) Is there an easiest, or righter, method to monitor a FTP daemon? If yes, could someone please explain me this method?

Thanks to all for the support!