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
/
snmp_back.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-10
|
3KB
|
159 lines
/*
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 "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; /*time left*/
struct timeval time_interval; /*time default*/
};
void snmp_usage()
{
fprintf(stderr,"\nusage: snmp: start");
}
main(int argc,char *argv[])
{
struct snbentry test;
char *action;
struct ObjectType *First,*ObjPtr;
int i;
char Hostname[50];
char Obj_name[50];
FILE *var_file;
long time_interval;
int firsttime;
int Current_Value;
if (argc != 2)
snmp_usage();
action=argv[1];
if (strcmp(action,"start"))
exit(0);
printf("\n %s", action);
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;
};
do {
printf("\n sleep");
system("sleep 5");
printf("\n awake");
ObjPtr=First;
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******************************************************");
printf("\n hostname: %s: ",ObjPtr->Hostname);
printf("Obj_name: %s\n",ObjPtr->Obj_Name);
printf("\n Current:%d, Diff:%d ",Current_Value,ObjPtr->Diff_Value);
printf("(in %d second)\n",ObjPtr->time_interval.tv_sec);
}
else {
ObjPtr->time_left.tv_sec=ObjPtr->time_left.tv_sec - 5;
}
ObjPtr=ObjPtr->Next;
}
} while (1);
}