Exemple #1
0
int main(int argc, char **argv)
{
        int c;
	oh_big_textbuffer bigbuf2;
        SaErrorT rv, rv_2;
        SaHpiVersionT hpiVer;
        SaHpiSessionIdT sessionid;
        
        /* Domain */
        SaHpiDomainInfoT domainInfo;

        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT rptentryid;
        SaHpiEntryIdT nextrptentryid;
        SaHpiResourceIdT resourceid;
        SaHpiEventLogEntryIdT entryid;
        SaHpiEventLogEntryIdT nextentryid;
        SaHpiEventLogEntryIdT preventryid;
        SaHpiEventLogInfoT info;
        SaHpiEventLogEntryT  el;
        SaHpiRdrT rdr, *rdrptr;
	SaHpiRptEntryT rpt_2nd, *rptptr;

        int free = 50;

        printf("%s: version %s\n",argv[0],progver);

        while ( (c = getopt( argc, argv,"cdpx?")) != EOF )
                switch(c) {
                case 'c': fclear = 1; break;
                case 'd': frdr   = 1; break;
                case 'p': frpt   = 1; break;				
                case 'x': fdebug = 1; break;
                default:
                        printf("\n\n\nUsage %s [-cdpx]\n",argv[0]);
			printf("    Where                             \n");
                        printf("        -c clears the event log\n");
			printf("        -d also get RDR with the event log\n");
			printf("        -p also get RPT with the event log\n");
                        printf("        -x displays eXtra debug messages\n\n\n");
                        exit(1);
                }
	
	
	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);
	
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv);
                else
                        printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv));
                exit(-1);
        }

        rv = saHpiDiscover(sessionid);
        if (fdebug) printf("saHpiResourcesDiscover %s\n", oh_lookup_error(rv));
	

        rv = saHpiDomainInfoGet(sessionid, &domainInfo);

        if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv));
        printf("DomainInfo: UpdateCount = %d, UpdateTime = %lx\n",
               domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp);

        /* walk the RPT list */
        rptentryid = SAHPI_FIRST_ENTRY;
        while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
	{
		rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);

		if (fdebug)
			printf("saHpiRptEntryGet %s\n", oh_lookup_error(rv));
			    
		if (rv == SA_OK) {
			resourceid = rptentry.ResourceId;
				    
			if (fdebug)
				printf("RPT %d capabilities = %x\n", resourceid,
						   rptentry.ResourceCapabilities);
				    
			if (!(rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) {
					    
				if (fdebug) printf("RPT doesn't have SEL\n");
				rptentryid = nextrptentryid;
				continue;  /* no SEL here, try next RPT */
			}
				    
			rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
	
			rv_2 = oh_init_bigtext(&bigbuf2);
			if (rv_2) return(rv_2);
			rv  = oh_decode_entitypath(&rptentry.ResourceEntity, &bigbuf2);
			printf("%s\n", bigbuf2.Data);
			printf("rptentry[%d] tag: %s\n", resourceid,rptentry.ResourceTag.Data);
				    
			/* initialize structure */
			info.Entries = 0;
			info.Size = 0;
			info.Enabled = 0;
				    
			rv_2 = saHpiEventLogInfoGet(sessionid,resourceid,&info);
			
			if (fdebug)
				printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv));
			if (rv_2 == SA_OK) {
				printf("EventLogInfo for %s, ResourceId %d\n",
						rptentry.ResourceTag.Data, resourceid);
				oh_print_eventloginfo(&info, 4);
			} else { 
				printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv_2));
			}
				    
			if (fclear) {
				rv = saHpiEventLogClear(sessionid,resourceid);
				if (rv == SA_OK)
					printf("EventLog successfully cleared\n");
				else
					printf("EventLog clear, error = %d, %s\n", rv, oh_lookup_error(rv));
				break;
			}
				    
			if (info.Entries != 0){
				entryid = SAHPI_OLDEST_ENTRY;
				while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES))
				{
				
					if (frdr) rdrptr = &rdr;
						else rdrptr = NULL;
					
					if (frpt) rptptr = &rpt_2nd;
						else rptptr = NULL;
						
						
					if(fdebug) printf("rdrptr %p, rptptr %p\n", rdrptr, rptptr);
					rv = saHpiEventLogEntryGet(sessionid,resourceid,
								entryid,&preventryid,
								&nextentryid, &el,rdrptr,rptptr);
								
					if (fdebug) printf("saHpiEventLogEntryGet %s\n",
							    			oh_lookup_error(rv));
								   
					if (rv == SA_OK) {
						oh_print_eventlogentry(&el, 6);
						if (frdr) {
							if (rdrptr->RdrType == SAHPI_NO_RECORD)
								printf("            No RDR associated with EventType =  %s\n\n", 
									 oh_lookup_eventtype(el.Event.EventType));
							else	
								oh_print_rdr(rdrptr, 12);
						}
						if (frpt) {
							if (rptptr->ResourceCapabilities == 0)
								printf("            No RPT associated with EventType =  %s\n\n", 
									 oh_lookup_eventtype(el.Event.EventType));							
							else 
								oh_print_rptentry(rptptr, 10);
						}

						preventryid = entryid;
						entryid = nextentryid;
					}
				}
				
			} else
				printf("\tSEL is empty.\n\n");
				    
			if (free < 6) {
				printf("WARNING: Log free space is very low (%d records)\n",free);
				printf("\tClear log with hpiel -c\n");
			}
		}		    
		rptentryid = nextrptentryid;
	}
	
	
	printf("done.\n");
        rv = saHpiSessionClose(sessionid);
	return(0);
}
Exemple #2
0
/* 
 * Main                
 */
