|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--nsjc
Name: nsjc - Nagios Java Client
This is the companion piece that goes with nsjsd Nagios Java Server).
The nsjc is the client that connects to the nsjsd and will report to the service
the status of a test. It is yet another application that is meant to enhance the
passive service reporting capability of the Nagios application. I wrote these
objects because I was frustrated with not being able to report status of my NT
boxes to my host server which was FreeBSD. I don't want to criticise the efforts
of those developers who spent time developing those applications which plug into
Nagios and help server information back to the server, it's just that for some
reason, I couldn't get them to work. Not being an expert in BSD and C programming
I decided to write something myself that I could control and understand.
Besides the frustration of trying to get the NT reporting software to work with my
systems, I do have some unique requirements. Not only do I have a mixed environment
of NT systems but I also have to worry about Novell server's as well. I haven't seen
anything out there that works with Novell, with the exception of the Perl scripts.
I could have used the perl scripts for reporting the Passive Service information but
again, I decided to work with something that I knew (and besides I'm finishing up
my Data Structures and Algorithms class in Java and took this as a challenge). So
I've written these objects with the intent that not only could they be used as
standalone pieces but they can also be reused in other Java applications and
applets as is.
Goal:
The goal of this project is to provide a set of reusable objects that can either be
incorporated into another application or can be used standalone via the command line.
Component Strategy:
The nsjsd listens on a set of ports and will only accept connections from specific
ip addresses and on specific ports (see the nsjsd code header). The nsjc will
attempt to connect to the server running the nsjsd on a specific port. Once it connects
it will attempt to send status information on a specific test. This status information
will then be sent to the Nagios command file, for Nagios to process. This means
your test information must be configured properly in the Nagios configuration files
(see the Nagios documentation for details).
Object Architecture:
This object holds several internal variables. These variables include host, test name,
test results, test comments, port, and thread timeout values. The host indicates which
server to connect to, the port is which port to connect on. The test information is
the information that is sent to the server and placed in the Nagios command file.
The thread timeout value is the time in milliseconds that the code will wait for
the object to complete it's communication with the server. You do not have to set
the thread timeout value, as it defaults to 5000 milliseconds. The port defaults to 27000.
If run from the command line the object will first attempt to parse the command line
arguments. Note that the port and thread timeout values are optional. Once the command
line arguments are interpreted it will instantiate a new nsjc object and then call the
send method. The send method launches a new thread then waits for that thread to
complete. It will only wait the time set by the timeout value, so if you have a slow
network and the component is timing out, you may want to up this value. However
5 seconds is probably more than enough.
If run inside another application then you'll want to instantiate the nsjc object
using one of the constructor methods, there are three. One constructor allows
you to set the host, port, timeout, and test data upon instantiation. The other
two constructors allow you build the nsjc object without port or without the timeout
value. Once the object has been instantiate then call the send method. The send
method will return a boolean which will notify the caller of it's success.
Notes:
Currently you have to instantiate the object with all the necessary data. The
instance variables are all private and can't be changed after object instantiation.
(At least in this version.) There is also a setting that will allow the programmer
to stop command line output. By default if this object is run from the command line
it will print output, however you can instantiate the object with command line output
off.
Comments:
Please keep in mind that these are very basic components
and that this is my first attempt at writing a client/server applet in Java.
License:
The is application is freely distributed. I only ask that if you incorporate or reuse
any of these components you make mention of where you got them from and my email address.
Nagios is a registered trademark of Ethan Galstad.
Field Summary | |
static int |
DEFAULT_PORT
Port used if no other port is passed into the object. Value is 27000. |
static long |
THREAD_TIMEOUT_DEFAULT
Default thread timeout in milliseconds. Value is 5000. |
Constructor Summary | |
nsjc(java.lang.String strHost,
int intPort,
java.lang.String strTest,
int intStatus,
java.lang.String strData,
boolean boolPrintStatus)
Name: nsjc Desc: Constructor to instantiate and initialize the object. |
|
nsjc(java.lang.String strHost,
int intPort,
java.lang.String strTest,
int intStatus,
java.lang.String strData,
long lngThreadTimeout,
boolean boolPrintStatus)
Name: nsjc Desc: Constructor to instantiate and initialize the object. |
|
nsjc(java.lang.String strHost,
java.lang.String strTest,
int intStatus,
java.lang.String strData,
boolean boolPrintStatus)
Name: nsjc Desc: Constructor to instantiate and initialize the object. |
Method Summary | |
static void |
main(java.lang.String[] args)
Name: main Desc: this is the main routine that will run when this object is instantiated via command line. |
void |
run()
Name: run Desc: this is the manditory run method, as this object implements Runnable. |
boolean |
send()
Name: send Desc: This method will instantiate a new thread and then waits for the thread. |
static void |
usage()
Name: usage Desc: this method is called when the 'main' method has problems interpreting the command line arguments or perceives an error in them. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_PORT
public static final long THREAD_TIMEOUT_DEFAULT
Constructor Detail |
public nsjc(java.lang.String strHost, java.lang.String strTest, int intStatus, java.lang.String strData, boolean boolPrintStatus)
strHost
- -> String, the host name you want to connect to (could be an ip address)strTest
- -> String, the name of the test (should match the test name in the Nagios config file)intStatus
- -> Must be either -1 UNKNOWN, 0 OK, 1 WARNING, or 2 CRITICALstrData
- -> String, extra data to send regarding the testboolPrintStatus
- -> boolean, true will print status information to the command line.public nsjc(java.lang.String strHost, int intPort, java.lang.String strTest, int intStatus, java.lang.String strData, boolean boolPrintStatus)
strHost
- -> String, the host name you want to connect to (could be an ip address)intPort
- -> int, the port to connect to on the hoststrTest
- -> String, the name of the test (should match the test name in the Nagios config file)intStatus
- -> Must be either -1 UNKNOWN, 0 OK, 1 WARNING, or 2 CRITICALstrData
- -> String, extra data to send regarding the testboolPrintStatus
- -> boolean, true will print status information to the command line.public nsjc(java.lang.String strHost, int intPort, java.lang.String strTest, int intStatus, java.lang.String strData, long lngThreadTimeout, boolean boolPrintStatus)
strHost
- -> String, the host name you want to connect to (could be an ip address)intPort
- -> int, the port to connect to on the hoststrTest
- -> String, the name of the test (should match the test name in the Nagios config file)intStatus
- -> Must be either -1 UNKNOWN, 0 OK, 1 WARNING, or 2 CRITICALstrData
- -> String, extra data to send regarding the testlngThreadTimeout
- -> long, the time in milliseconds for the code to wait for the thread to completeboolPrintStatus
- -> boolean, true will print status information to the command line.Method Detail |
public void run()
run
in interface java.lang.Runnable
public static void usage()
public static void main(java.lang.String[] args)
args
- -> an array of strings which hold the command line arguments. It must
have at least four arguments for this routine to run. (Of course the arugments
must be valid too.)public boolean send()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |