Hi James,
On Mon, 26 Nov 2012 18:44:48 -0800, James <kfc.android at gmail.com> wrote:
The reason why I want to modify Xymon is because I'm working on a small class project which only need a simple networking-related function (in my case: ping) with minimal size of code. [snip] My optimal goal is: to use minimal amount of code to perform a ping test, but keep the framework and style of Xymon. (Now I'm reading Xymonping.c file under /xymonnet folder)
I think those are somewhat conflicting goals; keeping a Xymon style "framework" will require more work than what is really necessary for a "small class project".
My guess is that the primary focus of your project is to show that you understand some network programming, rather than prove that you understand the details of Xymon - although I would be personally flattered if Xymon became mandatory teaching :-)
My advice to you would be:
Is it a requirement to use ping as the network test, or could you use a TCP connection as the network test ? ping is a bit complicated, because the normal network programming API's don't support it directly - you have to more or less construct the contents of each packet yourself. The socket API in Unix (or Winsock on Windows) have much better support for a normal transport-layer protocol - TCP - so that would allow you to show that you understand network programming, rather then getting bogged down with the details of ICMP packet request/response formats.
If you are allowed to use normal TCP connections for your network test, try writing some code using the Unix socket API and non-blocking sockets. I.e. you need to use the socket(), connect(), select(), read(), write() and close() API's - plus the various little details of getting all the data structures setup correctly. There must be lots of sample code for this - not least the "select_tut(2)" man-page in Linux - but for Xymon code look at lib/sendmsg.c the "sendtoxymond()" routine, or xymonnet/contest.c file "do_tcp_tests()". The first one is good to understand the basics, because it does one connection at a time; the xymonnet/contest.c code is a bit more complicated, because it juggles multiple connections at once. With TCP, you can use a connection to e.g. port 80 (web) or some other port - possibly something user-configurable on a per-host basis.
If you must use ping, then xymonping.c borrows heavily from fping, so have a look at that code as well.
Once you know how to check if you can connect/ping a host, then you can decide what the configuration file should be like, and how the test results can be reported. If you want something "xymon-like", then perhaps you can just generate a simple webpage listing the test result, so it gets updated whenever your test-program runs.
Regards, Henrik
PS: I know this does go a bit off-topic for the Xymon list, but we've all had to learn things at some point. So I'm just trying to guide the newbies in the right direction :-)