int
main(int argc, char **argv)
{
	SaErrorT 	rv = SA_OK;
	
	SaHpiVersionT	hpiVer;
	SaHpiSessionIdT sessionid;
	SaHpiResourceIdT resourceid = all_resources;

	int c;
	    
	printf("\n\n%s ver %s\n",argv[0],progver);
	while ( (c = getopt( argc, argv,"adrsoiwcn:x?")) != EOF ) {
		switch(c) {
			case 'a': f_listall = 1; break;
			case 'c': f_ctrl    = 1; break;
			case 'd': f_rdr     = 1; break;
			case 'i': f_inv     = 1; break;
			case 'r': f_rpt     = 1; break;
			case 's': f_sensor  = 1; break; 
			case 'w': f_wdog    = 1; break;
			case 'o': f_overview = 1; break; 			 
			case 'n':
				if (optarg)
					resourceid = atoi(optarg);
				else 
					resourceid = all_resources;
				break;
			case 'x': fdebug = 1; break;
			default:
				printf("\n\tUsage: %s [-option]\n\n", progname);
				printf("\t      (No Option) Display all rpts and rdrs\n");
				printf("\t           -a     Display all rpts and rdrs\n");
				printf("\t           -c     Display only controls\n");
				printf("\t           -d     Display rdr records\n");
				printf("\t           -i     Display only inventories\n");
				printf("\t           -o     Display system overview: rpt & rdr headers\n");				
				printf("\t           -r     Display only rpts\n");
				printf("\t           -s     Display only sensors\n");
				printf("\t           -w     Display only watchdog\n");				
				printf("\t           -n     Select particular resource id to display\n");
				printf("\t                  (Used with [-cdirs] options)\n");
				printf("\t           -x     Display debug messages\n");
				printf("\n\n\n\n");
				exit(1);
		}
	}
 
	if (argc == 1) f_listall = 1;

	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);

	if (fdebug) printf("saHpiSessionOpen\n");
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
	if (rv != SA_OK) {
		printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}
	if (fdebug)
	       	printf("saHpiSessionOpen returns with SessionId %d\n", sessionid);

	/*
	 * Resource discovery
	 */
	if (fdebug) printf("saHpiDiscover\n");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		printf("saHpiDiscover returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}

	printf("Discovery done\n");
	list_resources(sessionid, resourceid);

	rv = saHpiSessionClose(sessionid);
	
	exit(0);
}
Exemple #3
0
int
main (int argc, char **argv)
{
	
	  	int agentx_subagent = AGENT_TRUE;
	  	int c;
	  	int rc = 0;
	  
	  	SaErrorT 	rv = SA_OK;
		SaHpiVersionT	hpiVer;
		SaHpiSessionIdT sessionid;
                SaHpiDomainInfoT        domain_info;  		
		SaHpiBoolT      run_threaded = TRUE;
		
	  	pid_t child;
		
		char * env;
	  		  	
	  	/* change this if you want to be a SNMP master agent */
	  	
	  	debug_register_tokens (AGENT);
                snmp_enable_stderrlog ();
                snmp_set_do_debugging (1);

	  	while ((c = getopt (argc, argv, "fdsCx:h?")) != EOF) {
	    switch (c) {
	   	case 'f':
			do_fork = AGENT_TRUE;
		   	break;
	
	    case 'd':
			debug_register_tokens (AGENT);
			snmp_enable_stderrlog ();
			snmp_set_do_debugging (1);
	      	break;
	
	  	case 's':
			do_syslog = AGENT_FALSE;
	      	break;
	
	   	case 'C':
			netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
				       NETSNMP_DS_LIB_DONT_READ_CONFIGS,
				       1);
	     	break;
	
	  	case 'x':
			netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
				      NETSNMP_DS_AGENT_X_SOCKET,
				      optarg);
	      	break;
	
	 	case 'h':
	    default:
			usage(argv[0]);
			exit(1);
	      	break;
	    }
	  }
	
	  if (do_syslog == AGENT_TRUE) {
	      snmp_enable_calllog ();
	      snmp_enable_syslog_ident (AGENT, LOG_DAEMON);
	  }
	  snmp_log (LOG_INFO, "Starting %s\n", version);
	  /* we're an agentx subagent? */
	  if (agentx_subagent) {
	      /* make us a agentx client. */
	      rc = netsnmp_ds_set_boolean (NETSNMP_DS_APPLICATION_ID,
					   NETSNMP_DS_AGENT_ROLE, 1);
	  }
	
	  /* initialize the agent library */
	  rc = init_agent (AGENT);
	  if (rc != 0) {
	      snmp_log (LOG_ERR, "Could not initialize connection to SNMP daemon. \n"
			"Perhaps you are running %s as non-root?\n", argv[0]);
	      exit (rc);
	  }

	  /* Read configuration information here, before we initialize */
	
	  snmpd_register_config_handler (TRAPS_TOKEN,
					 hpiSubagent_parse_config_traps,
					 NULL,
					 "hpiSubagent on/off switch for sending events upon startup");
	
	  snmpd_register_config_handler (MAX_EVENT_TOKEN,
					 hpiSubagent_parse_config_max_event,
					 NULL,
					 "hpiSubagent MAX number of rows for Events.");
					 
	init_snmp (AGENT); 	
	
	/* 
	 * Initialize HPI library
	 */
	hpiVer = saHpiVersionGet();
	DEBUGMSGTL ((AGENT, "Hpi Version %d Implemented.\n", hpiVer));   	 

	rv = saHpiSessionOpen( SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL );
	if (rv != SA_OK) {
		DEBUGMSGTL ((AGENT, "saHpiSessionOpen Error: returns %s\n",
			oh_lookup_error(rv)));
		exit(-1);
	}
   	DEBUGMSGTL ((AGENT, "saHpiSessionOpen returns with SessionId %d\n", 
   		sessionid)); 

        /* Get the DomainInfo structur,  This is how we get theDomainId for this Session */
	rv = saHpiDomainInfoGet(sessionid, &domain_info);
	if (rv != SA_OK) {
                DEBUGMSGTL ((AGENT, "saHpiSessionOpen Error: returns %s\n",
                        oh_lookup_error(rv)));
                exit(-1);
	}

        /* store session numbers */
   	store_session_info(sessionid, domain_info.DomainId);	
   				
	/* subscribe all sessions/events */
        subcsribe_all_sessions();

	/* Resource discovery */
	rv = saHpiDiscover(sessionid);
	
	if (rv != SA_OK) {
		DEBUGMSGTL ((AGENT, "saHpiDiscover Error: returns %s\n",oh_lookup_error(rv)));
		exit(-1);
	}
	DEBUGMSGTL ((AGENT, "saHpiDiscover Success!\n"));	

	/* Initialize subagent tables */		
	init_saHpiDomainInfoTable(); 
	init_saHpiDomainAlarmTable();
	init_saHpiDomainReferenceTable();
	
	init_saHpiResourceTable();
	init_saHpiRdrTable();
	init_saHpiCtrlDigitalTable();
	init_saHpiCtrlDiscreteTable();
	init_saHpiCtrlAnalogTable();
	init_saHpiCtrlStreamTable();
	init_saHpiCtrlTextTable();
	init_saHpiCtrlOemTable();
	init_saHpiSensorTable();
	init_saHpiCurrentSensorStateTable();
	init_saHpiSensorReadingMaxTable();
	init_saHpiSensorReadingMinTable();
	init_saHpiSensorReadingNominalTable();
	init_saHpiSensorReadingNormalMaxTable();
	init_saHpiSensorReadingNormalMinTable();
	init_saHpiSensorThdLowCriticalTable();
	init_saHpiSensorThdLowMajorTable();
	init_saHpiSensorThdLowMinorTable();
	init_saHpiSensorThdUpCriticalTable();
	init_saHpiSensorThdUpMajorTable();
	init_saHpiSensorThdUpMinorTable();
	init_saHpiSensorThdPosHysteresisTable();
	init_saHpiSensorThdNegHysteresisTable();
	init_saHpiInventoryTable();
	init_saHpiWatchdogTable();
	init_saHpiAnnunciatorTable();
	init_saHpiAreaTable();
	init_saHpiFieldTable();

	init_saHpiEventTable();
	init_saHpiResourceEventTable();
	init_saHpiDomainEventTable();
	init_saHpiSensorEventTable();
	init_saHpiOEMEventTable();
	init_saHpiHotSwapEventTable();
	init_saHpiWatchdogEventTable();		
	init_saHpiSoftwareEventTable();
	init_saHpiSensorEnableChangeEventTable();
	init_saHpiUserEventTable();

	init_saHpiEventLogInfoTable();
	init_saHpiEventLogTable();
	init_saHpiResourceEventLogTable();
	init_saHpiSensorEventLogTable();
	
	init_saHpiHotSwapEventLogTable();
	init_saHpiWatchdogEventLogTable();
	init_saHpiSoftwareEventLogTable();
	init_saHpiOEMEventLogTable();
	init_saHpiUserEventLogTable();
	init_saHpiSensorEnableChangeEventLogTable();
	init_saHpiDomainEventLogTable();
	
	init_saHpiHotSwapTable();
        init_saHpiAutoInsertTimeoutTable();
	init_saHpiAutoInsertTimeoutTable();
	init_saHpiAnnouncementTable();
	init_saHpiAnnouncementEventLogTable();


	if (send_traps_on_startup == AGENT_TRUE)
		send_traps = AGENT_TRUE;
	/* after initialization populate tables */
	populate_saHpiDomainInfoTable(sessionid);

	populate_saHpiDomainAlarmTable(sessionid);

	poplulate_saHpiDomainReferenceTable(sessionid);	

	populate_saHpiResourceTable(sessionid);
	    /* populate_saHpiResourceTable() calls:
	     *     populate_saHpiRdrTable(); calls:
	     *         populate_saHpiCtrlDigitalTable();		
	     *	       populate_saHpiCtrlDiscreteTable();		
	     *	       populate_saHpiCtrlAnalogTable();		
	     *	       populate_saHpiCtrlStreamTable();		
	     *	       populate_saHpiCtrlTextTable();		
	     *	       populate_saHpiCtrlOemTable();		
	     *	       populate_saHpiSensorTable();		
	     *	           populate_saHpiSesnorReadingMaxTable();		
	     *	           populate_saHpiSesnorReadingMinTable();		
	     *	           populate_saHpiSesnorReadingNominalTable();		
	     *	           populate_saHpiSesnorReadingNormalMaxTable();		
	     *	           populate_saHpiSesnorReadingNormalMinTable();		
	     *	           populate_saHpiSensorThdLowCriticalTable();		
	     *	           populate_saHpiSensorThdLowMajorTable();		
	     *	           populate_saHpiSensorThdLowMinorTable();		
	     *	           populate_saHpiSensorThdUpCriticalTable();		
	     *	           populate_saHpiSensorThdUpMajorTable();		
	     *	           populate_saHpiSensorThdUpMinorTable();		
	     *	           populate_saHpiSensorThdPosHysteresisTable();		
	     *	           populate_saHpiSensorThdNegHysteresisTable();		
	     *	       populate_saHpiCurrentSensorStateTable();		
	     *	       populate_saHpiInventoyTable();		
	     *	       populate_saHpiWatchdogTable();		
	     *	       populate_saHpiAnnunciatorTable();		
	     *	       populate_saHpiAreaTable();		
	     *	           populate_saHpiFieldTable(); 
             *         populate_saHpiHotSwapTable();
             *             populate_saHpiAutoInsertTimeoutTable();             
  	     *         populate_saHpiAnnouncementTable();
	     */
            
	populate_saHpiEventTable(sessionid);
            /* populate_saHpiResourceEventTable();
	     * populate_saHpiDomainEventTable();
	     * populate_saHpiSensorEventTable();
	     * populate_saHpiOemEventTable();
	     * populate_saHpiHotSwapEventTable();
	     * populate_saHpiWatchdogEventTable();
	     * populate_saHpiSoftwareEventTable();
	     * populate_saHpiSensorEnableChangeEventTable();
	     * populate_saHpiUserEventTable();
	     */
        populate_saHpiEventLogInfo(sessionid);
        populate_saHpiEventLog (sessionid);
            /*
             * populate_saHpiResourceEventLogTable();
             * populate_saHpiSensorEventLogTable();
	     * populate_saHpiHotSwapEventLogTable();
	     * populate_saHpiWatchdogEventLogTable();
	     * populate_saHpiSoftwareEventLogTable();
	     * populate_saHpiOemEventLogTable();
	     * populate_saHpiUserEventLogTable();
	     * populate_saHpiSensorEnableChangeEventLogTable();
	     * populate_saHpiDomainEventLogTable();	     
             */

        /* Determine whether or not we're in threaded mode */
	env = getenv("OPENHPI_THREADED");
	if ((env == (char *)NULL) || (strcmp(env, "NO") == 0)) {
                DEBUGMSGTL ((AGENT, "Running in nonthreaded mode.  Configuring polling mechanism\n"));  
                run_threaded = SAHPI_FALSE;
		if (init_alarm() != AGENT_ERR_NOERROR) {
                    snmp_log (LOG_ERR, "Could not initialize polling mechanism. Exiting\n.");
                    rc = -1;
                    goto stop;
                }
	}	
	else {
                DEBUGMSGTL ((AGENT, "Running in threaded mode.  Spawing thread\n"));
		/* start event thread */
                set_run_threaded(TRUE);
                if (start_event_thread(&sessionid) != AGENT_ERR_NOERROR) {
                        snmp_log (LOG_ERR, "Could not start our internal loop . Exiting\n.");
                        rc = -1;
                        goto stop;
                }
	}	

        send_traps = AGENT_TRUE;
        /* If we're going to be a snmp master agent, initial the ports */

        if (!agentx_subagent)
                init_master_agent ();	/* open the port to listen on (defaults to udp:161) */
                
        if (do_fork == AGENT_TRUE) {
                if ((child = fork ()) < 0) {
                        snmp_log (LOG_ERR, "Could not fork!\n");
                        exit (-1);
                }
                if (child != 0)
                        exit (0);
        }

        /* In case we recevie a request to stop (kill -TERM or kill -INT) */
        keep_running = 1;
        signal (SIGTERM, stop_server);
        signal (SIGINT, stop_server);

                /* you're main loop here... */
        while (keep_running) {
                /* if you use select(), see snmp_select_info() in snmp_api(3) */
                /*     --- OR ---  */		
                rc = agent_check_and_process (1);
		
        }
