188 lines
4.5 KiB
C
188 lines
4.5 KiB
C
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
#include <sys/time.h>
|
|||
|
#include <stdarg.h>
|
|||
|
#include <ver.h>
|
|||
|
#define ND_MODE 1
|
|||
|
#include <node.h>
|
|||
|
#define LOG_MODE 1
|
|||
|
#include <log.h>
|
|||
|
|
|||
|
VER_INFO_EXPORT (logresolve, "$Revision: 1.1 $", "$Name: $", __FILE__, "$Author: smas $")
|
|||
|
|
|||
|
typedef struct {
|
|||
|
double sec;
|
|||
|
struct timeval start;
|
|||
|
struct timeval stop;
|
|||
|
} cpt;
|
|||
|
|
|||
|
#define t_start(x){gettimeofday (&(x.start), NULL);}
|
|||
|
#define t_stop(x){gettimeofday (&(x.stop), NULL); x.sec = (double)(x.stop.tv_sec) - (double)(x.start.tv_sec) + \
|
|||
|
((double)(x.stop.tv_usec) - (double)(x.start.tv_usec)) / 1000000;}
|
|||
|
cpt t_exec;
|
|||
|
|
|||
|
char * Get_Rooting (LOGT_Rooting);
|
|||
|
char * Get_RC (LOGT_RC);
|
|||
|
|
|||
|
#define USAGE "Usage : %s [ --help | --version [-v] | --event <event name> ]\n"
|
|||
|
|
|||
|
int main (int argc, char **argv)
|
|||
|
{
|
|||
|
LOGT_Info * Info;
|
|||
|
char * Event;
|
|||
|
int i;
|
|||
|
|
|||
|
if (argc >= 2)
|
|||
|
{
|
|||
|
if (!strcmp (argv [1], "--help"))
|
|||
|
{
|
|||
|
fprintf (stderr, USAGE, argv [0]);
|
|||
|
return 1;
|
|||
|
}
|
|||
|
else if (!strcmp (argv [1], "--version"))
|
|||
|
{
|
|||
|
if (argc >= 3 && !strcmp (argv [2], "-v"))
|
|||
|
return VER_Object_Print (stdout, VERD_VERBOSE);
|
|||
|
else
|
|||
|
return VER_Object_Print (stdout, VERD_MINIMAL);
|
|||
|
}
|
|||
|
else if (!strcmp (argv [1], "--event"))
|
|||
|
{
|
|||
|
if (argc != 3)
|
|||
|
{
|
|||
|
fprintf (stderr, USAGE, argv [0]);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
Event = argv [2];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
fprintf (stderr, USAGE, argv [0]);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
fprintf (stderr, USAGE, argv [0]);
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* R<>cup<75>ration des informations sur un <20>v<EFBFBD>nement */
|
|||
|
|
|||
|
Info = (LOGT_Info *) malloc (sizeof (LOGT_Info));
|
|||
|
|
|||
|
if (LOG_Library_Open (0, NULL, LOGD_OPEN | LOGD_DEBUG_ALL) != LOGS_OK)
|
|||
|
{
|
|||
|
fprintf (stderr, "=> Ouverture de la librairie LIBLOG impossible\n");
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
t_start (t_exec);
|
|||
|
|
|||
|
if (LOG_Event_Info_Get (NULL, &Info, Event) != LOGS_OK)
|
|||
|
{
|
|||
|
t_stop (t_exec);
|
|||
|
fprintf (stderr, "=> Impossible de r<>soudre l'<27>v<EFBFBD>nement \"%s\"\n", Event);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
NDT_Node * Node;
|
|||
|
|
|||
|
t_stop (t_exec);
|
|||
|
fprintf (stdout, "\nEv<EFBFBD>nement \"%s\" r<>solu en %.4f sec :\n", Event, t_exec.sec);
|
|||
|
fprintf (stdout, "\t- Type : %s (Id=%d)\n", Info->Event_Name, Info->Event_Type);
|
|||
|
fprintf (stdout, "\t- Routage : %s\n", Get_Rooting (Info->Rooting));
|
|||
|
fprintf (stdout, "\t- Gravit<69> : %c\n", (char)Info->Gravite);
|
|||
|
fprintf (stdout, "\t- Code retour : %s\n", Get_RC (Info->RC));
|
|||
|
fprintf (stdout, "\t- Format :");
|
|||
|
if (Info->Data_List)
|
|||
|
{
|
|||
|
ND_Node_First_Get (Info->Data_List, &Node);
|
|||
|
i = 0;
|
|||
|
while (Node)
|
|||
|
{
|
|||
|
if (i > 0) fprintf (stdout, ",");
|
|||
|
fprintf (stdout, " %s", (char *)(Node->Value));
|
|||
|
ND_Node_Next_Get (Node, &Node);
|
|||
|
i++;
|
|||
|
}
|
|||
|
}
|
|||
|
fprintf (stdout, "\n\n");
|
|||
|
}
|
|||
|
|
|||
|
LOG_Library_Close (LOGD_CLOSE);
|
|||
|
|
|||
|
free (Info);
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
char * Get_Rooting (LOGT_Rooting Rooting)
|
|||
|
{
|
|||
|
static char lib [20];
|
|||
|
|
|||
|
switch ((int)Rooting)
|
|||
|
{
|
|||
|
case LOGD_ROOTING_NULL:
|
|||
|
strcpy (lib, "NULL");
|
|||
|
break;
|
|||
|
case LOGD_ROOTING_STDERR:
|
|||
|
strcpy (lib, "STDERR");
|
|||
|
break;
|
|||
|
case LOGD_ROOTING_DATABASE:
|
|||
|
strcpy (lib, "BASE");
|
|||
|
break;
|
|||
|
case LOGD_ROOTING_DEFAULT:
|
|||
|
strcpy (lib, "DEFAULT");
|
|||
|
break;
|
|||
|
case LOGD_ROOTING_PREVIOUS:
|
|||
|
strcpy (lib, "PREVIOUS");
|
|||
|
break;
|
|||
|
default:
|
|||
|
strcpy (lib, "unknown");
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
return lib;
|
|||
|
}
|
|||
|
|
|||
|
char * Get_RC (LOGT_RC RC)
|
|||
|
{
|
|||
|
static char lib [20];
|
|||
|
|
|||
|
switch ((int)RC)
|
|||
|
{
|
|||
|
case LOGD_RC_OK:
|
|||
|
strcpy (lib, "OK");
|
|||
|
break;
|
|||
|
case LOGD_RC_ANOERR:
|
|||
|
strcpy (lib, "ANOERR");
|
|||
|
break;
|
|||
|
case LOGD_RC_REJDON:
|
|||
|
strcpy (lib, "REJDON");
|
|||
|
break;
|
|||
|
case LOGD_RC_REJENR:
|
|||
|
strcpy (lib, "REJENR");
|
|||
|
break;
|
|||
|
case LOGD_RC_WARNING:
|
|||
|
strcpy (lib, "WARNING");
|
|||
|
break;
|
|||
|
case LOGD_RC_RECYCLE:
|
|||
|
strcpy (lib, "RECYCLE");
|
|||
|
break;
|
|||
|
case LOGD_RC_EXIT:
|
|||
|
strcpy (lib, "EXIT");
|
|||
|
break;
|
|||
|
case LOGD_RC_ABEND:
|
|||
|
strcpy (lib, "ABEND");
|
|||
|
break;
|
|||
|
default:
|
|||
|
strcpy (lib, "unknown");
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
return lib;
|
|||
|
}
|