home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.umcs.maine.edu
/
2015-02-07.ftp.umcs.maine.edu.tar
/
ftp.umcs.maine.edu
/
pub
/
thesis
/
zhongy
/
snmp
/
start.c_back2
< prev
next >
Wrap
Text File
|
1994-05-19
|
4KB
|
182 lines
/*
This is a generalized snmp client package.
Following main program will do statistic on the MIB object defined
on VAR.TXT file.
This package will do statistic on "any" MIB object on "any host" on an
interval defined by user.
(Right now, this package only support the integer based MIB ogject: integer,
counter,timeticks,gauge,)
All MIB objects are defined in MIB.TXT file
programer: Zhong Yunxiang
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#include <setjmp.h>
#include <signal.h>
#include "asn1.h"
#include "snmp.h"
#include "snmparse.h"
#include "snmpencode.h"
#include "snmprint.h"
#include "snmpbasic.h"
struct ObjectType{
char Hostname[50];
char Obj_Name[50];
int Pre_Value;
int Diff_Value;
ObjectType *Next;
struct timeval time_left;
struct timeval time_interval;
};
void snmp_usage()
{
fprintf(stderr,"\nusage: snmp start");
}
void start()
{
struct snbentry test;
struct ObjectType *First,*ObjPtr;
int i;
char Hostname[50];
char Obj_name[50];
FILE *var_file;
long time_interval;
int firsttime;
int Current_Value;
NUM_MIBITEM=init_mib();
printf("\n num_mib_item:%d",NUM_MIBITEM);
/*
initialize database
*/
if ((var_file=fopen("VAR.TXT","r")) == NULL) {
printf("\n VAR.TXT can not be opened");
exit(0);
};
firsttime=1;
while (1) {
bzero(Hostname,sizeof(Hostname));
bzero(Obj_name,sizeof(Obj_name));
fscanf(var_file,"%s",Hostname);
if (!strcmp(Hostname,"END")){
break;
}
fscanf(var_file,"%s",Obj_name);
fscanf(var_file,"%d",&time_interval);
ObjPtr=new struct ObjectType;
strcpy(ObjPtr->Hostname,Hostname);
strcpy(ObjPtr->Obj_Name,Obj_name);
ObjPtr->time_interval.tv_sec=time_interval;
ObjPtr->time_left.tv_sec=time_interval;
if (firsttime ==0 ) {
ObjPtr->Next=First;
First=ObjPtr;
}
else {
firsttime=0;
ObjPtr->Next=NULL;
First=ObjPtr;
}
}
close(var_file);
/*
ObjPtr=First;
while (ObjPtr != NULL ) {
printf("\n %s",ObjPtr->Obj_Name);
ObjPtr=ObjPtr->Next;
};
*/
printf("\n initializing finished");
/*initialize the value in database
get the value first time
*/
ObjPtr=First;
while (ObjPtr != NULL ) {
test=get_value(ObjPtr->Obj_Name,ObjPtr->Hostname);
ObjPtr->Pre_Value=test.sb_val.sv_val.sv_int;
ObjPtr=ObjPtr->Next;
};
printf("\n\n wait 5 seconds\n\n");
system("sleep 5");
/*
do retrieve
*/
do {
/*
printf("\n awake");
*/
ObjPtr=First;
printf("\n Hostname Objname Current_val Diff Period");
printf("\n******************************************************************************");
while (ObjPtr != NULL ) {
if (ObjPtr->time_left.tv_sec == 0) {
test=get_value(ObjPtr->Obj_Name,ObjPtr->Hostname);
Current_Value=test.sb_val.sv_val.sv_int;
ObjPtr->Diff_Value=Current_Value - ObjPtr->Pre_Value;
ObjPtr->Pre_Value=Current_Value;
ObjPtr->time_left.tv_sec=ObjPtr->time_interval.tv_sec;
printf("\n%-25s",ObjPtr->Hostname);
printf(" %-20s",ObjPtr->Obj_Name);
printf("%-10d %-5d ",Current_Value,ObjPtr->Diff_Value);
printf(" %-4d",ObjPtr->time_interval.tv_sec);
printf("\n-----------------------------------------------------------------------------");
}
else {
ObjPtr->time_left.tv_sec=ObjPtr->time_left.tv_sec - 5;
}
ObjPtr=ObjPtr->Next;
}
printf("\n\n wait 5 seconds\n\n");
system("sleep 5");
} while (1);
}