stop:
        DEBUGMSGTL ((AGENT,
        "WARNING: closeSaHpiSession: hpiSubagent.c: nolong implemented!"));
        //closeSaHpiSession();
        /* at shutdown time */
        snmp_log (LOG_INFO, "Stopping %s\n", version);
        snmp_shutdown (AGENT);
  
  return rc;
}
Exemple #4
0
int main(int argc, char **argv)
{
        SaHpiInt32T         ComputerNumber;  //0..n-1
        SaHpiInt32T         SelectedSystem;  //0..n-1
        SaHpiPowerStateT    Action;
        COMPUTER_DATA       *ComputerPtr;
        SaHpiBoolT          BladeSelected;
        SaHpiBoolT          MultipleBlades;
        SaHpiBoolT          ActionSelected;
        SaHpiBoolT          PrintUsage;
        SaHpiBoolT          DebugPrints;
        GSList*             Computer;
        GSList*             ComputerListHead;
        int                 option;
        SaHpiSessionIdT     SessionId;
        SaErrorT            Status, Clean_Up_Status;
        SaHpiEntryIdT       RptEntry, RptNextEntry;
        SaHpiRptEntryT      Report;
        SaHpiInt32T         Index, EntityElement;
        SaHpiPowerStateT  PowerState;
        char                PowerStateString[3][7]={"off\0","on\0","cycled\0"};
        SaHpiVersionT       HpiVersion;

        /*
        // Print out the Program name and Version
        */
        PROGRAM_HEADER;

        /* Set Program Defaults */
        ComputerNumber = 0;
        SelectedSystem = 0;
        Action = 255;  //set it out of range to stand for status
        BladeSelected  = FALSE;
        MultipleBlades = FALSE;
        ActionSelected = FALSE;
        PrintUsage     = FALSE;
        DebugPrints    = FALSE;
        RptEntry       = SAHPI_FIRST_ENTRY;

        HpiVersion = saHpiVersionGet();
        /* Parse out option instructions */
        while (1)
        {
                option = getopt(argc, argv, "dpruxb:");
                if ((option == EOF) || (PrintUsage == TRUE))
                {
                        break;  //break out of the while loop
                }

                switch (option)
                {
                case 'd':
                        Action = SAHPI_POWER_OFF;
                        ActionSelected = TRUE;
                        break;
                case 'p':
                        Action = SAHPI_POWER_ON;
                        ActionSelected = TRUE;
                        break;
                case 'r':
                        Action = SAHPI_POWER_CYCLE;
                        ActionSelected = TRUE;
                        break;
                case 'u':
                        BladeSelected = TRUE;
                        ActionSelected = TRUE;
                        break;
                case 'x':
                        DebugPrints = TRUE;
                        break;
                case 'b':
                        if (*optarg == 0)
                        {
                                PrintUsage = TRUE;
                                break;  //no argument
                        }
                        SelectedSystem = atoi(optarg) - 1;  //Normalizing to 0...n-1
                        if ((SelectedSystem > MAX_MANAGED_SYSTEMS) ||
                            (SelectedSystem < 0))
                        {
                                //Argument is out of Range
                                PrintUsage = TRUE;
                        }
                        BladeSelected = TRUE;
                        break;
                default:
                        PrintUsage = TRUE;
                        break;
                }  //end of switch statement
        } //end of argument parsing while loop

        if (PrintUsage == TRUE)
        {
                UsageMessage(PrgName);
                exit(1);   //When we exit here, there is nothing to clean up
        }

        /* Initialize the first of a list of computers */

        HPI_POWER_DEBUG_PRINT("1.0 Initializing the List Structure for the computers\n");
        Computer = g_slist_alloc();
        ComputerListHead = Computer;
        HPI_POWER_DEBUG_PRINT("1.1 Allocating space for the information on each computer\n");
        ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));

        Computer->data = (gpointer)ComputerPtr;

        /* Initialize HPI domain and session */
        HPI_POWER_DEBUG_PRINT("2.1 Initalizing HPI Session\n");
        Status = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,
                                  &SessionId,
                                  NULL);

        if (Status == SA_OK)
        {
                /* Find all of the individual systems */
                // regenerate the Resource Presence Table(RPT)
                HPI_POWER_DEBUG_PRINT("2.2 Hpi Discovery\n");
                Status = saHpiDiscover(SessionId);
        } else {
                printf("2.1 Initalizing HPI Session FAILED, code %s\n", oh_lookup_error(Status));
                return -1;
        }

        HPI_POWER_DEBUG_PRINT("3.0 Walking through all of the Report Tables\n");
        while ((Status == SA_OK) && (RptEntry != SAHPI_LAST_ENTRY))
        {
                HPI_POWER_DEBUG_PRINT("@");
                Status = saHpiRptEntryGet(SessionId,
                                          RptEntry,
                                          &RptNextEntry,
                                          &Report);
                RptEntry = RptNextEntry;

                // Blades will have the first Element of the Entity Path set to SBC_BLADE
                EntityElement = 0;
                HPI_POWER_DEBUG_PRINT(".");
                if (Report.ResourceEntity.Entry[EntityElement].EntityType ==
                    SAHPI_ENT_SBC_BLADE)
                {
                        HPI_POWER_DEBUG_PRINT("#");
                        // We have found a Blade
                        ComputerPtr->ResID = Report.ResourceId;
                        /* enumerate this list as created */
                        ComputerPtr->number = ComputerNumber;
                        ComputerNumber++;
                        ComputerPtr->Instance =
                                Report.ResourceEntity.Entry[EntityElement].EntityLocation;
                        // find a Name string for this blade
                        snprintf(ComputerPtr->NameStr, sizeof(ComputerPtr->NameStr),
                                "%s %d",
                                (char*)Report.ResourceTag.Data,
                                (int) ComputerPtr->Instance);

                        // Create a new allocation for another system
                        ComputerPtr = (COMPUTER_DATA*)malloc(sizeof(COMPUTER_DATA));
                        // Add another member to the list
                        Computer = g_slist_append(Computer,(gpointer)ComputerPtr);
                        // set a flag that we are working with blades
                        MultipleBlades = TRUE;

                }
        }

        HPI_POWER_DEBUG_PRINT("\n4.0 Generating Listing of options to choose from:\n");
        /* If parsed option does not select blade and
       more than one is found */
        if ((MultipleBlades == TRUE) && (BladeSelected == FALSE) && (Status == SA_OK))
        {
                HPI_POWER_DEBUG_PRINT("4.1 Printing out a listing of all the blades\n");
                for (Index = 0; Index < ComputerNumber; Index++)
                {
                        HPI_POWER_DEBUG_PRINT("$");
                        // obtain the information for this computer
                        ComputerPtr = g_slist_nth_data(ComputerListHead, Index);
                        if (ComputerPtr == NULL)
                        {
                                printf("Call returned a NULL\n");
                                break;
                        }

                        // retrieve the power status for this computer
                        HPI_POWER_DEBUG_PRINT("%%");
                        PowerState = 0;
                        Status = saHpiResourcePowerStateGet(SessionId,
                                                            ComputerPtr->ResID,
                                                            &PowerState);
                        if (Status != SA_OK)
                        {
                                printf("%s does not support PowerStateGet",
                                       ComputerPtr->NameStr);
                        }

                        /* Print out all of the systems */
                        printf("%2d) %20s  - %s \n\r", (Index + 1),
                               ComputerPtr->NameStr,
                               PowerStateString[PowerState]);
                }
                /* Prompt user to select one */
                while ((Index >= ComputerNumber) || (Index < 0))
                {
                        printf("\nEnter the number for the desired blade: ");
                        scanf("%d",&Index);
                        Index--; //normalize to 0..n-1
                        printf("\n");
                }
                BladeSelected = TRUE;
                SelectedSystem = Index;
        }
        HPI_POWER_DEBUG_PRINT("4.2 Generating Listing of Actions to choose from\n");
        /* If action is not selected */
        if ((ActionSelected == FALSE) && (Status == SA_OK))
        {
                /* prompt user to select an action */
                printf("\nSelect Action: 0 - Off; 1 - On; 2 - Reset; 3 - Status \n\r");
                printf("Enter a number 0 to 3:  ");
                scanf("%d", &Index);
                switch (Index)
                {
                case 0:
                        Action = SAHPI_POWER_OFF;
                        break;
                case 1:
                        Action = SAHPI_POWER_ON;
                        break;
                case 2:
                        Action = SAHPI_POWER_CYCLE;
                        break;
                default:
                        Action = 255;  //Out of Range for "Status"
                        break;
                }
        }
        /* execute the command */

        if (Status == SA_OK)
        {
                HPI_POWER_DEBUG_PRINT("5.0 Executing the command\n\r");
                // obtain the information for this computer
                ComputerPtr = g_slist_nth_data(ComputerListHead, SelectedSystem);

                if (Action <= SAHPI_POWER_CYCLE)
                {
                        HPI_POWER_DEBUG_PRINT("5.1 Setting a New Power State\n\r");
                        // Set the new power status for this computer
                        Status = saHpiResourcePowerStateSet(SessionId,
                                                            ComputerPtr->ResID,
                                                            Action);
                        /* return status */
                        if (Status == SA_OK)
                        {
                                printf("\n%s -- %20s has been successfully powered %s\n",
                                       PrgName,
                                       ComputerPtr->NameStr,
                                       PowerStateString[Action]);
                        }
                }
                else   // Report Power status for the system
                {
                        HPI_POWER_DEBUG_PRINT("5.2 Getting the Power Status\n\r");
                        // retrieve the power status for this computer
                        PowerState = 0;
                        Status = saHpiResourcePowerStateGet(SessionId,
                                                            ComputerPtr->ResID,
                                                            &PowerState);
                        if (Status != SA_OK)
                        {
                                printf("%s does not support PowerStateGet",
                                       ComputerPtr->NameStr);
                        }

                        /* Print out Status for this system */
                        printf("%2d) %20s  - %s \n\r", (ComputerPtr->number + 1),
                               ComputerPtr->NameStr,
                               PowerStateString[PowerState]);
                }
        }
        HPI_POWER_DEBUG_PRINT("6.0 Clean up");
        /* clean up */
        Clean_Up_Status = saHpiSessionClose(SessionId);

        //Free all of the Allocations for the Computer data
        Computer = ComputerListHead;
        while (Computer != NULL)
        {
                free(Computer->data);
                Computer = g_slist_next(Computer);
        }
        //Free the whole List
        g_slist_free(ComputerListHead);

        /* return status code and exit */

        if (Status != SA_OK)
        {
                HPI_POWER_DEBUG_PRINT("7.0 Reporting Bad Status");
                printf("Program %s returns with Error = %s\n", PrgName, oh_lookup_error(Status));
        }

        return(Status);
}
Exemple #5
0
static int
bladehpi_set_config(StonithPlugin *s, StonithNVpair *list)
{
	struct pluginDevice *	dev = NULL;
	StonithNamesToGet	namestocopy [] =
	{	{ST_ENTITYROOT,	NULL}
	,	{NULL,		NULL}
	};
	int			rc, i;
	SaErrorT		ohrc;
	
	if (Debug) {
		LOG(PIL_DEBUG, "%s: called", __FUNCTION__);
	}
	
	ERRIFWRONGDEV(s, S_OOPS);

	dev = (struct pluginDevice *)s;

	if (Debug) {
		LOG(PIL_DEBUG, "%s conditionally compiled with:"
#ifdef IBMBC_WAIT_FOR_OFF
		" IBMBC_WAIT_FOR_OFF"
#endif
		, dev->pluginid);
	}
	
	if ((rc = OurImports->CopyAllValues(namestocopy, list)) != S_OK) {
		return rc;
	}

	if (Debug) {
		LOG(PIL_DEBUG, "%s = %s", ST_ENTITYROOT
		,	namestocopy[0].s_value);	
	}

	if (get_num_tokens(namestocopy[0].s_value) == 1) {
		/* name=value pairs on command line, look for soft_reset */
		const char *softreset = 
			OurImports->GetValue(list, ST_SOFTRESET);
		if (softreset != NULL) {
			if (!strcasecmp(softreset, "true") ||
			    !strcmp(softreset, "1")) {
				dev->softreset = 1;
			} else if (!strcasecmp(softreset, "false") ||
				   !strcmp(softreset, "0")) {
				dev->softreset = 0;
			} else {
				LOG(PIL_CRIT, "Invalid %s %s, must be "
					"true, 1, false or 0"
				,	ST_SOFTRESET, softreset);
				FREE(namestocopy[0].s_value);
				return S_OOPS;
			}
		}
	} else {
		/* -p or -F option with args "entity_root [soft_reset]..." */
		char *pch = namestocopy[0].s_value;

		/* skip over entity_root and null-terminate */
		pch += strcspn(pch, WHITESPACE);
		*pch = EOS;

		/* skip over white-space up to next token */
		pch++;
		pch += strspn(pch, WHITESPACE);
		if (!strcasecmp(pch, "true") || !strcmp(pch, "1")) {
			dev->softreset = 1;
		} else if (!strcasecmp(pch, "false") || !strcmp(pch, "0")) {
			dev->softreset = 0;
		} else {
			LOG(PIL_CRIT, "Invalid %s %s, must be "
				"true, 1, false or 0"
			,	ST_SOFTRESET, pch);
			FREE(namestocopy[0].s_value);
			return S_OOPS;
		}
	}

	dev->device = STRDUP(namestocopy[0].s_value);
	FREE(namestocopy[0].s_value);
	if (dev->device == NULL) {
		LOG(PIL_CRIT, "Out of memory for strdup in %s", __FUNCTION__);
		return S_OOPS;
	}

	if (strcspn(dev->device, WHITESPACE) != strlen(dev->device) ||
	    sscanf(dev->device, SYSTEM_CHASSIS_FMT, &i) != 1 || i < 0) {
		LOG(PIL_CRIT, "Invalid %s %s, must be of format %s"
		,	ST_ENTITYROOT, dev->device, SYSTEM_CHASSIS_FMT);
		return S_BADCONFIG;
	}
	
	dev->ohver = saHpiVersionGet();
	if (dev->ohver > SAHPI_INTERFACE_VERSION) {
		LOG(PIL_CRIT, "Installed OpenHPI interface (%x) greater than "
			"one used by plugin (%x), incompatibilites may exist"
		,	dev->ohver, SAHPI_INTERFACE_VERSION);
		return S_BADCONFIG;
	}

	ohrc = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID
				    , &dev->ohsession, NULL);
	if (ohrc != SA_OK) {
		LOG(PIL_CRIT, "Unable to open HPI session (%d)", ohrc);
		return S_BADCONFIG;
	}

	ohrc = saHpiDiscover(dev->ohsession);
	if (ohrc != SA_OK) {
		LOG(PIL_CRIT, "Unable to discover resources (%d)", ohrc);
		return S_BADCONFIG;
	}

	if (get_bladehpi_hostlist(dev) != S_OK) {
		LOG(PIL_CRIT, "Unable to obtain list of hosts in %s"
		,	__FUNCTION__);
		return S_BADCONFIG;
	}

	return S_OK;
}
Exemple #6
0
 *      Shuah Khan <*****@*****.**>
 *	Renier Morales <*****@*****.**>
 */

