コード例 #1
0
ファイル: domain.c プロジェクト: openhpi1/testrepo
int add_domain(SaHpiDomainIdT did)
{
        struct oh_domain *d;
        
        if (did>MAX_GLOBAL_DOMAIN) {
                dbg("Could not add so large domain, the region is kept for dymanic domain");
                return -1;
        }
        if(is_in_domain_list(did) > 0) {
                dbg("Domain %d exists already, something is fishy", did);
                return -1;
        }
        
        data_access_lock();
        
        d = malloc(sizeof(*d));
        if (!d) {
                dbg("Out of memory");
                data_access_unlock();
                return -1;
        }
        
        d->domain_id = did;
        d->sel = oh_sel_create(OH_SEL_MAX_SIZE);
 
        global_domain_list = g_slist_append(global_domain_list, d);

        data_access_unlock();
        
        return 0;
}
コード例 #2
0
ファイル: sel_test_001.c プロジェクト: openhpi1/testrepo
/**
 * main: SEL test
 * 
 * This test tests the creation of an SEL.
 * 
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv) 
{
        oh_sel *sel;
        
        sel = oh_sel_create(5);
        
        if(sel == NULL) {
                dbg("ERROR: sel pointer == NULL.");
                return 1;
        }
        
        if(sel->enabled != TRUE) {
                dbg("ERROR: sel->enabled invalid.");
                return 1;
        }
        
        if(sel->overflow != FALSE) {
                dbg("ERROR: sel->overflow invalid.");
                return 1;
        }
        
        if(sel->deletesupported != FALSE) {
                dbg("ERROR: sel->deletesupported invalid.");
                return 1;
        }
        
        if(sel->lastUpdate != SAHPI_TIME_UNSPECIFIED) {
                dbg("ERROR: sel->lastUpdate invalid.");
                return 1;
        }
        
        if(sel->offset != 0) {
                dbg("ERROR: sel->offset invalid.");
                return 1;
        }
        
        if(sel->nextId != SAHPI_OLDEST_ENTRY + 1) {
                dbg("ERROR: sel->nextId invalid.");
                return 1;
        }
        
        if(sel->maxsize != 5) {
                dbg("ERROR: sel->maxsize invalid.");
                return 1;
        }
        
        if(sel->selentries != NULL) {
                dbg("ERROR: sel->selentries invalid.");
                return 1;
        }
        
        return 0;
}
コード例 #3
0
ファイル: sel_test_003.c プロジェクト: CSU-GH/okl4_3.0
/**
 * main: SEL test
 * 
 * This test tests creates an SEL and adds five events.
 * It then save the SEL to a file.
 * 
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv) 
{
        oh_sel *sel;
        int x;
        SaErrorT retc;
        
        /* create the SEL */
        sel = oh_sel_create();
        
        if(sel == NULL) {
                dbg("ERROR: sel == NULL.");
                return 1;
        }

        /* add a multiple events */
        for (x = 0; x < 5; x++) {
                retc = add_event(sel, x);
                if (retc != SA_OK) {
                        dbg("ERROR: add_event failed.");
                        return 1;
                }
        }

        /* save the SEL */
        retc = oh_sel_map_to_file(sel, "./selTest.data");
        if (retc != SA_OK) {
                dbg("ERROR: oh_sel_map_to_file failed.");
                return 1;
        }

        /* close the sel */
        retc = oh_sel_close(sel);
        if (retc != SA_OK) {
                dbg("ERROR: oh_sel_close failed.");
                return 1;
        }

        
        return 0;
}
コード例 #4
0
ファイル: sel_test_004.c プロジェクト: openhpi1/testrepo
/**
 * main: SEL test
 * 
 * This test tests creates an SEL and adds five events.
 * It then save the SEL to a file.
 * 
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv) 
{
        oh_sel *sel;
        SaErrorT retc;
        
        /* create the SEL */
        sel = oh_sel_create(OH_SELTEST_MAX_ENTRIES);
        
        if(sel == NULL) {
                dbg("ERROR: sel == NULL.");
                return 1;
        }

        /* get SEL from file with invalid filename */
        retc = oh_sel_map_from_file(sel, NULL);
        if (retc != SA_ERR_HPI_INVALID_PARAMS) {
                dbg("ERROR: oh_sel_map_from_file failed with invalid filename.");
                return 1;
        }

        /* get SEL from file */
        retc = oh_sel_map_from_file(sel, "./selTest.data");
        if (retc != SA_OK) {
                dbg("ERROR: oh_sel_map_from_file failed.");
                return 1;
        }

        /* check out the SEL */
        if(sel->enabled != TRUE) {
                dbg("ERROR: sel->enabled invalid.");
                return 1;
        }
        
        if(sel->overflow != FALSE) {
                dbg("ERROR: sel->overflow invalid.");
                return 1;
        }
        
        if(sel->deletesupported != FALSE) {
                dbg("ERROR: sel->deletesupported invalid.");
                return 1;
        }
        
        if(sel->lastUpdate == SAHPI_TIME_UNSPECIFIED) {
                dbg("ERROR: sel->lastUpdate invalid.");
                return 1;
        }
        
        if(sel->offset != 0) {
                dbg("ERROR: sel->offset invalid.");
                return 1;
        }
        
        /* note: if sel_test_003.c changes this test may need to change */
        if(sel->nextId < OH_SELTEST_MAX_ENTRIES) {
                dbg("ERROR: sel->nextId invalid.");
                return 1;
        }
        
        if(sel->maxsize != OH_SELTEST_MAX_ENTRIES) {
                dbg("ERROR: sel->maxsize invalid.");
                return 1;
        }
        
        if(sel->selentries == NULL) {
                dbg("ERROR: sel->selentries invalid.");
                return 1;
        }

        /* close the sel */
        retc = oh_sel_close(sel);
        if (retc != SA_OK) {
                dbg("ERROR: oh_sel_close failed.");
                return 1;
        }

        
        return 0;
}
コード例 #5
0
ファイル: snmp_bc_session.c プロジェクト: openhpi1/testrepo
void *snmp_bc_open(GHashTable *handler_config)
{
    struct oh_handler_state *handle;
    struct snmp_bc_hnd *custom_handle;
    char *root_tuple;

    root_tuple = (char *)g_hash_table_lookup(handler_config, "entity_root");
    if(!root_tuple) {
        dbg("ERROR: Cannot open snmp_bc plugin. No entity root found in configuration.");
        return NULL;
    }

    handle = (struct oh_handler_state *)g_malloc0(sizeof(struct oh_handler_state));
    custom_handle =
        (struct snmp_bc_hnd *)g_malloc0(sizeof(struct snmp_bc_hnd));
    if(!handle || !custom_handle) {
        dbg("Could not allocate memory for handle or custom_handle.");
        return NULL;
    }
    handle->data = custom_handle;

    handle->config = handler_config;

    /* Initialize RPT cache */
    handle->rptcache = (RPTable *)g_malloc0(sizeof(RPTable));

    /* Initialize SEL cache */
    handle->selcache =  oh_sel_create(OH_SEL_MAX_SIZE);

    /* Initialize String-to-Event hash table */
    if (str2event_hash_init()) {
        dbg("Couldn't initialize str2event hash table.");
        return NULL;
    }

    /* Initialize BC_Event_Number-to-HPI_Event hash table */
    if (event2hpi_hash_init()) {
        dbg("Couldn't initialize event2hpi hash table.");
        return NULL;
    }

    /* Initialize snmp library */
    init_snmp("oh_snmp_bc");

    snmp_sess_init(&(custom_handle->session)); /* Setting up all defaults for now. */
    custom_handle->session.peername = (char *)g_hash_table_lookup(handle->config, "host");

    /* set the SNMP version number */
    custom_handle->session.version = SNMP_VERSION_1;

    /* set the SNMPv1 community name used for authentication */
    custom_handle->session.community = (char *)g_hash_table_lookup(handle->config, "community");
    custom_handle->session.community_len = strlen(custom_handle->session.community);

    /* windows32 specific net-snmp initialization (is a noop on unix) */
    SOCK_STARTUP;

    custom_handle->ss = snmp_open(&(custom_handle->session));

    if(!custom_handle->ss) {
        snmp_perror("ack");
        snmp_log(LOG_ERR, "something horrible happened!!!\n");
        dbg("Unable to open snmp session.");
        return NULL;
    }

    /* Set BladeCenter Type */
    {
        struct snmp_value  get_value;

        if ((snmp_get(custom_handle->ss, SNMP_BC_BLADECENTER_TYPE, &get_value) != 0) ||
                (get_value.type != ASN_OCTET_STR)) {
            dbg("SNMP could not read %s; Type=%d.\n",
                SNMP_BC_BLADECENTER_TYPE, get_value.type);
            return NULL;
        }

        if (!strcmp(get_value.string, SNMP_BC_BCE_MODEL)) {
            strcpy(bc_type, SNMP_BC_PLATFORM_BCE);
        }
        else if (!strcmp(get_value.string, SNMP_BC_BCT_MODEL_AC)) {
            strcpy(bc_type, SNMP_BC_PLATFORM_BCT);
        }
        else if (!strcmp(get_value.string, SNMP_BC_BCT_MODEL_DC)) {
            strcpy(bc_type, SNMP_BC_PLATFORM_BCT);
        }
        else {
            dbg("Unrecognized BladeCenter Type=%s.\n", get_value.string);
            return NULL;
        }
    }

    return handle;
}
コード例 #6
0
ファイル: snmp_bc_session.c プロジェクト: openhpi1/testrepo
void *snmp_bc_open(GHashTable *handler_config)
{
        struct oh_handler_state *handle;
        struct snmp_bc_hnd *custom_handle;
        char *hostname, *version, *sec_level, *authtype, *user, *pass, *community;
        char *root_tuple;
	SaErrorT rc;

        root_tuple = (char *)g_hash_table_lookup(handler_config, "entity_root");
        if(!root_tuple) {
                dbg("ERROR: Cannot open snmp_bc plugin. No entity root found in configuration.");
                return NULL;
        }

        hostname = (char *)g_hash_table_lookup(handler_config, "host");
        if (!hostname) {
                dbg("ERROR: Cannot open snmp_bc plugin. No hostname found in configuration.");
                return NULL;
        }

        handle = (struct oh_handler_state *)g_malloc0(sizeof(struct oh_handler_state));
        custom_handle =
                (struct snmp_bc_hnd *)g_malloc0(sizeof(struct snmp_bc_hnd));
        if(!handle || !custom_handle) {
                dbg("Could not allocate memory for handle or custom_handle.");
                return NULL;
        }

        handle->data = custom_handle;
        handle->config = handler_config;

        /* Initialize RPT cache */
        handle->rptcache = (RPTable *)g_malloc0(sizeof(RPTable));
 
        /* Initialize SEL cache */
        handle->selcache = oh_sel_create(OH_SEL_MAX_SIZE);
	handle->selcache->gentimestamp = FALSE;

	/* Initialize String-to-Event hash table */
	if (str2event_use_count == 0) {  
		if (str2event_hash_init()) {
			dbg("Couldn't initialize str2event hash table.");
			return NULL;
		}
		str2event_use_count++;
	} else 
		str2event_use_count++;
	
	/* Initialize BC_Event_Number-to-HPI_Event hash table */
	if (event2hpi_hash_init(handle)) {
		dbg("Couldn't initialize event2hpi hash table.");
		return NULL;
	}
       
	/* Initialize simulator tables */
	if (is_simulator()) {
		custom_handle->ss = NULL;
		sim_init();
	}
	else {
		/* Initialize snmp library */
		init_snmp("oh_snmp_bc");        
		snmp_sess_init(&(custom_handle->session)); /* Setting up all defaults for now. */
		/* Set snmp agent's hostname */
		custom_handle->session.peername = hostname;
							/* From testing with mm snmpv3 agent, */
		custom_handle->session.retries  = 3;	/* set retries to 3.                  */ 
							/* Number of uS until first timeout,  */
							/* then exponential backoff.          */
							/* Set timeout value to 2 secs.       */			
		custom_handle->session.timeout  = 2000000; 

		/* Get config parameters */
		version = (char *)g_hash_table_lookup(handle->config, "version");
		if (!version) {
			dbg("Cannot open snmp_bc. Need version configuration parameter.");
			return NULL;
		}
		sec_level = (char *)g_hash_table_lookup(handle->config, "security_level");
		authtype = (char *)g_hash_table_lookup(handle->config, "auth_type");
		user = (char *)g_hash_table_lookup(handle->config, "security_name");
		pass = (char *)g_hash_table_lookup(handle->config, "passphrase");
		community = (char *)g_hash_table_lookup(handle->config, "community");
		
		/* Configure snmp session */
		if (!strcmp(version,"3")) { /* if snmp version 3*/
			if (!user) {
				dbg("Cannot open snmp_bc. Need security_name configuration parameter.");
				return NULL;
			}
			custom_handle->session.version = SNMP_VERSION_3;
			custom_handle->session.securityName = user;
			custom_handle->session.securityNameLen = strlen(user);
			custom_handle->session.securityLevel = SNMP_SEC_LEVEL_NOAUTH;
			
			if (!strncmp(sec_level,"auth",4)) { /* if using password */
				if (!pass) {
					dbg("Cannot open snmp_bc. Need passphrase configuration parameter.");
					return NULL;
				}
				
				custom_handle->session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
				if (!authtype || !strcmp(authtype,"MD5")) {
					custom_handle->session.securityAuthProto = usmHMACMD5AuthProtocol;
					custom_handle->session.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
				} else if (!strcmp(authtype,"SHA")) {
					custom_handle->session.securityAuthProto = usmHMACSHA1AuthProtocol;
					custom_handle->session.securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
				} else {dbg("Cannot open snmp_bc. Wrong auth_type."); return NULL;}
				
				custom_handle->session.securityAuthKeyLen = USM_AUTH_KU_LEN;
				if (generate_Ku(custom_handle->session.securityAuthProto,
						custom_handle->session.securityAuthProtoLen,
						(u_char *) pass, strlen(pass),
						custom_handle->session.securityAuthKey,
						&(custom_handle->session.securityAuthKeyLen)) != SNMPERR_SUCCESS) {
					snmp_perror("snmp_bc");
					snmp_log(LOG_ERR,
						 "Error generating Ku from authentication passphrase.\n");
					dbg("Unable to establish snmp authnopriv session.");
					return NULL;
				}
				
				if (!strcmp(sec_level,"authPriv")) { /* if using encryption */
					custom_handle->session.securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
					custom_handle->session.securityPrivProto = usmDESPrivProtocol;
					custom_handle->session.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
					custom_handle->session.securityPrivKeyLen = USM_PRIV_KU_LEN;
					if (generate_Ku(custom_handle->session.securityAuthProto,
							custom_handle->session.securityAuthProtoLen,
							(u_char *) pass, strlen(pass),
							custom_handle->session.securityPrivKey,
							&(custom_handle->session.securityPrivKeyLen)) != SNMPERR_SUCCESS) {
						snmp_perror("snmp_bc");
						snmp_log(LOG_ERR,
							 "Error generating Ku from private passphrase.\n");
						dbg("Unable to establish snmp authpriv session.");
						return NULL;
					}
					
				}
			}                                
		} else if (!strcmp(version,"1")) { /* if using snmp version 1 */
			if (!community) {
				dbg("Cannot open snmp_bc. Need community configuration parameter.");
				return NULL;
			}
			custom_handle->session.version = SNMP_VERSION_1;
			custom_handle->session.community = community;
			custom_handle->session.community_len = strlen(community);
		} else {
			dbg("Cannot open snmp_bc. Unrecognized version parameter %s",version);
			return NULL;
		}
                
		/* windows32 specific net-snmp initialization (is a noop on unix) */
		SOCK_STARTUP;

		custom_handle->ss = snmp_open(&(custom_handle->session));

		if(!custom_handle->ss) {
			snmp_perror("ack");
			snmp_log(LOG_ERR, "something horrible happened!!!\n");
			dbg("Unable to open snmp session.");
			return NULL;
		}
	}

	/* Set BladeCenter Type */
	{
		struct snmp_value get_value;

		if (snmp_get(custom_handle->ss,SNMP_BC_TIME_DST,&get_value) == SA_OK) 
			strcpy(custom_handle->handler_timezone, get_value.string);
		else { 
		
			dbg("SNMP could not read BC DST %s; Type=%d.\n", 
			    SNMP_BC_TIME_DST, get_value.type);
			return NULL;
		}
		
		rc = snmp_get(custom_handle->ss, BC_TELCO_SYSTEM_HEALTH_STAT_OID, &get_value); 
		if (rc == SA_OK) {
			strcpy(custom_handle->bc_type, SNMP_BC_PLATFORM_BCT);
		} else if (( rc == SA_ERR_SNMP_NOSUCHOBJECT) || (rc == SA_ERR_SNMP_NOSUCHINSTANCE)) { 
			strcpy(custom_handle->bc_type, SNMP_BC_PLATFORM_BC);
		} else {		 

			dbg("SNMP could not read %s; Type=%d.\n", 
			    SNMP_BC_BLADECENTER_TYPE, get_value.type);
			return NULL;
		}

	}

	if (is_simulator) 
		sim_banner(custom_handle);
	

        return handle;
}