/** * Adds a remote class volume. */ void cvolcm_AddClassVolume( pwr_tStatus* sts, gdb_sNode* np, const net_sGvolume* vp) { gdb_sCclassVolume *ccvp, *rp; gdb_sVolume* cvp; gdb_AssumeLocked; pwr_Assert(vp != NULL); ccvp = pool_Alloc(sts, gdbroot->pool, sizeof(*ccvp)); if (ccvp == NULL) return; ccvp->key.nid = vp->nid; ccvp->key.vid = vp->vid; ccvp->time = net_NetTimeToTime(&vp->time); cvp = hash_Search(sts, gdbroot->vid_ht, &vp->vid); if (cvp == NULL) /* This volume doesn't exist locally, but we may create it later on */ ccvp->equalClasses = 0; else { pwr_tTime t = net_NetTimeToTime(&cvp->g.time); ccvp->equalClasses = time_Acomp(&ccvp->time, &t) == 0 ? 1 : 0; } rp = hash_Insert(sts, gdbroot->ccvol_ht, ccvp); if (rp == NULL) { /* This was previously a bugcheck but obviously can occur */ pool_Free(NULL, gdbroot->pool, ccvp); return; } pool_QinsertPred(NULL, gdbroot->pool, &ccvp->ccvol_ll, &np->ccvol_lh); }
void printMsgInfo ( mh_sMsgInfo *mp, FILE *outFile ) { char time_str[40]; pwr_tTime event_time; col_print(outFile, "%d", mp->Id.Nix); event_time = net_NetTimeToTime(&(mp->Id.BirthTime)); time_AtoAscii(&event_time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); col_print(outFile, "%s", time_str); col_print(outFile, "%d",mp->Id.Idx); /* sp->Object sp->SupObject */ printEventFlags(outFile, mp->EventFlags); event_time = net_NetTimeToTime(&(mp->EventTime)); time_AtoAscii( &event_time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); col_print(outFile, "%s", time_str); // col_print(outFile, "%s",mp->EventName_V3); convertEventType(mp->EventType, time_str); col_print(outFile, "%s", time_str); convertEventPrio(mp->EventPrio, time_str); col_print(outFile, "%s",time_str); }
void rt_post::format_email_text( mh_sMessage *MsgP, char *text, unsigned int size) { ala_uEvent *event = (ala_uEvent *) MsgP; char prio[2]; pwr_tTime etime; char timstr[40]; switch ( event->Info.EventPrio) { case mh_eEventPrio_A: strcpy( prio, "A"); break; case mh_eEventPrio_B: strcpy( prio, "B"); break; case mh_eEventPrio_C: strcpy( prio, "C"); break; case mh_eEventPrio_D: strcpy( prio, "D"); break; default: strcpy( prio, "?"); } etime = net_NetTimeToTime( &event->Info.EventTime); time_AtoAscii( &etime, time_eFormat_DateAndTime, timstr, sizeof(timstr)); snprintf( text, size, "Proview alarm from node %s\nPriority %s\nEvent time %s\n\nEvent text: %s\nEvent name: %s", nodename, prio, timstr, event->Msg.EventText, event->Msg.EventName); }
void printRet ( sEvent *sp, FILE *outFile ) { char time_str[40]; new_row( outFile); printMsgInfo(&(sp->Mess.ret.Info), outFile); pwr_tTime event_time; //EventText //Status //TargetIdx //DetectTime //AValue //CtrlLimit //Hysteres //Unit //DValue //High col_print(outFile, "\"%s\"", sp->Mess.ret.EventText); col_print(outFile, "%s", sp->Mess.ret.EventName); col_print(outFile, "%u", sp->Mess.ret.TargetId.Idx); event_time = net_NetTimeToTime(&(sp->Mess.ret.DetectTime)); time_AtoAscii( &event_time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); col_print(outFile, "%s", time_str); switch (sp->Mess.ret.SupInfo.SupType) { case mh_eSupType_Analog: col_print(outFile, "%.2f", sp->Mess.ret.SupInfo.mh_uSupInfo_u.A.ActualValue); col_print(outFile, "%.2f", sp->Mess.ret.SupInfo.mh_uSupInfo_u.A.CtrlLimit); col_print(outFile, "%.2f", sp->Mess.ret.SupInfo.mh_uSupInfo_u.A.Hysteres); col_print(outFile, "%s", sp->Mess.ret.SupInfo.mh_uSupInfo_u.A.Unit); col_print(outFile,""); col_print(outFile, "%u", sp->Mess.ret.SupInfo.mh_uSupInfo_u.A.High); break; case mh_eSupType_Digital: col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); col_print(outFile, "%u", sp->Mess.ret.SupInfo.mh_uSupInfo_u.D.ActualValue); col_print(outFile, "%u", sp->Mess.ret.SupInfo.mh_uSupInfo_u.D.High); break; case mh_eSupType__: case mh_eSupType_None: case mh_eSupType_Link: case mh_eSupType_: break; } }
/** * Adds a remote class volume. */ void cvolcm_AddClassVolume( pwr_tStatus *sts, gdb_sNode *np, const net_sGvolume *vp ) { gdb_sCclassVolume *ccvp; gdb_sVolume *cvp; gdb_AssumeLocked; pwr_Assert(vp != NULL); ccvp = pool_Alloc(sts, gdbroot->pool, sizeof(*ccvp)); if (ccvp == NULL) return; ccvp->key.nid = vp->nid; ccvp->key.vid = vp->vid; ccvp->time = net_NetTimeToTime(&vp->time); cvp = hash_Search(sts, gdbroot->vid_ht, &vp->vid); if (cvp == NULL) /* This volume doesn't exist locally, but we may create it later on */ ccvp->equalClasses = 0; else { pwr_tTime t = net_NetTimeToTime( &cvp->g.time); ccvp->equalClasses = time_Acomp(&ccvp->time, &t) == 0 ? 1 : 0; } ccvp = hash_Insert(sts, gdbroot->ccvol_ht, ccvp); if (ccvp == NULL) errh_Bugcheck(GDH__WEIRD, "adding cached class volume"); pool_QinsertPred(NULL, gdbroot->pool, &ccvp->ccvol_ll, &np->ccvol_lh); }
sEvent * CopyEvent ( mh_sMsgInfo *ip ) { sEvent *sp; mh_sMessage *mp = (mh_sMessage*) ip; mh_sAck *ap = (mh_sAck*) ip; mh_sReturn *rp = (mh_sReturn*) ip; mh_sBlock *bp = (mh_sBlock*) ip; sp = malloc(sizeof(sEvent)); sp->EventType = ip->EventType; sp->EventTime = net_NetTimeToTime( &ip->EventTime); switch (ip->EventType) { case mh_eEvent_Alarm: case mh_eEvent_MaintenanceAlarm: case mh_eEvent_SystemAlarm: case mh_eEvent_UserAlarm1: case mh_eEvent_UserAlarm2: case mh_eEvent_UserAlarm3: case mh_eEvent_UserAlarm4: case mh_eEvent_Info: case mh_eEvent_InfoSuccess: sp->Mess.message = *mp; break; case mh_eEvent_Ack: sp->Mess.ack = *ap; break; case mh_eEvent_Cancel: case mh_eEvent_Return: sp->Mess.ret = *rp; break; case mh_eEvent_Block: case mh_eEvent_Unblock: case mh_eEvent_Reblock: case mh_eEvent_CancelBlock: sp->Mess.block = *bp; break; default: Log("rt_elog: Error in CopyEvent unknown EventType"); break; } return sp; }
/* Inserts an event into the DBs cache. */ static pwr_tStatus Insert ( mh_sMsgInfo *ip ) { sEvent *sp; char msg[80]; pwr_tInt32 ret; sKey eventKey; DBT key, data; /*copy the event into the struct that is to be stored*/ sp = CopyEvent(ip); /*clear the DBT-structs for future avoidance of errors(if DB is upgraded)*/ memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); eventKey.Id = ip->Id; eventKey.EventTime = net_NetTimeToTime( &ip->EventTime); /* copy the data do the DBT-structs*/ key.data = (void *)&eventKey; key.size = sizeof(sKey); data.data = (void *)sp; data.size = sizeof(sEvent); switch(ret = dataBaseP->put(dataBaseP, NULL, &key, &data, DB_NOOVERWRITE)) { case 0: /*everything is good*/ nrOfInsertsSinceLastTime++; break; case DB_KEYEXIST: /*data elready stored*/ break; default: /*error storing the event in DB send errormess to errh*/ sprintf(msg, "dbp->put: %s, no mess stored", db_strerror(ret)); Log(msg); break; } free(sp); return MH__SUCCESS; }
void printBlock ( sEvent *sp, FILE *outFile ) { char time_str[40]; pwr_tTime event_time; new_row( outFile); printMsgInfo(&(sp->Mess.block.Info), outFile); //EventText //Status //TargetIdx //DetectTime //AValue //CtrlLimit //Hysteres //Unit //DValue //High col_print(outFile, "\"\""); col_print(outFile, "%s", sp->Mess.block.EventName); col_print(outFile, "%u", sp->Mess.block.TargetId.Idx); event_time = net_NetTimeToTime( &(sp->Mess.block.DetectTime)); time_AtoAscii(&event_time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); col_print(outFile, "%s", time_str); col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); col_print(outFile,""); }
JNIEXPORT jobject JNICALL Java_jpwr_rt_Mh_outunitAck (JNIEnv *env, jclass obj, jobject id) { int sts = 1; //char *str; char *str_copy; mh_sEventId eventId; jfieldID nix_fid; jfieldID idx_fid; jfieldID birthTime_fid; jclass mhrsEventId_class; pwr_tTime t; jclass pwrtStatus_id = NULL; static jmethodID pwrtStatus_cid = NULL; jint jsts; jobject return_obj; jstring jstr; pwrtStatus_id = (*env)->FindClass( env, "jpwr/rt/PwrtStatus"); if(pwrtStatus_id == NULL) { printf("fel vid PwrtStatus classidhämtning\n"); return NULL; } if(pwrtStatus_cid == NULL) { //hämta upp classid och sedan pekare till konstruktorn för PwrtStatus pwrtStatus_cid = (*env)->GetMethodID( env, pwrtStatus_id, "<init>", "(I)V"); if(pwrtStatus_cid == NULL) { printf("fel vid PwrtStatus methodidhämtning\n"); return NULL; } } //hämta upp classid till MhrsEventId-objektet mhrsEventId_class =(*env)->GetObjectClass(env,id); nix_fid =(*env)->GetFieldID(env,mhrsEventId_class,"nix", "I"); if (nix_fid ==NULL) { printf("hittade inte nix\n"); sts = -2;//lyckades inte hitta fältet } //printf("efter nix hämtning\n"); idx_fid =(*env)->GetFieldID(env,mhrsEventId_class,"idx", "I"); if (idx_fid ==NULL) { printf("hittade inte idx\n"); sts = -2;//lyckades inte hitta fältet } //printf("efter idx hämtning\n"); birthTime_fid =(*env)->GetFieldID(env,mhrsEventId_class,"birthTime", "Ljava/lang/String;"); if (birthTime_fid ==NULL) { printf("hittade inte birthTime\n"); sts = -2;//lyckades inte hitta fältet } eventId.Nix = (pwr_tNodeIndex)(*env)->GetIntField(env,id,nix_fid); eventId.Idx = (pwr_tUInt32)(*env)->GetIntField(env,id,idx_fid); jstr = (*env)->GetObjectField(env,id,birthTime_fid); str_copy = (char *)(*env)->GetStringUTFChars(env,jstr,NULL); if (str_copy ==NULL) { sts = -1;//out of memory } t = net_NetTimeToTime( &eventId.BirthTime); time_AsciiToA(str_copy, &t); sts = mh_OutunitAck(&eventId); (*env)->ReleaseStringUTFChars(env,jstr,str_copy); jsts = (jint) sts; //skapa returobjekt return_obj = (*env)->NewObject( env, pwrtStatus_id, pwrtStatus_cid, jsts); (*env)->DeleteLocalRef(env,pwrtStatus_id); return return_obj; }
pwr_tStatus ev_mh_info_bc( mh_sMessage *MsgP) { JNIEnv *env; jclass PwrtObjid_id; jmethodID PwrtObjid_cid; jobject objid_obj = NULL; jstring jevText; jstring jevName; jstring jevTime; jstring jevBirthTime; jint jevFlags; jint jevPrio; jint jevStatus; jint jevNix; jint jevIdx; jint jevType; jint oix, vid; jstring jevTargetBirthTime; jint jevTargetNix = (jint) 0; jint jevTargetIdx = (jint) 0; char time_str[40]; char birthTime_str[40]; pwr_tObjid objid = MsgP->Object.Objid; pwr_tTime time = net_NetTimeToTime( &MsgP->Info.EventTime); pwr_tTime birthTime = net_NetTimeToTime( &MsgP->Info.Id.BirthTime); //hämta enviormentpekaren (*jvm)->AttachCurrentThread(jvm,(void **)&env,NULL); if(env == NULL) printf("env är null"); PwrtObjid_id = (*env)->FindClass( env, "jpwr/rt/PwrtObjid"); PwrtObjid_cid = (*env)->GetMethodID( env, PwrtObjid_id, "<init>", "(II)V"); oix = (jint) objid.oix; vid = (jint) objid.vid; objid_obj = (*env)->NewObject( env, PwrtObjid_id, PwrtObjid_cid, oix, vid); time_AtoAscii( &time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); time_AtoAscii( &birthTime, time_eFormat_ComprDateAndTime, birthTime_str, sizeof(birthTime_str)); //gör om till Java-strängar jevText = (*env)->NewStringUTF( env, MsgP->EventText); jevName = (*env)->NewStringUTF( env, MsgP->EventName); jevTime = (*env)->NewStringUTF( env, time_str); jevBirthTime = (*env)->NewStringUTF( env, birthTime_str); jevTargetBirthTime = (*env)->NewStringUTF( env, " "); //gör om till Java-int jevFlags = (jint)MsgP->Info.EventFlags; jevPrio = (jint)MsgP->Info.EventPrio; jevStatus = (jint)MsgP->Status; jevNix = (jint)MsgP->Info.Id.Nix; jevIdx = (jint)MsgP->Info.Id.Idx; jevType = (jint)MsgP->Info.EventType; //anropa callback metoden i Mh-klassen (*env)->CallStaticVoidMethod( env, Mh_id, Mh_messReceived_id, jevText, jevName, jevTime, jevFlags, jevPrio, jevStatus, jevNix, jevBirthTime, jevIdx, jevTargetNix, jevTargetBirthTime, jevTargetIdx, jevType, objid_obj); //important:check if an exception was raised if ((*env)->ExceptionCheck(env)) { printf("exception i info\n"); return 1; } return 1; }
pwr_tStatus rt_post::mh_alarm_bc( mh_sMessage *MsgP) { ala_uEvent *event = (ala_uEvent *) MsgP; int sts; char str[256]; char user[80]; char group[80]; char *s; pwr_tTime etime, current; pwr_tDeltaTime diff; int rcvnum; char rcv_array[10][80]; char text[400]; if ( !post || post->conf->Disable) return 1; if ( !event->Info.EventFlags & pwr_mEventFlagsMask_Email || !event->Info.EventFlags & pwr_mEventFlagsMask_SMS) return 1; // Skip events older than 10 minutes etime = net_NetTimeToTime( &event->Info.EventTime); time_GetTime( ¤t); time_Adiff( &diff, ¤t, &etime); if ( time_DToFloat( 0, &diff) > 600) return 1; // Check if already handled if ( event->Info.EventFlags & pwr_mEventFlagsMask_Email) { if ( post->email_check( &event->Info.Id)) return 1; else post->email_register( &event->Info.Id); } if ( event->Info.EventFlags & pwr_mEventFlagsMask_SMS) { if ( post->sms_check( &event->Info.Id)) return 1; else post->sms_register( &event->Info.Id); } post->replace_symbol( str, event->Msg.Receiver); rcvnum = dcli_parse( str, ",", "", (char *) rcv_array, sizeof( rcv_array)/sizeof( rcv_array[0]), sizeof( rcv_array[0]), 0); for ( int i = 0; i < rcvnum; i++) { dcli_trim( str, rcv_array[i]); s = strrchr( str, '.'); if ( s) { *s = 0; strncpy( group, post->systemgroup, sizeof(group)); strncat( group, ".", sizeof(group)); strncat( group, str, sizeof(group)); strncpy( user, s+1, sizeof(user)); } else { strncpy( group, post->systemgroup, sizeof(group)); strncpy( user, str, sizeof(user)); } SystemName *sn = new SystemName( group); sts = sn->parse(); if ( EVEN(sts)) { delete sn; errh_Error( "Post systemgroup parse error, %m", sts); continue; } SystemList *sl = post->udb->find_system( sn); delete sn; if ( !sl) { errh_Error( "No such system group, %s", group); continue; } UserList *ul = (UserList *) sl->find_user( user); if ( !ul) { errh_Error( "No such user, %s", user); continue; } if ( event->Info.EventFlags & pwr_mEventFlagsMask_Email && strcmp( post->conf->EmailCmd, "") != 0) { char address[40]; pwr_tCmd cmd; ul->get_email( address, sizeof(address)); post->format_email_text( MsgP, text, sizeof(text)); post->format_cmd( cmd, post->conf->EmailCmd, address, text); if ( post->conf->Options & pwr_mPostOptionsMask_Log) errh_Info( "Email: %s", cmd); system( cmd); post->conf->SentEmail++; } if ( event->Info.EventFlags & pwr_mEventFlagsMask_SMS && strcmp( post->conf->SMS_Cmd, "") != 0) { char sms[40]; pwr_tCmd cmd; ul->get_sms( sms, sizeof(sms)); post->format_sms_text( MsgP, text, sizeof(text)); post->format_cmd( cmd, post->conf->SMS_Cmd, sms, text); if ( post->conf->Options & pwr_mPostOptionsMask_Log) errh_Info( "SMS: %s", cmd); system( cmd); post->conf->SentSMS++; } } return 1; }
/** Handle GetCclass message */ void cmvolsm_GetCclass ( qcom_sGet *get ) { pwr_tStatus sts; pwr_tStatus lsts; int size; net_sGetCclassR *rmp = NULL; net_sGetCclass *mp = get->data; qcom_sPut put; gdb_sAttribute *ap; net_sCattribute *cap; gdb_sClass *cp; gdb_sObject *cop; int i; pwr_tBoolean equal = FALSE; const int maxacnt = ((net_cSizeLarge - sizeof(*rmp)) / sizeof(rmp->attr[0])) + 1; int maxaidx; int acnt; pwr_tTime mp_time; gdb_AssumeUnlocked; gdb_ScopeLock { cp = hash_Search(&sts, gdbroot->cid_ht, &mp->cid); if (cp == NULL) break; cop = pool_Address(NULL, gdbroot->pool, cp->cor); mp_time = net_NetTimeToTime(&mp->time); if (time_Acomp(&mp_time, &cop->u.n.time) == 0) { equal = TRUE; size = sizeof(*rmp); } else { acnt = MIN(maxacnt, cp->acount - mp->aidx); maxaidx = acnt + mp->aidx; size = sizeof(*rmp) + MAX(0, (acnt - 1)) * sizeof(rmp->attr[0]); } rmp = net_Alloc(&sts, &put, size, net_eMsg_getCclassR); if (rmp == NULL) { errh_Error("cmvolsm_GetCclass. net_Alloc, size %d, cid %d, error %m", size, mp->cid, sts); break; } rmp->ver = net_cVersion; rmp->sts = 1; rmp->equal = equal; if (equal) { rmp->acntmsg = 0; rmp->cclass.size = 0; rmp->cclass.acount = 0; break; } rmp->cclass.cid = mp->cid; rmp->cclass.time = net_TimeToNetTime(&cop->u.n.time); rmp->cclass.size = cp->size; rmp->cclass.acount = cp->acount; for (i = mp->aidx, ap = &cp->attr[mp->aidx], cap = rmp->attr; i < maxaidx; i++, ap++, cap++ ) { cap->aix = ap->aix; cap->flags = ap->flags; cap->type = ap->type; cap->offs = ap->offs; cap->size = ap->size; cap->elem = ap->elem; cap->moffset = ap->moffset; } rmp->acntmsg = acnt; rmp->saidx = mp->aidx; rmp->naidx = (i == cp->acount) ? UINT_MAX : i; } gdb_ScopeUnlock; if (EVEN(sts)) { rmp = net_Alloc(&lsts, &put, sizeof(*rmp), net_eMsg_getCclassR); if (EVEN(lsts)) { errh_Error("cmvolsm_GetCclass. net_Alloc, size %d, cid %d, error %m", sizeof(*rmp), mp->cid, lsts); return; } rmp->ver = net_cVersion; } if (EVEN(sts)) rmp->sts = sts; else rmp->sts = 1; net_Reply(&lsts, get, &put, 0); }