#include <string.h>

#include <SaHpi.h>
#include <oHpi.h>
#include <oh_clients.h>

void oh_prog_version(const char *prog_name, const char *svn_rev_str)
{
	SaHpiUint32T ohpi_major = oHpiVersionGet() >> 48;
        SaHpiUint32T ohpi_minor = (oHpiVersionGet() << 16) >> 48;
        SaHpiUint32T ohpi_patch = (oHpiVersionGet() << 32) >> 48;
        SaHpiVersionT hpiver;
        char svn_rev[SAHPI_MAX_TEXT_BUFFER_LENGTH];

        strncpy(svn_rev, svn_rev_str, SAHPI_MAX_TEXT_BUFFER_LENGTH);
        svn_rev[strlen(svn_rev_str)-2] = '\0';

        printf("%s (rev %s) - This program came with OpenHPI %u.%u.%u\n",
               prog_name, svn_rev+11, ohpi_major, ohpi_minor, ohpi_patch);
        hpiver = saHpiVersionGet();
        printf("SAF HPI Version %c.0%d.0%d\n\n",
               (hpiver >> 16) + ('A' - 1),
               (hpiver & 0x0000FF00) >> 8,
               hpiver & 0x000000FF);
}

Exemple #7
0
/* 
 * Main                
 */
