La necesidad de esta implementacion ha sido por que no existen plugins para la monitorizacion de subversion y bacula en nagios ( o almenos no he encontrado ninguno ), luego he visto que existe check_tcp que de momento ya me vale :)

Lo que hace el programa es intentar conectar a un puerto de una ip y si lo consigue imaginamos que el servicio esta funcionando.

[sourcecode='delphi']
program check_port;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, Sockets, SysUtils

{ you can add units after this };
Var
Addr : TInetSockAddr;
S : Longint;
Sin,Sout : Text;
tmp: String;

begin
if ((ParamStr(1)='') or (ParamStr(2)='')) then
begin
Writeln('ERROR - Numero de parametros incorrectos');
Writeln('Debes escribir ip puerto');
exit;
end;

S:=fpSocket(AF_INET,SOCK_STREAM,0);
if SocketError>0 then
writeln('Socket Error ' + IntToStr(SocketError));

Addr.sin_family:=AF_INET;
Addr.sin_addr := StrToNetAddr(ParamStr(1));
Addr.sin_port:=htons(StrToInt(ParamStr(2)));

If Not Connect (S,ADDR,SIN,SOUT) Then
tmp := 'Error '
else
tmp := 'Exito ';

WriteLn(tmp + 'en la conexion con ' + ParamStr(1) + ' al puerto ' + ParamStr(2));

end.
[/sourcecode]

La funcion Connect esta deprecated pero como el nagios ya trae por defecto el plugin check_tcp tampoco era plan de perder invertir mas tiempo

Tags

  • freepascal
  • red

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
8 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.