int
main(int argc, char **argv)
{
	SaErrorT 	rv = SA_OK;
	
	SaHpiVersionT	hpiVer;
	SaHpiSessionIdT sessionid;
	SaHpiResourceIdT resourceid = all_resources;

	int c;
	    
	printf("\n\n%s ver %s\n",argv[0],progver);
	while ( (c = getopt( argc, argv,"rsicawn:x?")) != EOF ) {
		switch(c) {
			case 'r': f_rpt     = 1; break;
			case 's': f_sensor = 1; break;
			case 'i': f_inv = 1; break;
			case 'c': f_ctrl = 1; break;
			case 'w': f_wdog = 1; break;
			case 'a': f_ann = 1; break;
			case 'n':
				if (optarg)
					resourceid = atoi(optarg);
				else 
					resourceid = all_resources;
				break;
			case 'x': fdebug = 1; break;
			default:
				printf("\n\tUsage: %s [-option]\n\n", progname);
				printf("\t      (No Option) Display system topology: rpt & rdr headers\n");	
				printf("\t           -r     Display only rpts\n");
				printf("\t           -s     Display only sensors\n");
				printf("\t           -c     Display only controls\n");
				printf("\t           -w     Display only watchdogs\n");
				printf("\t           -i     Display only inventories\n");
				printf("\t           -a     Display only annunciators\n");												
				printf("\t           -x     Display debug messages\n");
				printf("\n\n\n\n");
				exit(1);
		}
	}
 
	if (argc == 1)  f_overview = 1;
	memset (previous_system, 0, SAHPI_MAX_TEXT_BUFFER_LENGTH);
	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);

	if (fdebug) printf("saHpiSessionOpen\n");
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
	if (rv != SA_OK) {
		printf("saHpiSessionOpen returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}
	if (fdebug)
	       	printf("saHpiSessionOpen returns with SessionId %d\n", sessionid);

	/*
	 * Resource discovery
	 */
	if (fdebug) printf("saHpiDiscover\n");
	rv = saHpiDiscover(sessionid);
	if (rv != SA_OK) {
		printf("saHpiDiscover returns %s\n",oh_lookup_error(rv));
		exit(-1);
	}

	if (fdebug)  printf("Discovery done\n");
	list_resources(sessionid, resourceid);

	rv = saHpiSessionClose(sessionid);
	
	exit(0);
}
Exemple #8
0
int
main (int argc, char **argv)
{
	
	  	int agentx_subagent = AGENT_TRUE;
	  	int c;
	  	int rc = 0;
        	  
	  	SaErrorT 	rv = SA_OK;
		SaHpiVersionT	hpiVer;
		SaHpiSessionIdT sessionid;
		
		
		
	  	pid_t child;
		
		/* for simulator */
		struct oh_handler_state *state = NULL;
		struct oh_event *event = (struct oh_event *)g_malloc0(sizeof(struct oh_event));
		struct oh_event *event2= (struct oh_event *)g_malloc0(sizeof(struct oh_event));
		struct oh_event *event3= (struct oh_event *)g_malloc0(sizeof(struct oh_event));		
		struct oh_event *event4= (struct oh_event *)g_malloc0(sizeof(struct oh_event));
		struct oh_event *event5= (struct oh_event *)g_malloc0(sizeof(struct oh_event));	
		struct oh_event *event6= (struct oh_event *)g_malloc0(sizeof(struct oh_event));	
		struct oh_event *event7= (struct oh_event *)g_malloc0(sizeof(struct oh_event));	
		struct oh_event *event8= (struct oh_event *)g_malloc0(sizeof(struct oh_event));			
							
		SaErrorT rc1;
	  	char OemString[] = "MY Oem EVENT";
	  	char SWString[] = "MY SW EVENT";			  	
	  	/* change this if you want to be a SNMP master agent */
	  	
	  	debug_register_tokens (AGENT);
                snmp_enable_stderrlog ();
                snmp_set_do_debugging (1);

	  	while ((c = getopt (argc, argv, "fdsCx:h?")) != EOF) {
	    switch (c) {
	   	case 'f':
			do_fork = AGENT_TRUE;
		   	break;
	
	    case 'd':
			debug_register_tokens (AGENT);
			snmp_enable_stderrlog ();
			snmp_set_do_debugging (1);
	      	break;
	
	  	case 's':
			do_syslog = AGENT_FALSE;
	      	break;
	
	   	case 'C':
			netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
				       NETSNMP_DS_LIB_DONT_READ_CONFIGS,
				       1);
	     	break;
	
	  	case 'x':
			netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
				      NETSNMP_DS_AGENT_X_SOCKET,
				      optarg);
	      	break;
	
	 	case 'h':
	    default:
			usage(argv[0]);
			exit(1);
	      	break;
	    }
	  }
	
	  if (do_syslog == AGENT_TRUE) {
	      snmp_enable_calllog ();
	      snmp_enable_syslog_ident (AGENT, LOG_DAEMON);
	  }
	  snmp_log (LOG_INFO, "Starting %s\n", version);
	  /* we're an agentx subagent? */
	  if (agentx_subagent) {
	      /* make us a agentx client. */
	      rc = netsnmp_ds_set_boolean (NETSNMP_DS_APPLICATION_ID,
					   NETSNMP_DS_AGENT_ROLE, 1);
	  }
	
	  /* initialize the agent library */
	  rc = init_agent (AGENT);
	  if (rc != 0) {
	      snmp_log (LOG_ERR, "Could not initialize connection to SNMP daemon. \n"
			"Perhaps you are running %s as non-root?\n", argv[0]);
	      exit (rc);
	  }

	  /* Read configuration information here, before we initialize */
	
	  snmpd_register_config_handler (TRAPS_TOKEN,
					 hpiSubagent_parse_config_traps,
					 NULL,
					 "hpiSubagent on/off switch for sending events upon startup");
	
	  snmpd_register_config_handler (MAX_EVENT_TOKEN,
					 hpiSubagent_parse_config_max_event,
					 NULL,
					 "hpiSubagent MAX number of rows for Events.");
					 
	init_snmp (AGENT); 	
	
	/* 
	 * Initialize HPI library
	 */
	hpiVer = saHpiVersionGet();
	DEBUGMSGTL ((AGENT, "Hpi Version %d Implemented.\n", hpiVer));   	 

	rv = saHpiSessionOpen( SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL );
	if (rv != SA_OK) {
		DEBUGMSGTL ((AGENT, "saHpiSessionOpen Error: returns %s\n",
			oh_lookup_error(rv)));
		exit(-1);
	}
   	DEBUGMSGTL ((AGENT, "saHpiSessionOpen returns with SessionId %d\n", 
   		sessionid));  

        /* store session numbers */
   	store_session_info(sessionid, SAHPI_UNSPECIFIED_DOMAIN_ID);	
   				
	/* subscribe all sessions/events */
        subcsribe_all_sessions();

	/* Resource discovery */
	rv = saHpiDiscover(sessionid);
	
	if (rv != SA_OK) {
		DEBUGMSGTL ((AGENT, "saHpiDiscover Error: returns %s\n",oh_lookup_error(rv)));
		exit(-1);
	}
	DEBUGMSGTL ((AGENT, "saHpiDiscover Success!\n"));	

	/* Initialize subagent tables */		
	init_saHpiDomainInfoTable(); 
	init_saHpiDomainAlarmTable();
	init_saHpiDomainReferenceTable();
	
	init_saHpiResourceTable();
	init_saHpiRdrTable();
	init_saHpiCtrlDigitalTable();
	init_saHpiCtrlDiscreteTable();
	init_saHpiCtrlAnalogTable();
	init_saHpiCtrlStreamTable();
	init_saHpiCtrlTextTable();
	init_saHpiCtrlOemTable();
	init_saHpiSensorTable();
	init_saHpiCurrentSensorStateTable();
	init_saHpiSensorReadingMaxTable();
	init_saHpiSensorReadingMinTable();
	init_saHpiSensorReadingNominalTable();
	init_saHpiSensorReadingNormalMaxTable();
	init_saHpiSensorReadingNormalMinTable();
	init_saHpiSensorThdLowCriticalTable();
	init_saHpiSensorThdLowMajorTable();
	init_saHpiSensorThdLowMinorTable();
	init_saHpiSensorThdUpCriticalTable();
	init_saHpiSensorThdUpMajorTable();
	init_saHpiSensorThdUpMinorTable();
	init_saHpiSensorThdPosHysteresisTable();
	init_saHpiSensorThdNegHysteresisTable();
	init_saHpiInventoryTable();
	init_saHpiWatchdogTable();
	init_saHpiAnnunciatorTable();
	init_saHpiAreaTable();
	init_saHpiFieldTable();

	init_saHpiEventTable();
	init_saHpiResourceEventTable();
	init_saHpiDomainEventTable();
	init_saHpiSensorEventTable();
	init_saHpiOemEventTable();
	init_saHpiHotSwapEventTable();
	init_saHpiWatchdogEventTable();		
	init_saHpiSoftwareEventTable();
	init_saHpiSensorEnableChangeEventTable();
	init_saHpiUserEventTable();

	init_saHpiEventLogInfoTable();
	init_saHpiEventLogTable();
	init_saHpiResourceEventLogTable();
	init_saHpiSensorEventLogTable();
	
	init_saHpiHotSwapEventLogTable();
	init_saHpiWatchdogEventLogTable();
	init_saHpiSoftwareEventLogTable();
	init_saHpiOemEventLogTable();
	init_saHpiUserEventLogTable();
	init_saHpiSensorEnableChangeEventLogTable();
	init_saHpiDomainEventLogTable();
	
	init_saHpiHotSwapTable();
	init_saHpiAutoInsertTimeoutTable();
	init_saHpiAnnouncementTable();
/*	init_saHpiAnnouncementEventLogTable();	*/


	if (send_traps_on_startup == AGENT_TRUE)
		send_traps = AGENT_TRUE;
	/* after initialization populate tables */
	populate_saHpiDomainInfoTable(sessionid);

	populate_saHpiDomainAlarmTable(sessionid);

	poplulate_saHpiDomainReferenceTable(sessionid);	

	populate_saHpiResourceTable(sessionid);
	    /* populate_saHpiResourceTable() calls:
	     *     populate_saHpiRdrTable(); calls:
	     *         populate_saHpiCtrlDigitalTable();		
	     *	       populate_saHpiCtrlDiscreteTable();		
	     *	       populate_saHpiCtrlAnalogTable();		
	     *	       populate_saHpiCtrlStreamTable();		
	     *	       populate_saHpiCtrlTextTable();		
	     *	       populate_saHpiCtrlOemTable();		
	     *	       populate_saHpiSensorTable();		
	     *	           populate_saHpiSesnorReadingMaxTable();		
	     *	           populate_saHpiSesnorReadingMinTable();		
	     *	           populate_saHpiSesnorReadingNominalTable();		
	     *	           populate_saHpiSesnorReadingNormalMaxTable();		
	     *	           populate_saHpiSesnorReadingNormalMinTable();		
	     *	           populate_saHpiSensorThdLowCriticalTable();		
	     *	           populate_saHpiSensorThdLowMajorTable();		
	     *	           populate_saHpiSensorThdLowMinorTable();		
	     *	           populate_saHpiSensorThdUpCriticalTable();		
	     *	           populate_saHpiSensorThdUpMajorTable();		
	     *	           populate_saHpiSensorThdUpMinorTable();		
	     *	           populate_saHpiSensorThdPosHysteresisTable();		
	     *	           populate_saHpiSensorThdNegHysteresisTable();		
	     *	       populate_saHpiCurrentSensorStateTable();		
	     *	       populate_saHpiInventoyTable();		
	     *	       populate_saHpiWatchdogTable();		
	     *	       populate_saHpiAnnunciatorTable();		
	     *	       populate_saHpiAreaTable();		
	     *	           populate_saHpiFieldTable();
	     *         populate_saHpiHotSwapTable();
	     */

	populate_saHpiEventTable(sessionid);
            /* populate_saHpiResourceEventTable();
	     * populate_saHpiDomainEventTable();
	     * populate_saHpiSensorEventTable();
	     * populate_saHpiOemEventTable();
	     * populate_saHpiHotSwapEventTable();
	     * populate_saHpiWatchdogEventTable();
	     * populate_saHpiSoftwareEventTable();
	     * populate_saHpiSensorEnableChangeEventTable();
	     * populate_saHpiUserEventTable();
	     */
        populate_saHpiEventLogInfo(sessionid);
        populate_saHpiEventLog (sessionid);
            /*
             * populate_saHpiResourceEventLogTable();
             * populate_saHpiSensorEventLogTable();
	     * populate_saHpiHotSwapEventLogTable();
	     * populate_saHpiWatchdogEventLogTable();
	     * populate_saHpiSoftwareEventLogTable();
	     * populate_saHpiOemEventLogTable();
	     * populate_saHpiUserEventLogTable();
	     * populate_saHpiSensorEnableChangeEventLogTable();
	     * populate_saHpiDomainEventLogTable();	     
             */


        /* Generate Event Here */
		
	DEBUGMSGTL ((AGENT,
        "%%%%%%%% Generating simultor event %%%%%%%%\n"));
	
	state = sim_get_handler_by_name("eventGenerator");
	
	if (!state) {
                DEBUGMSGTL ((AGENT, "%%%%%%%% Couldn't find handler name %%%%%%%%\n"));
	}
	else { // build an event
		
	        event->did = 1; /* domain id for the event */
                event->type = OH_ET_HPI;
                event->u.hpi_event.res = sim_rpt_array[0].rpt;
                event->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event->u.hpi_event.event.EventType = SAHPI_ET_WATCHDOG;
		event->u.hpi_event.event.Timestamp = 0;
		event->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event->u.hpi_event.event.EventDataUnion.WatchdogEvent.WatchdogNum = 1;
		event->u.hpi_event.event.EventDataUnion.WatchdogEvent.WatchdogAction = SAHPI_WAE_RESET;
		event->u.hpi_event.event.EventDataUnion.WatchdogEvent.WatchdogPreTimerAction = SAHPI_WPI_SMI;
		event->u.hpi_event.event.EventDataUnion.WatchdogEvent.WatchdogUse = SAHPI_WTU_BIOS_FRB2;
		
		
		rc1 = sim_inject_event(state, event);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 1: %d %%%%%%%%\n", rc1));
		
	        event2->did = 1; /* domain id for the event */
                event2->type = OH_ET_HPI;
                event2->u.hpi_event.res = sim_rpt_array[0].rpt;
                event2->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event2->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event2->u.hpi_event.event.EventType = SAHPI_ET_HOTSWAP;
		event2->u.hpi_event.event.Timestamp = 0;
		event2->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event2->u.hpi_event.event.EventDataUnion.HotSwapEvent.HotSwapState = SAHPI_HS_STATE_INSERTION_PENDING;
		event2->u.hpi_event.event.EventDataUnion.HotSwapEvent.PreviousHotSwapState = SAHPI_HS_STATE_NOT_PRESENT;				

		rc1 = sim_inject_event(state, event2);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 2: %d %%%%%%%%\n", rc1));
		
	        event3->did = 1; /* domain id for the event */
                event3->type = OH_ET_HPI;
                event3->u.hpi_event.res = sim_rpt_array[0].rpt;
                event3->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event3->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event3->u.hpi_event.event.EventType = SAHPI_ET_SENSOR;
		event3->u.hpi_event.event.Timestamp = 0;
		event3->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.SensorNum = SAHPI_DEFAGSENS_PWR;
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.SensorType = SAHPI_VOLTAGE;	   
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.EventCategory = SAHPI_EC_GENERIC;   
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.Assertion = 1;   
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.EventState = SAHPI_ES_STATE_00;    
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.OptionalDataPresent = SAHPI_SOD_TRIGGER_READING;
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.TriggerReading.IsSupported = 1;
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.TriggerReading.Type = SAHPI_SENSOR_READING_TYPE_UINT64;
		event3->u.hpi_event.event.EventDataUnion.SensorEvent.TriggerReading.Value.SensorUint64 = 0xFEEEEEEEEEEEEEED;
		
		rc1 = sim_inject_event(state, event3);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 3: %d %%%%%%%%\n", rc1));	
		
	        event4->did = 1; /* domain id for the event */
                event4->type = OH_ET_HPI;
                event4->u.hpi_event.res = sim_rpt_array[0].rpt;
                event4->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event4->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event4->u.hpi_event.event.EventType = SAHPI_ET_OEM;
		event4->u.hpi_event.event.Timestamp = 0;
		event4->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event4->u.hpi_event.event.EventDataUnion.OemEvent.MId = SAHPI_MANUFACTURER_ID_UNSPECIFIED;		
		event4->u.hpi_event.event.EventDataUnion.OemEvent.OemEventData.DataType = SAHPI_TL_TYPE_BCDPLUS;
		event4->u.hpi_event.event.EventDataUnion.OemEvent.OemEventData.Language = SAHPI_LANG_ENGLISH;
		event4->u.hpi_event.event.EventDataUnion.OemEvent.OemEventData.DataLength = 12;
		memcpy(event4->u.hpi_event.event.EventDataUnion.OemEvent.OemEventData.Data, &OemString[0],
		       event4->u.hpi_event.event.EventDataUnion.OemEvent.OemEventData.DataLength);
		
		rc1 = sim_inject_event(state, event4);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 4: %d %%%%%%%%\n", rc1));	
		
	        event5->did = 1; /* domain id for the event */
                event5->type = OH_ET_HPI;
                event5->u.hpi_event.res = sim_rpt_array[0].rpt;
                event5->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event5->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event5->u.hpi_event.event.EventType = SAHPI_ET_HPI_SW;
		event5->u.hpi_event.event.Timestamp = 0;
		event5->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.MId = SAHPI_MANUFACTURER_ID_UNSPECIFIED;
		event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.Type = SAHPI_HPIE_STARTUP;
		event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.DataType = SAHPI_TL_TYPE_TEXT;
		event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.Language = SAHPI_LANG_ENGLISH;
		event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.DataLength = 11;  								     
		memcpy(event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.Data, &SWString[0],
		       event5->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.DataLength);

		rc1 = sim_inject_event(state, event5);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 5: %d %%%%%%%%\n", rc1));	
		
	        event6->did = 1; /* domain id for the event */
                event6->type = OH_ET_HPI;
                event6->u.hpi_event.res = sim_rpt_array[0].rpt;
                event6->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event6->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event6->u.hpi_event.event.EventType = SAHPI_ET_SENSOR_ENABLE_CHANGE;
		event6->u.hpi_event.event.Timestamp = 0;
		event6->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.SensorNum = SAHPI_DEFAGSENS_PWR;
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.SensorType = SAHPI_VOLTAGE;	   
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.EventCategory = SAHPI_EC_GENERIC;   
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.SensorEnable = 1;
                event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.SensorEventEnable = 1;
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.AssertEventMask = SAHPI_ES_STATE_ASSERTED;
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.DeassertEventMask = SAHPI_ES_STATE_DEASSERTED;
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.OptionalDataPresent = SAHPI_SEOD_CURRENT_STATE;  
		event6->u.hpi_event.event.EventDataUnion.SensorEnableChangeEvent.CurrentState = SAHPI_ES_LIMIT_EXCEEDED; 
		
		rc1 = sim_inject_event(state, event6);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 6: %d %%%%%%%%\n", rc1));	
		
	        event7->did = 1; /* domain id for the event */
                event7->type = OH_ET_HPI;
                event7->u.hpi_event.res = sim_rpt_array[0].rpt;
                event7->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event7->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event7->u.hpi_event.event.EventType = SAHPI_ET_DOMAIN;
		event7->u.hpi_event.event.Timestamp = 0;
		event7->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event7->u.hpi_event.event.EventDataUnion.DomainEvent.Type = SAHPI_DOMAIN_REF_ADDED;
		event7->u.hpi_event.event.EventDataUnion.DomainEvent.DomainId = SAHPI_UNSPECIFIED_DOMAIN_ID;
		
		rc1 = sim_inject_event(state, event7);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 7: %d %%%%%%%%\n", rc1));	
		
	        event8->did = 1; /* domain id for the event */
                event8->type = OH_ET_HPI;
                event8->u.hpi_event.res = sim_rpt_array[0].rpt;
                event8->u.hpi_event.rdr.RecordId = 0; // Not sure here
		event8->u.hpi_event.event.Source = sim_rpt_array[0].rpt.ResourceId;
		event8->u.hpi_event.event.EventType = SAHPI_ET_RESOURCE;
		event8->u.hpi_event.event.Timestamp = 0;
		event8->u.hpi_event.event.Severity = SAHPI_CRITICAL;
		event8->u.hpi_event.event.EventDataUnion.ResourceEvent.ResourceEventType = SAHPI_RESE_RESOURCE_FAILURE;								  				       	        	     		
		
		rc1 = sim_inject_event(state, event8);
                DEBUGMSGTL ((AGENT, "%%%%%%%% Return code from inject 8: %d %%%%%%%%\n", rc1));	

	}


        /* start event thread */
        set_run_threaded(TRUE);
        if (start_event_thread(sessionid) != AGENT_ERR_NOERROR) {
                snmp_log (LOG_ERR, "Could not start our internal loop . Exiting\n.");
                rc = -1;
                goto stop;
        }

        send_traps = AGENT_TRUE;
        /* If we're going to be a snmp master agent, initial the ports */

        if (!agentx_subagent)
                init_master_agent ();	/* open the port to listen on (defaults to udp:161) */
                
        if (do_fork == AGENT_TRUE) {
                if ((child = fork ()) < 0) {
                        snmp_log (LOG_ERR, "Could not fork!\n");
                        exit (-1);
                }
                if (child != 0)
                        exit (0);
        }

   
        /* In case we recevie a request to stop (kill -TERM or kill -INT) */
        keep_running = 1;
        signal (SIGTERM, stop_server);
        signal (SIGINT, stop_server);



        /* you're main loop here... */
        while (keep_running) {
                /* if you use select(), see snmp_select_info() in snmp_api(3) */
                /*     --- OR ---  */
                rc = agent_check_and_process (1);	/* 0 == don't block */
        }
stop:
        DEBUGMSGTL ((AGENT,
        "WARNING: closeSaHpiSession: hpiSubagent.c: nolong implemented!"));
        //closeSaHpiSession();
        /* at shutdown time */
        snmp_log (LOG_INFO, "Stopping %s\n", version);
        snmp_shutdown (AGENT);
  
  return rc;
}
Exemple #9
0
int main(int argc, char **argv)
{
        int c;
        SaErrorT rv, rv_2;
        SaHpiVersionT hpiVer;
        SaHpiSessionIdT sessionid;
        
        /* Domain */
        SaHpiDomainInfoT domainInfo;
        SaHpiEventLogEntryIdT entryid;
        SaHpiEventLogEntryIdT nextentryid;
        SaHpiEventLogEntryIdT preventryid;
        SaHpiEventLogInfoT info;
        SaHpiEventLogEntryT  el;
	SaHpiRdrT rdr, *rdrptr;
	SaHpiRptEntryT rpt, *rptptr;


        printf("%s: version %s\n",argv[0],progver);

        while ( (c = getopt( argc, argv,"cdpx?")) != EOF )
                switch(c) {
                case 'c': fclear = 1; break;
                case 'd': frdr   = 1; break;
                case 'p': frpt   = 1; break;				
                case 'x': fdebug = 1; break;
                default:
                        printf("\n\n\nUsage %s [-cdpx]\n",argv[0]);
			printf("    Where                             \n");
                        printf("        -c clears the event log\n");
			printf("        -d also get RDR with the event log\n");
			printf("        -p also get RPT with the event log\n");
                        printf("        -x displays eXtra debug messages\n\n\n");
                        exit(1);
                }
	
	/* 
	 * House keeping:
	 * 	-- get (check?) hpi implementation version
	 *      -- open hpi session	
	 */
	if (fdebug) printf("saHpiVersionGet\n");
	hpiVer = saHpiVersionGet();
	printf("Hpi Version %d Implemented.\n", hpiVer);
	
        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, SpiLibd not running\n",rv);
                else
                        printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv));
                exit(-1);
        }

        rv = saHpiDiscover(sessionid);
        if (fdebug) printf("saHpiResourcesDiscover %s\n", oh_lookup_error(rv));
	

        rv = saHpiDomainInfoGet(sessionid, &domainInfo);
        if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv));

        printf("DomainInfo: UpdateCount = %d, UpdateTime = %lx\n",
               domainInfo.RptUpdateCount, (unsigned long)domainInfo.RptUpdateTimestamp);

	/* initialize structure */
	info.Entries = 0;
	info.Size = 0;
	info.Enabled = 0;
		    
	rv_2 = saHpiEventLogInfoGet(sessionid,SAHPI_UNSPECIFIED_RESOURCE_ID,&info);
			
	if (fdebug)
			printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv));
	if (rv_2 == SA_OK) {
		printf("Domain EventLogInfo\n");
		oh_print_eventloginfo(&info, 4);
	} else { 
		printf("Domain saHpiEventLogInfoGet %s\n", oh_lookup_error(rv_2));
	}
				    
	if (fclear) {
		rv = saHpiEventLogClear(sessionid,SAHPI_UNSPECIFIED_RESOURCE_ID);
		if (rv == SA_OK)
			printf("EventLog successfully cleared\n");
		else
			printf("EventLog clear, error = %d, %s\n", rv, oh_lookup_error(rv));
		return(0);
	}
				    
	if (info.Entries != 0){
		rv = SA_OK;
		entryid = SAHPI_OLDEST_ENTRY;
		while ((rv == SA_OK) && (entryid != SAHPI_NO_MORE_ENTRIES))
		{
		
			if (frdr) rdrptr = &rdr;
			else rdrptr = NULL;
					
			if (frpt) rptptr = &rpt;
			else rptptr = NULL;
				
			rv = saHpiEventLogEntryGet(sessionid,SAHPI_UNSPECIFIED_RESOURCE_ID,
						entryid,&preventryid,
						&nextentryid, &el, rdrptr, rptptr);
								
			if (fdebug) printf("saHpiEventLogEntryGet %s\n",
					    			oh_lookup_error(rv));
								   
			if (rv == SA_OK) {
				oh_print_eventlogentry(&el, 6);
				
				if (frdr) {
					if (rdrptr->RdrType == SAHPI_NO_RECORD)
						printf("            No RDR associated with EventType =  %s\n\n", 
						oh_lookup_eventtype(el.Event.EventType));
					else	
						oh_print_rdr(rdrptr, 12);
				}
				
				if (frpt) {
					if (rptptr->ResourceCapabilities == 0)
						printf("            No RPT associated with EventType =  %s\n\n", 
						oh_lookup_eventtype(el.Event.EventType));							
					else 
						oh_print_rptentry(rptptr, 10);
				}
				
				preventryid = entryid;
				entryid = nextentryid;
			} else {
				printf("Domain EventLogEntryGet, error = %d, %s\n", rv, oh_lookup_error(rv));
				break;
			}
		}
				
	} else 
		printf("\tSEL is empty.\n\n");		    
			    
	
        rv = saHpiSessionClose(sessionid);
	return(0);
}