int ForEachDomain(SaHpiSessionIdT session_id) { SaErrorT status; int retval = SAF_TEST_UNKNOWN; SaHpiDomainInfoT DomainInfo; status = saHpiDomainInfoGet(session_id, &DomainInfo); if (status != SA_OK) { e_print(saHpiDomainInfoGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (DomainInfo.DomainCapabilities & SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY) { // Domain does not have auto-insert // write capability retval = SAF_TEST_NOTSUPPORT; } } if (retval == SAF_TEST_UNKNOWN) { // // Call the function passing in a Timeout value // which is negative and not equal to // SAHPI_TIMEOUT_BLOCK or SAHPI_TIMEOUT_IMMEDIATE. // status = saHpiAutoInsertTimeoutSet(session_id, BAD_TIMEOUT_VALUE); if (status != SA_ERR_HPI_INVALID_PARAMS) { e_print(saHpiAutoInsertTimeoutSet, SA_ERR_HPI_INVALID_PARAMS, status); retval = SAF_TEST_FAIL; } else retval = SAF_TEST_PASS; } return (retval); }
static ret_code_t domain_info(void) { SaHpiDomainInfoT info; SaHpiTextBufferT *buf; SaErrorT rv; char date[30]; rv = saHpiDomainInfoGet(Domain->sessionId, &info); if (rv != SA_OK) { printf("ERROR!!! saHpiDomainInfoGet: %s\n", oh_lookup_error(rv)); return(HPI_SHELL_CMD_ERROR); }; printf("Domain: %d Capabil: 0x%x IsPeer: %d Guid: %s\n", info.DomainId, info.DomainCapabilities, info.IsPeer, info.Guid); buf = &(info.DomainTag); print_text_buffer_text(" Tag: ", buf, NULL, ui_print); printf("\n"); time2str(info.DrtUpdateTimestamp, date, 30); printf(" DRT update count: %d DRT Timestamp : %s\n", info.DrtUpdateCount, date); time2str(info.RptUpdateTimestamp, date, 30); printf(" RPT update count: %d RPT Timestamp : %s\n", info.RptUpdateCount, date); time2str(info.DatUpdateTimestamp, date, 30); printf(" DAT update count: %d DAT Timestamp : %s\n", info.DatUpdateCount, date); printf(" ActiveAlarms: %d CriticalAlarms: %d Major: %d" "Minor: %d Limit: %d\n", info.ActiveAlarms, info.CriticalAlarms, info.MajorAlarms, info.MinorAlarms, info.DatUserAlarmLimit); printf(" DatOverflow : %d\n", info.DatOverflow); return(HPI_SHELL_OK); }
static int bladehpi_status(StonithPlugin *s) { struct pluginDevice * dev; SaErrorT ohrc; SaHpiDomainInfoT ohdi; int rc = S_OK; if (Debug) { LOG(PIL_DEBUG, "%s: called", __FUNCTION__); } ERRIFWRONGDEV(s, S_OOPS); dev = (struct pluginDevice *)s; rc = open_hpi_session(dev); if( rc != S_OK ) return rc; /* Refresh the hostlist only if RPTs updated */ ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); rc = S_BADCONFIG; goto done; } if (dev->ohrptcnt != ohdi.RptUpdateCount) { free_bladehpi_hostlist(dev); if (get_bladehpi_hostlist(dev) != S_OK) { LOG(PIL_CRIT, "Unable to obtain list of hosts in %s" , __FUNCTION__); rc = S_BADCONFIG; goto done; } } /* At this point, hostlist is up to date */ if (dev->ohsensid && dev->ohsensnum) { /* * For accurate status, need to make a call that goes out to * BladeCenter MM because the calls made so far by this * function (and perhaps get_bladehpi_hostlist) only retrieve * information from memory cached by OpenHPI */ ohrc = saHpiSensorReadingGet(dev->ohsession , dev->ohsensid, dev->ohsensnum, NULL, NULL); if (ohrc == SA_ERR_HPI_BUSY || ohrc == SA_ERR_HPI_NO_RESPONSE) { LOG(PIL_CRIT, "Unable to connect to BladeCenter in %s" , __FUNCTION__); rc = S_OOPS; goto done; } } done: close_hpi_session(dev); return (rc == S_OK) ? (dev->ohdevid ? S_OK : S_OOPS) : rc; }
SaErrorT get_sessionId(Domain_t *domain) { SaErrorT rv; SaHpiDomainInfoT info; if (domain->session_opened) return(SA_OK); rv = saHpiSessionOpen(domain->domainId, &(domain->sessionId), NULL); if (rv != SA_OK) { printf("saHpiSessionOpen error %s\n", oh_lookup_error(rv)); return rv; }; domain->session_opened = 1; rv = saHpiDomainInfoGet(domain->sessionId, &info); if (rv != SA_OK) { printf("ERROR!!! saHpiDomainInfoGet: %s\n", oh_lookup_error(rv)); return(rv); }; domain->domainId = info.DomainId; return(SA_OK); }
/** * * @sessionid: * * @return: */ SaErrorT populate_saHpiAutoInsertTimeoutTable(SaHpiSessionIdT sessionid) { SaErrorT rv; int new_row = MIB_FALSE; SaHpiDomainInfoT domain_info; SaHpiTimeoutT timeout; oid auto_insert_oid[AUTO_INSERT_INDEX_NR]; netsnmp_index auto_insert_index; saHpiAutoInsertTimeoutTable_context *auto_insert_context; DEBUGMSGTL ((AGENT, "populate_saHpiAutoInsertTimeoutTable: called\n")); rv = saHpiDomainInfoGet(sessionid, &domain_info); if (rv != SA_OK) { DEBUGMSGTL ((AGENT, "populate_saHpiAutoInsertTimeoutTable: saHpiDomainInfoGet Failed: rv = %d\n", rv)); return AGENT_ERR_INTERNAL_ERROR; } auto_insert_index.len = AUTO_INSERT_INDEX_NR; auto_insert_oid[0] = domain_info.DomainId; auto_insert_index.oids = (oid *) & auto_insert_oid; /* See if Row exists. */ auto_insert_context = NULL; auto_insert_context = CONTAINER_FIND(cb.container, &auto_insert_index); if (!auto_insert_context) { // New entry. Add it auto_insert_context = saHpiAutoInsertTimeoutTable_create_row(&auto_insert_index); new_row = MIB_TRUE; } if (!auto_insert_context) { snmp_log (LOG_ERR, "Not enough memory for an Auto Insert Timeout row!"); return AGENT_ERR_INTERNAL_ERROR; } rv = saHpiAutoInsertTimeoutGet(sessionid, &timeout); if (rv != SA_OK) { DEBUGMSGTL ((AGENT, "populate_saHpiAutoInsertTimeoutTable: saHpiAutoInsertTimeoutGet Failed: rv = %d\n", rv)); return AGENT_ERR_INTERNAL_ERROR; } auto_insert_context->saHpiAutoInsertTimeoutForInsert_len = sizeof(SaHpiTimeoutT); memcpy(auto_insert_context->saHpiAutoInsertTimeoutForInsert, &timeout, auto_insert_context->saHpiAutoInsertTimeoutForInsert_len); if (new_row == MIB_TRUE) CONTAINER_INSERT (cb.container, auto_insert_context); return SA_OK; }
int main(int argc, char **argv) { SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; GOptionContext *context; atag.tlen = 0; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Shows resources' inventory records\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION )) { //TODO: Feature 880127? g_option_context_free (context); return 1; } g_option_context_free (context); if (fatag) { atag.tag = (char *)strdup(fatag); atag.tlen = strlen(fatag); g_free(fatag); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (copt.debug) DBG("saHpiDomainInfoGet rv = %d",rv); // if (copt.debug) DBG("RptInfo: UpdateCount = %x, UpdateTime = %lx", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (copt.debug) DBG("Starting Discovery, pass %u ...",nloops); rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover rv = %d",rv); if (rv != SA_OK) { CRIT("saHpiDiscover error %d",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%u rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* obtain resource tag */ char tagstr[MAX_STRSIZE]; fixstr(&rptentry.ResourceTag,tagstr); /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; resourceid = rptentry.ResourceId; if (copt.debug) DBG("rptentry[%u] resourceid=%d", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%u] Tag: %s \thas inventory capability\n", rptentryid,tagstr); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (copt.debug) DBG("saHpiRdrGet[%u] rv = %d",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (copt.debug) DBG("Rdr[%u] type = %u tag = %s",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (copt.debug) { DBG("Rdr[%x] is inventory, IdrId=%x",rdr.RecordId,idrid); DBG("Inv BufferSize=%u", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (copt.debug) DBG("IDR Info: ok "); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((atag.tlen > 0) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (copt.debug) DBG("walkInventory rv_rdr = %d",rv_rdr); } /* Good write - re-read */ } /*endif foundasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (copt.debug) DBG("rdr type = %u", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (copt.debug) DBG("Resource[%u] Tag: %s", rptentryid,tagstr); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (copt.debug) DBG("loop %u inventory found = %d",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); return 0; }
/********************************************************** * Main Function * takes no arguments * * returns: SAF_TEST_PASS when successfull * SAF_TEST_FAIL when an unexpected error occurs *************************************************************/ int main(int argc, char **argv) { SaHpiSessionIdT session, new_session; SaErrorT status; SaHpiDomainInfoT domain_info; SaHpiEntryIdT entry_id, next_entry_id, entry_id_domain2; SaHpiDrtEntryT domain_table_entry; int retval = SAF_TEST_UNKNOWN; SaHpiTextBufferT new_tag, old_tag, old_tag_domain2; SaHpiEntityPathT old_entity_path; SaHpiRptEntryT Report; SaHpiBoolT old_session_open = SAHPI_FALSE; SaHpiBoolT new_session_open = SAHPI_FALSE; SaHpiBoolT found_res = SAHPI_FALSE; SaHpiResourceIdT res_id_domain1; // // Open the session // status = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // old_session_open = SAHPI_TRUE; // // Get the DRT info // status = saHpiDomainInfoGet(session, &domain_info); if (status != SA_OK) { //Unable to discover e_print(saHpiDomainInfoGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!domain_info.IsPeer) retval = SAF_TEST_NOTSUPPORT; else { status = saHpiDrtEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &domain_table_entry); if (status != SA_OK) { e_print(saHpiDrtEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //Get the information of another domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiSessionOpen(domain_table_entry.DomainId, &new_session, NULL); if (status != SA_OK) { e_print(saHpiSessionOpen, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { // // Discover Resources // new_session_open = SAHPI_TRUE; } } //update the resource tag in the first domain if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(session, SAHPI_FIRST_ENTRY, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { old_entity_path = Report.ResourceEntity; old_tag.DataType = Report.ResourceTag.DataType; old_tag.Language = Report.ResourceTag.Language; old_tag.DataLength = Report.ResourceTag.DataLength; memcpy(old_tag.Data, Report.ResourceTag.Data, sizeof(Report.ResourceTag.Data)); res_id_domain1 = Report.ResourceId; //find the exist tag for resource in the 2nd domain while (next_entry_id != SAHPI_LAST_ENTRY) { entry_id = next_entry_id; status = saHpiRptEntryGet(new_session, entry_id, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; break; } else { if (is_entitypath_equal (&Report.ResourceEntity, &old_entity_path)) { found_res = SAHPI_TRUE; entry_id_domain2 = Report.EntryId; old_tag_domain2.DataType = Report.ResourceTag.DataType; old_tag_domain2.Language = Report.ResourceTag.Language; old_tag_domain2.DataLength = Report.ResourceTag. DataLength; memcpy(old_tag_domain2.Data, Report.ResourceTag.Data, sizeof(Report. ResourceTag. Data)); break; } } } if (!found_res) retval = SAF_TEST_FAIL; if (retval == SAF_TEST_UNKNOWN) { memset(&new_tag, 0, sizeof(new_tag)); new_tag.DataType = SAHPI_TL_TYPE_BINARY; new_tag.Language = SAHPI_LANG_ENGLISH; new_tag.DataLength = sizeof(TEST_STR); memcpy(new_tag.Data, TEST_STR, new_tag.DataLength); status = saHpiResourceTagSet(session, res_id_domain1, &new_tag); if (status != SA_OK) { e_print(saHpiResourceTagSet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } } } } //find the resource in the second domain and check whether the resource tag has been changed if (retval == SAF_TEST_UNKNOWN) { status = saHpiRptEntryGet(new_session, entry_id_domain2, &next_entry_id, &Report); if (status != SA_OK) { e_print(saHpiRptEntryGet, SA_OK, status); retval = SAF_TEST_UNRESOLVED; } else { if (!tag_cmp(&Report.ResourceTag, &old_tag_domain2)) retval = SAF_TEST_PASS; else { m_print ("The resource tag for the resource in the second domain "); m_print ("is different than the resource tag for the resource "); m_print ("in the first domain. They should have been the same!"); retval = SAF_TEST_FAIL; } } } // // Close all the session // if (old_session_open) { status = saHpiSessionClose(session); if (status != SA_OK) { m_print("The old session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } if (new_session_open) { status = saHpiSessionClose(new_session); if (status != SA_OK) { m_print("The new session failed to close properly!"); e_print(saHpiSessionClose, SA_OK, status); } } return retval; }
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); }
static SaErrorT show_domains(void) { SaErrorT rv = SA_OK; oHpiDomainEntryT domainentry; SaHpiEntryIdT domainentryid; SaHpiEntryIdT nextdomainentryid; SaHpiDomainInfoT relateddomaininfo; SaHpiDomainIdT relateddomainid = SAHPI_UNSPECIFIED_DOMAIN_ID; SaHpiSessionIdT relatedsessionid; /* walk the Domain Table */ domainentryid = SAHPI_FIRST_ENTRY; do { if (fdebug) printf("oHpiDomainEntryGet called with entry=%u\n", domainentryid); rv = oHpiDomainEntryGet( domainentryid,&nextdomainentryid,&domainentry); if ((rv != SA_OK) || fdebug) printf("oHpiDomainEntryGet returns %s\n", oh_lookup_error(rv)); if (rv == SA_OK ) { if (fdebug) printf("oHpiDomainEntryGet provides domainid=%u," " nextentryid=%u\n", domainentry.id, nextdomainentryid); printf("Domain defined on host(%s:%u) with id: %u\n", (char *)domainentry.daemonhost.Data, domainentry.port, domainentry.id); if (fverbose) { /* display the domaininfo for that related domain */ relateddomainid = domainentry.id; rv = saHpiSessionOpen(relateddomainid, &relatedsessionid,NULL); if (rv != SA_OK) { printf("Domain %u cannot be opened\n", relateddomainid); continue; } if (fdebug) { printf("saHpiSessionOpen returns with SessionId %u\n", relatedsessionid); printf("saHpiDomainInfoGet for domain %u\n", relateddomainid); } rv = saHpiDomainInfoGet(relatedsessionid, &relateddomaininfo); if (rv!=SA_OK) { printf("\nDomaininfo of domain %u cannot be " "retrieved.\n", relateddomainid); if (fdebug) printf("saHpiDomainInfoGet for domain " "%u failed with returncode %s\n", relateddomainid, oh_lookup_error(rv)); } else { /* Print info about related domain */ rv = print_domaininfo(relateddomaininfo,1); } rv = saHpiSessionClose(relatedsessionid); if (fdebug) printf("saHpiSessionClose returns %s\n", oh_lookup_error(rv)); } //verbose } else if (rv == SA_ERR_HPI_NOT_PRESENT) { if (domainentryid == SAHPI_FIRST_ENTRY) printf("Domain list is empty. \n"); else printf("Internal error while walking the Domainlist\n"); } else printf("Internal error while walking the Domainlist\n"); domainentryid = nextdomainentryid; } while ((rv == SA_OK) && (domainentryid != SAHPI_LAST_ENTRY)); return(rv); }
int main(int argc, char **argv) { int c; int is_reset = 0; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiResourceIdT resourceid; SaHpiResetActionT action = -1; uchar breset; uchar bopt; uchar fshutdown = 0; printf("%s ver %s\n", argv[0],progver); breset = 3; /* hard reset as default */ bopt = 0; /* Boot Options default */ while ( (c = getopt( argc, argv,"rdwconsx?")) != EOF ) switch(c) { case 'd': breset = 0; break; /* power down */ case 'r': breset = 3; action = SAHPI_COLD_RESET; break; /* hard reset */ case 'w': action = SAHPI_WARM_RESET; break; case 'x': fdebug = 1; break; /* debug messages */ case 'c': breset = 2; break; /* power cycle */ case 'o': fshutdown = 1; break; /* shutdown OS */ case 'n': breset = 4; break; /* interrupt (NMI) */ case 's': bopt = 1; break; /* hard reset to svc part */ default: Usage(argv[0]); exit(1); } if (fshutdown) breset = 5; /* soft shutdown option */ 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 error %d\n",rv); exit(-1); } rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover rv = %d\n",rv); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet rv = %d\n",rv); printf("RptInfo: UpdateCount = %x, 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)) { SaErrorT rv1; rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("saHpiRptEntryGet: rv = %d\n",rv); if (rv == SA_OK) { /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; resourceid = rptentry.ResourceId; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] resourceid=%d tag: %s\n", entryid,resourceid, rptentry.ResourceTag.Data); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_RESET) { is_reset = 1; rv1 = saHpiResourceResetStateSet(sessionid, resourceid, action); //resourceid, SAHPI_POWER_OFF); printf("ResetStateSet status = %d...requested %d\n",rv1, action); } } rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); if (is_reset == 0) printf("No resources with Reset capability found\n"); return(0); }
int main(int argc, char **argv) { SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiWatchdogNumT wdnum; SaHpiWatchdogT wdt; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Read and Enables the watchdog timer.\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION //TODO: Feature 880127 - OHC_VERBOSE_OPTION )) { // no verbose mode implemented g_option_context_free (context); return 1; } g_option_context_free (context); if (ftimeout == 0) ftimeout = 120; else fenable = TRUE; rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) return rv; rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover rv = %s",oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (copt.debug) DBG("saHpiDomainInfoGet rv = %s",oh_lookup_error(rv)); printf("DomainInfo: UpdateCount = %x, 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 (rv != SA_OK) printf("RptEntryGet: rv = %s\n",oh_lookup_error(rv)); if (rv == SA_OK) { /* handle WDT for this RPT entry */ resourceid = rptentry.ResourceId; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; if (copt.debug) printf("rptentry[%u] resourceid=%u capab=%x tag: %s\n", rptentryid, resourceid, rptentry.ResourceCapabilities, rptentry.ResourceTag.Data); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_WATCHDOG) { printf("%s has watchdog capability\n",rptentry.ResourceTag.Data); wdnum = SAHPI_DEFAULT_WATCHDOG_NUM; rv = saHpiWatchdogTimerGet(sessionid,resourceid,wdnum,&wdt); if (copt.debug) DBG("saHpiWatchdogTimerGet rv = %s",oh_lookup_error(rv)); if (rv != 0) { printf("saHpiWatchdogTimerGet error = %s\n",oh_lookup_error(rv)); rv = 0; rptentryid = nextrptentryid; continue; } show_wdt(wdnum,&wdt); if (fdisable) { printf("Disabling watchdog timer ...\n"); /* clear FRB2, timeout back to 120 sec */ /* TODO: add setting wdt values here */ wdt.TimerUse = SAHPI_WTU_NONE; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = SAHPI_WA_NO_ACTION; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = SAHPI_WPI_NONE; /* 0=none 1=SMI 2=NMI 3=message */ wdt.PreTimeoutInterval = 60000; /*msec*/ wdt.InitialCount = 120000; /*msec*/ wdt.PresentCount = 120000; /*msec*/ rv = saHpiWatchdogTimerSet(sessionid,resourceid,wdnum,&wdt); if (copt.debug) DBG("saHpiWatchdogTimerSet rv = %s",oh_lookup_error(rv)); if (rv == 0) show_wdt(wdnum,&wdt); } else if (fenable) { printf("Enabling watchdog timer ...\n"); /* hard reset action, no pretimeout, clear SMS/OS when done */ /* use ftimeout for timeout */ wdt.TimerUse = SAHPI_WTU_SMS_OS; /* 1=FRB2 2=POST 3=OSLoad 4=SMS_OS 5=OEM */ wdt.TimerAction = SAHPI_WA_RESET; /* 0=none 1=reset 2=powerdown 3=powercycle */ wdt.PretimerInterrupt = SAHPI_WPI_NMI; /* 0=none 1=SMI 2=NMI 3=message */ wdt.PreTimeoutInterval = (ftimeout / 2) * 1000; /*msec*/ wdt.InitialCount = ftimeout * 1000; /*msec*/ wdt.PresentCount = ftimeout * 1000; /*msec*/ rv = saHpiWatchdogTimerSet(sessionid,resourceid,wdnum,&wdt); if (copt.debug) DBG("saHpiWatchdogTimerSet rv = %s",oh_lookup_error(rv)); if (rv == 0) show_wdt(wdnum,&wdt); } if (freset && !fdisable) { printf("Resetting watchdog timer ...\n"); rv = saHpiWatchdogTimerReset(sessionid,resourceid,wdnum); if (copt.debug) DBG("saHpiWatchdogTimerReset rv = %s",oh_lookup_error(rv)); } } /*watchdog capability*/ rptentryid = nextrptentryid; /* get next RPT (usu only one anyway) */ } /*endif RPT ok*/ } /*end while loop*/ rv = saHpiSessionClose(sessionid); return 0; }
static int get_bladehpi_hostlist(struct pluginDevice *dev) { struct blade_info * bi; SaErrorT ohrc; SaHpiEntryIdT ohnextid; SaHpiRptEntryT ohRPT; SaHpiDomainInfoT ohdi; SaHpiUint32T ohupdate; if (Debug) { LOG(PIL_DEBUG, "%s: called, dev->device=%s" , __FUNCTION__, dev->device); } if (dev->device == NULL || *dev->device == 0) { LOG(PIL_CRIT, "Unconfigured stonith object in %s" , __FUNCTION__); return S_BADCONFIG; } ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); return S_BADCONFIG; } try_again: ohupdate = ohdi.RptUpdateCount; dev->ohdevid = dev->ohsensid = dev->ohsensnum = 0; ohnextid = SAHPI_FIRST_ENTRY; do { char blname[SAHPI_MAX_TEXT_BUFFER_LENGTH]; int blnum; ohrc = saHpiRptEntryGet(dev->ohsession, ohnextid , &ohnextid, &ohRPT); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get RPT entry in %s (%d)" , __FUNCTION__, ohrc); free_bladehpi_hostlist(dev); return S_BADCONFIG; } switch (get_resource_type(dev->device, &ohRPT)) { case OHRES_BLADECENT: dev->ohdevid = ohRPT.ResourceId; if (Debug) { LOG(PIL_DEBUG, "BladeCenter '%s' has id %d" , (char*)ohRPT.ResourceTag.Data , dev->ohdevid); } break; case OHRES_MGMTMOD: if (ohRPT.ResourceCapabilities&SAHPI_CAPABILITY_SENSOR){ dev->ohsensnum = get_sensor_num(dev->ohsession , ohRPT.ResourceId); if (dev->ohsensnum) { dev->ohsensid = ohRPT.ResourceId; if (Debug) { LOG(PIL_DEBUG , "MgmtModule '%s' has id %d " "with sensor #%d" , (char*)ohRPT.ResourceTag.Data , dev->ohsensid , dev->ohsensnum); } } } break; case OHRES_BLADE: if ((bi = (struct blade_info *) MALLOC(sizeof(struct blade_info))) == NULL) { LOG(PIL_CRIT, "Out of memory in %s" , __FUNCTION__); free_bladehpi_hostlist(dev); return S_OOPS; } /* * New format consists of "Blade N - name" while older * format consists only of "name"; we only need to * stash name because ResourceID is the important info */ if (sscanf((char*)ohRPT.ResourceTag.Data, "Blade %d - %s" , &blnum, blname) == 2) { bi->name = STRDUP(blname); } else { bi->name = STRDUP((char*)ohRPT.ResourceTag.Data); } if (bi->name == NULL) { LOG(PIL_CRIT, "Out of memory for strdup in %s" , __FUNCTION__); free_bladehpi_hostlist(dev); return S_OOPS; } bi->resourceId = ohRPT.ResourceId; bi->resourceCaps = ohRPT.ResourceCapabilities; dev->hostlist = g_list_append(dev->hostlist, bi); if (Debug) { LOG(PIL_DEBUG, "Blade '%s' has id %d, caps %x" , bi->name, bi->resourceId, bi->resourceCaps); } break; } } while (ohrc == SA_OK && ohnextid != SAHPI_LAST_ENTRY); ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); free_bladehpi_hostlist(dev); return S_BADCONFIG; } if (ohupdate != ohdi.RptUpdateCount) { free_bladehpi_hostlist(dev); if(Debug){ LOG(PIL_DEBUG, "Looping through entries again," " count changed from %d to %d" , ohupdate, ohdi.RptUpdateCount); } goto try_again; } dev->ohrptcnt = ohupdate; return S_OK; }
int main(int argc, char **argv) { int month, day, year; int day_array[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct tm new_tm_time; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiTimeT oldtime; SaHpiTimeT newtime; SaHpiTimeT readbacktime; SaHpiTextBufferT buffer; GOptionContext *context; /* Print version strings */ oh_prog_version(argv[0]); /* Parsing options */ static char usetext[]="- Exercises Event Log clock APIs.\n " OH_SVN_REV; OHC_PREPARE_REVISION(usetext); context = g_option_context_new (usetext); g_option_context_add_main_entries (context, my_options, NULL); if (!ohc_option_parse(&argc, argv, context, &copt, OHC_ALL_OPTIONS - OHC_ENTITY_PATH_OPTION // not applicable - OHC_VERBOSE_OPTION )) { // no verbose mode g_option_context_free (context); EXIT1; } g_option_context_free (context); if ( !findate || !fintime) { CRIT("Please enter date and time to be set, or try --help."); EXIT1; } if (findate) { if (copt.debug) printf("New date to be set: %s\n",findate); if (sscanf(findate,"%2d/%2d/%4d", &month, &day, &year) != 3) { CRIT("%s: Invalid date", argv[0]); EXIT1; } /* check month, day and year for correctness */ if ((month < 1) || (month > 12)) { CRIT("%s: Month out of range: (%d)", argv[0], month); EXIT1; }; if (year < 1900) { CRIT("%s: Year out of range: (%d)", argv[0], year); EXIT1; }; month--; if (month == 1) { /* if the given year is a leap year */ if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) day_array[1] = 29; }; if ((day < 1) || (day > day_array[month])) { CRIT("%s: Day out of range: (%d)", argv[0], day); EXIT1; }; new_tm_time.tm_mon = month; new_tm_time.tm_mday = day; new_tm_time.tm_year = year - 1900; } if (fintime) { if (copt.debug) DBG("New time to be set: %s",fintime); if (sscanf(fintime,"%2d:%2d:%2d", &new_tm_time.tm_hour, &new_tm_time.tm_min, &new_tm_time.tm_sec) != 3) { CRIT("%s: Invalid time", argv[0]); EXIT1; } /* check hours, minutes and seconds for correctness */ if ((new_tm_time.tm_hour < 0) || (new_tm_time.tm_hour > 24)) { CRIT("%s: Hours out of range: (%d)", argv[0], new_tm_time.tm_hour); EXIT1; }; if ((new_tm_time.tm_min < 0) || (new_tm_time.tm_min > 60)) { CRIT("%s: Minutes out of range: (%d)", argv[0], new_tm_time.tm_min); EXIT1; }; if ((new_tm_time.tm_sec < 0) || (new_tm_time.tm_sec > 60)) { CRIT("%s: Seconds out of range: (%d)", argv[0], new_tm_time.tm_sec); EXIT1; } } if (copt.debug) DBG("Values passed to mktime():\n\tmon %d\n\tday %d\n\tyear %d\n\tHH %d\n\tMM %d\n\tSS %d", new_tm_time.tm_mon, new_tm_time.tm_mday, new_tm_time.tm_year, new_tm_time.tm_hour, new_tm_time.tm_min, new_tm_time.tm_sec); newtime = (SaHpiTimeT) mktime(&new_tm_time) * 1000000000; if (copt.debug) DBG("New date and time in SaHpiTimeT %" PRId64 "\n", (int64_t)newtime); rv = ohc_session_open_by_option ( &copt, &sessionid); if (rv != SA_OK) EXIT1; if (copt.debug) DBG("saHpiDiscover"); rv = saHpiDiscover(sessionid); if (copt.debug) DBG("saHpiDiscover %s", oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (copt.debug) DBG("saHpiDomainInfoGet %s", oh_lookup_error(rv)); printf("DomainInfo: RptUpdateCount = %u, RptUpdateTimestamp = %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 (copt.debug) DBG("saHpiRptEntryGet %s", oh_lookup_error(rv)); if ((rv == SA_OK) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { resourceid = rptentry.ResourceId; if (copt.debug) DBG("RPT %x capabilities = %x", resourceid, rptentry.ResourceCapabilities); rv = saHpiEventLogTimeGet(sessionid, resourceid, &oldtime); oh_decode_time(oldtime, &buffer); printf ("\nCurrent event log time on HPI target: %s\n", buffer.Data); printf ("Setting new event log time on HPI target ...\n"); rv = saHpiEventLogTimeSet(sessionid, resourceid, newtime); if (rv != SA_OK) { CRIT("saHpiEventLogTimeSet returned %s", oh_lookup_error(rv)); } rv = saHpiEventLogTimeGet(sessionid, resourceid, &readbacktime); oh_decode_time(readbacktime, &buffer); printf ("Read-Back-Check event log time: %s\n", buffer.Data); } // entryid = SAHPI_OLDEST_ENTRY; rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); g_free(findate); g_free(fintime); return(0); }
static int bladehpi_reset_req(StonithPlugin *s, int request, const char *host) { GList * node = NULL; struct pluginDevice * dev = NULL; struct blade_info * bi = NULL; SaHpiPowerStateT ohcurstate, ohnewstate; SaHpiDomainInfoT ohdi; SaErrorT ohrc; int rc = S_OK; if (Debug) { LOG(PIL_DEBUG, "%s: called, request=%d, host=%s" , __FUNCTION__, request, host); } ERRIFWRONGDEV(s, S_OOPS); if (host == NULL) { LOG(PIL_CRIT, "Invalid host argument to %s", __FUNCTION__); rc = S_OOPS; goto done; } dev = (struct pluginDevice *)s; rc = open_hpi_session(dev); if( rc != S_OK ) return rc; ohrc = saHpiDomainInfoGet(dev->ohsession, &ohdi); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get domain info in %s (%d)" , __FUNCTION__, ohrc); rc = S_BADCONFIG; goto done; } if (dev->ohrptcnt != ohdi.RptUpdateCount) { free_bladehpi_hostlist(dev); if (get_bladehpi_hostlist(dev) != S_OK) { LOG(PIL_CRIT, "Unable to obtain list of hosts in %s" , __FUNCTION__); rc = S_OOPS; goto done; } } for (node = g_list_first(dev->hostlist) ; node != NULL ; node = g_list_next(node)) { bi = ((struct blade_info *)node->data); if (Debug) { LOG(PIL_DEBUG, "Found host %s in hostlist", bi->name); } if (!strcasecmp(bi->name, host)) { break; } } if (!node || !bi) { LOG(PIL_CRIT , "Host %s is not configured in this STONITH module, " "please check your configuration information", host); rc = S_OOPS; goto done; } /* Make sure host has proper capabilities for get */ if (!(bi->resourceCaps & SAHPI_CAPABILITY_POWER)) { LOG(PIL_CRIT , "Host %s does not have power capability", host); rc = S_OOPS; goto done; } ohrc = saHpiResourcePowerStateGet(dev->ohsession, bi->resourceId , &ohcurstate); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to get host %s power state (%d)" , host, ohrc); rc = S_OOPS; goto done; } switch (request) { case ST_POWERON: if (ohcurstate == SAHPI_POWER_ON) { LOG(PIL_INFO, "Host %s already on", host); goto done; } ohnewstate = SAHPI_POWER_ON; break; case ST_POWEROFF: if (ohcurstate == SAHPI_POWER_OFF) { LOG(PIL_INFO, "Host %s already off", host); goto done; } ohnewstate = SAHPI_POWER_OFF; break; case ST_GENERIC_RESET: if (ohcurstate == SAHPI_POWER_OFF) { ohnewstate = SAHPI_POWER_ON; } else { ohnewstate = SAHPI_POWER_CYCLE; } break; default: LOG(PIL_CRIT, "Invalid request argument to %s" , __FUNCTION__); rc = S_INVAL; goto done; } if (!dev->softreset && (ohnewstate == SAHPI_POWER_CYCLE)) { int maxwait; ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, SAHPI_POWER_OFF); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state to" " OFF (%d)", host, ohrc); rc = S_OOPS; goto done; } /* * Must wait for power off here or subsequent power on request * may take place while power is still on and thus ignored */ maxwait = MAX_POWEROFF_WAIT; do { maxwait--; sleep(1); ohrc = saHpiResourcePowerStateGet(dev->ohsession , bi->resourceId, &ohcurstate); } while ((ohrc == SA_OK) && (ohcurstate != SAHPI_POWER_OFF) && (maxwait > 0)); if (Debug) { LOG(PIL_DEBUG, "Waited %d seconds for power off" , MAX_POWEROFF_WAIT - maxwait); } ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, SAHPI_POWER_ON); if (ohrc != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state to" " ON (%d)", host, ohrc); rc = S_OOPS; goto done; } } else { /* Make sure host has proper capabilities to reset */ if ((ohnewstate == SAHPI_POWER_CYCLE) && (!(bi->resourceCaps & SAHPI_CAPABILITY_RESET))) { LOG(PIL_CRIT , "Host %s does not have reset capability" , host); rc = S_OOPS; goto done; } if ((ohrc = saHpiResourcePowerStateSet(dev->ohsession , bi->resourceId, ohnewstate)) != SA_OK) { LOG(PIL_CRIT, "Unable to set host %s power state (%d)" , host, ohrc); rc = S_OOPS; goto done; } } #ifdef IBMBC_WAIT_FOR_OFF if (ohnewstate == SAHPI_POWER_OFF) { int maxwait = MAX_POWEROFF_WAIT; do { maxwait--; sleep(1); ohrc = saHpiResourcePowerStateGet(dev->ohsession , bi->resourceId, &ohcurstate); } while ((ohrc == SA_OK) && (ohcurstate != SAHPI_POWER_OFF) && (maxwait > 0)); if (Debug) { LOG(PIL_DEBUG, "Waited %d seconds for power off" , MAX_POWEROFF_WAIT - maxwait); } } #endif LOG(PIL_INFO, "Host %s %s %d.", host, __FUNCTION__, request); done: close_hpi_session(dev); return rc; }
/* * int populate_saHpiDomainInfoTable(SaHpiSessionIdT sessionid) */ int populate_saHpiDomainInfoTable(SaHpiSessionIdT sessionid) { SaErrorT rv; int new_row = MIB_FALSE; SaHpiDomainInfoT domain_info; oid domain_info_oid[DOMAIN_INFO_INDEX_NR]; netsnmp_index domain_info_index; saHpiDomainInfoTable_context *domain_info_context; DEBUGMSGTL ((AGENT, "populate_saHpiDomainInfoTable\n")); rv = saHpiDomainInfoGet(sessionid, &domain_info); if (rv != SA_OK) { DEBUGMSGTL ((AGENT, "saHpiDomainInfoGet Failed: rv = %d\n",rv)); return AGENT_ERR_INTERNAL_ERROR; } domain_info_index.len = DOMAIN_INFO_INDEX_NR; domain_info_oid[0] = domain_info.DomainId; domain_info_index.oids = (oid *) & domain_info_oid; /* See if it exists. */ domain_info_context = NULL; domain_info_context = CONTAINER_FIND (cb.container, &domain_info_index); if (!domain_info_context) { // New entry. Add it domain_info_context = saHpiDomainInfoTable_create_row ( &domain_info_index); new_row = MIB_TRUE; } if (!domain_info_context) { snmp_log (LOG_ERR, "Not enough memory for a DomainInfo row!"); return AGENT_ERR_INTERNAL_ERROR; } /** SaHpiDomainId = ASN_UNSIGNED */ domain_info_context->saHpiDomainId = domain_info.DomainId; /** BITS = ASN_OCTET_STR */ memset( domain_info_context->saHpiDomainCapabilities, 0, sizeof(domain_info_context->saHpiDomainCapabilities)); if(domain_info.DomainCapabilities == (SaHpiDomainCapabilitiesT)0X00000001) { memcpy( domain_info_context->saHpiDomainCapabilities, "SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY", sizeof("SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY") ); domain_info_context->saHpiDomainCapabilities_len = sizeof("SAHPI_DOMAIN_CAP_AUTOINSERT_READ_ONLY"); } else { domain_info_context->saHpiDomainCapabilities_len = 0; } /** TruthValue = ASN_INTEGER */ domain_info_context->saHpiDomainIsPeer = (domain_info.IsPeer == SAHPI_TRUE) ? MIB_TRUE : MIB_FALSE; /** SaHpiTextType = ASN_INTEGER */ domain_info_context->saHpiDomainTagTextType = domain_info.DomainTag.DataType; /** SaHpiTextLanguage = ASN_INTEGER */ domain_info_context->saHpiDomainTagTextLanguage = domain_info.DomainTag.Language; /** SaHpiText = ASN_OCTET_STR */ memcpy(domain_info_context->saHpiDomainTag, domain_info.DomainTag.Data, domain_info.DomainTag.DataLength); domain_info_context->saHpiDomainTag_len = domain_info.DomainTag.DataLength; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainReferenceUpdateCount = domain_info.DrtUpdateCount; /** SaHpiTime = ASN_COUNTER64 */ assign_timestamp(&domain_info.DrtUpdateTimestamp, &domain_info_context->saHpiDomainReferenceUpdateTimestamp); /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainResourcePresenceUpdateCount = domain_info.RptUpdateCount; /** SaHpiTime = ASN_COUNTER64 */ assign_timestamp(&domain_info.RptUpdateTimestamp, &domain_info_context->saHpiDomainResourcePresenceUpdateTimestamp);; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainAlarmUpdateCount = domain_info.DatUpdateCount; /** SaHpiTime = ASN_COUNTER64 */ assign_timestamp(&domain_info.DatUpdateTimestamp, &domain_info_context->saHpiDomainAlarmUpdateTimestamp); /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainActiveAlarms = domain_info.ActiveAlarms; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainCriticalAlarms = domain_info.CriticalAlarms; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainMajorAlarms = domain_info.MajorAlarms; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainMinorAlarms = domain_info.MinorAlarms; /** UNSIGNED32 = ASN_UNSIGNED */ domain_info_context->saHpiDomainAlarmUserLimit = domain_info.DatUserAlarmLimit; /** TruthValue = ASN_INTEGER */ domain_info_context->saHpiDomainAlarmOverflow = (domain_info.DatOverflow == SAHPI_TRUE) ? MIB_TRUE : MIB_FALSE; /** SaHpiGuid = ASN_OCTET_STR */ /* typedef SaHpiUint8T SaHpiGuidT[16]; */ memcpy(domain_info_context->saHpiDomainGuid, domain_info.Guid, 16); domain_info_context->saHpiDomainGuid_len = 16; if (new_row == MIB_TRUE) CONTAINER_INSERT (cb.container, domain_info_context); domain_info_entry_count = CONTAINER_SIZE (cb.container); return rv; }
int main(int argc, char **argv) { int c, month, day, year; char i_newdate[20]; char i_newtime[20]; int day_array[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; struct tm new_tm_time; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogEntryIdT entryid; SaHpiTimeT oldtime; SaHpiTimeT newtime; SaHpiTimeT readbacktime; SaHpiTextBufferT buffer; oh_prog_version(argv[0], OH_SVN_REV); while ( (c = getopt( argc, argv,"d:t:x")) != EOF ) { switch(c) { case 'd': findate = 1; strcpy(i_newdate, optarg); break; case 't': fintime = 1; strcpy(i_newtime, optarg); break; case 'x': fdebug = 1; break; default: usage(argv); exit(1); } } if ( !findate || !fintime) { usage(argv); exit(1); } if (findate) { if (fdebug) printf("New date to be set: %s\n",i_newdate); if (sscanf(i_newdate,"%2d/%2d/%4d", &month, &day, &year) < 8) { printf("%s: Invalid date\n", argv[0]); } /* check month, day and year for correctness */ if ((month < 1) || (month > 12)) { printf("%s: Month out of range: (%d)\n", argv[0], month); usage(argv); exit(1); }; if (year < 1900) { printf("%s: Year out of range: (%d)\n", argv[0], year); usage(argv); exit(1); }; month--; if (month == 1) { /* if the given year is a leap year */ if ((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0)) day_array[1] = 29; }; if ((day < 1) || (day > day_array[month])) { printf("%s: Day out of range: (%d)\n", argv[0], day); usage(argv); exit(1); }; new_tm_time.tm_mon = month; new_tm_time.tm_mday = day; new_tm_time.tm_year = year - 1900; } if (fintime) { if (fdebug) printf("New time to be set: %s\n",i_newtime); if (sscanf(i_newtime,"%2d:%2d:%2d", &new_tm_time.tm_hour, &new_tm_time.tm_min, &new_tm_time.tm_sec) < 6) { printf("%s: Invalid time\n", argv[0]); } /* check hours, minutes and seconds for correctness */ if ((new_tm_time.tm_hour < 0) || (new_tm_time.tm_hour > 24)) { printf("%s: Hours out of range: (%d)\n", argv[0], new_tm_time.tm_hour); usage(argv); exit(1); }; if ((new_tm_time.tm_min < 0) || (new_tm_time.tm_min > 60)) { printf("%s: Minutes out of range: (%d)\n", argv[0], new_tm_time.tm_min); usage(argv); exit(1); }; if ((new_tm_time.tm_sec < 0) || (new_tm_time.tm_sec > 60)) { printf("%s: Seconds out of range: (%d)\n", argv[0], new_tm_time.tm_sec); usage(argv); exit(1); } } if (fdebug) printf("Values passed to mktime():\n\tmon %d\n\tday %d\n\tyear %d\n\tHH %d\n\tMM %d\n\tSS %d\n", new_tm_time.tm_mon, new_tm_time.tm_mday, new_tm_time.tm_year, new_tm_time.tm_hour, new_tm_time.tm_min, new_tm_time.tm_sec); newtime = (SaHpiTimeT) mktime(&new_tm_time) * 1000000000; if (fdebug) printf("New date and time in SaHpiTimeT %lli\n", (long long int)newtime); 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("saHpiDiscover %s\n", oh_lookup_error(rv)); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv)); printf("DomainInfo: RptUpdateCount = %d, RptUpdateTimestamp = %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) && (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { resourceid = rptentry.ResourceId; if (fdebug) printf("RPT %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); rv = saHpiEventLogTimeGet(sessionid, resourceid, &oldtime); oh_decode_time(oldtime, &buffer); printf ("\nCurrent event log time on HPI target: %s\n", buffer.Data); printf ("Setting new event log time on HPI target ...\n"); rv = saHpiEventLogTimeSet(sessionid, resourceid, newtime); if (rv != SA_OK) { printf("saHpiEventLogTimeSet %s\n", oh_lookup_error(rv)); } rv = saHpiEventLogTimeGet(sessionid, resourceid, &readbacktime); oh_decode_time(readbacktime, &buffer); printf ("Read-Back-Check event log time: %s\n", buffer.Data); } entryid = SAHPI_OLDEST_ENTRY; rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); return(0); }
int main(int argc, char **argv) { int c, test_fail = 0, wait = 0; char *timeout_str= (char *)NULL; int do_discover_after_subscribe = 0; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiEventLogInfoT info; SaHpiRdrT rdr; SaHpiTimeoutT timeout; SaHpiEventT event; memset(&rptentry, 0, sizeof(rptentry)); printf("%s: version %s\n", argv[0], progver); while ( (c = getopt( argc, argv,"t:xd?")) != EOF ) { switch(c) { case 't': timeout_str = optarg; break; case 'd': do_discover_after_subscribe = 1; break; case 'x': fdebug = 1; break; default: Usage(argv); exit(1); } } if (timeout_str != (char *)NULL) { if ((strcmp(timeout_str, "SAHPI_TIMEOUT_BLOCK") == 0) || (strcmp(timeout_str, "BLOCK") == 0)) { timeout = SAHPI_TIMEOUT_BLOCK; } else { wait = atoi(timeout_str); timeout = (SaHpiTimeoutT)(wait * HPI_NSEC_PER_SEC); } } else timeout = (SaHpiTimeoutT) SAHPI_TIMEOUT_IMMEDIATE; printf("************** timeout:[%lld] ****************\n", timeout); 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); } if (fdebug) printf("saHpiDiscover\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover: %s\n", oh_lookup_error(rv)); exit(-1); } if (fdebug) printf( "Subscribe to events\n"); rv = saHpiSubscribe( sessionid ); if (rv != SA_OK) { printf("saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } if (do_discover_after_subscribe) { if (fdebug) printf("saHpiDiscover after saHpiSubscribe\n"); rv = saHpiDiscover(sessionid); if (rv != SA_OK) { printf("saHpiDiscover after saHpiSubscribe: %s\n", oh_lookup_error(rv)); exit(-1); } } 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)) { printf("**********************************************\n"); 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 %x capabilities = %x\n", resourceid, rptentry.ResourceCapabilities); if ( (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_EVENT_LOG)) { /* Using EventLogInfo to build up event queue - for now */ rv = saHpiEventLogInfoGet(sessionid, resourceid, &info); if (fdebug) printf("saHpiEventLogInfoGet %s\n", oh_lookup_error(rv)); if (rv == SA_OK) oh_print_eventloginfo(&info, 4); } else { if (fdebug) printf("RPT doesn't have SEL\n"); } rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] tag: %s\n", resourceid, rptentry.ResourceTag.Data); rptentryid = nextrptentryid; } printf("**********************************************\n"); } printf( "Go and get the event\n"); while (1) { rdr.RdrType = SAHPI_NO_RECORD; rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry, NULL); if (rv != SA_OK) { if (rv != SA_ERR_HPI_TIMEOUT) { printf("ERROR during EventGet : %s\n", oh_lookup_error(rv)); test_fail = 1; } else { if (timeout == SAHPI_TIMEOUT_BLOCK) { printf("ERROR: Timeout while infinite wait\n"); test_fail = 1; } else if (timeout != SAHPI_TIMEOUT_IMMEDIATE) { printf("ERROR: Time, %d seconds, expired waiting" " for event\n", wait); test_fail = 1; } } break; } else { oh_print_event(&event, 4); } } if (test_fail == 0) printf(" Test PASS.\n"); else printf(" Test FAILED.\n"); /* Unsubscribe to future events */ if (fdebug) printf( "Unsubscribe\n"); rv = saHpiUnsubscribe( sessionid ); rv = saHpiSessionClose(sessionid); return(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; }
int main(int argc, char **argv) { int c; SaErrorT rv,rv_rdr; SaHpiSessionIdT sessionid; SaHpiDomainInfoT rptinfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; SaHpiRdrT rdr; SaHpiIdrInfoT idrInfo; SaHpiIdrIdT idrid; int invfound = 0; int nloops = 0; oh_prog_version(argv[0], OH_SVN_REV); atag.tlen = 0; while ( (c = getopt( argc, argv,"a:vxz?")) != EOF ) switch(c) { case 'z': fzdebug = 1; /* fall thru to include next setting */ case 'x': fdebug = 1; break; case 'v': fverbose = 1; break; case 'a': fasset = 1; if (optarg) { atag.tag = (char *)strdup(optarg); atag.tlen = strlen(optarg); } break; default: printf("Usage: %s [-x] [-a asset_tag]\n", argv[0]); printf(" -a Sets the asset tag\n"); printf(" -x Display debug messages\n"); printf(" -z Display extra debug messages\n"); exit(1); } /* compile error */ // inv = (SaHpiIdrAreaHeaderT *)&inbuff[0]; inv = (SaHpiIdrAreaHeaderT *)(void *)&inbuff[0]; rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL); if (fdebug) printf("saHpiSessionOpen rv = %d sessionid = %x\n",rv,sessionid); if (rv != SA_OK) { printf("saHpiSessionOpen error %d\n",rv); exit(-1); } rv = saHpiDomainInfoGet(sessionid,&rptinfo); if (fdebug) printf("saHpiDomainInfoGet rv = %d\n",rv); // if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n", // rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp); while (!invfound && (nloops < 7)) { /* * The OpenHPI ipmi plugin has a bug whereby the FRU RDR is added * much later, and always requires a rediscovery. (bug #1095256) * This should not apply to other well-behaved plugins. */ nloops++; if (fdebug) printf("Starting Discovery, pass %d ...\n",nloops); rv = saHpiDiscover(sessionid); if (fdebug) printf("saHpiDiscover rv = %d\n",rv); if (rv != SA_OK) { printf("saHpiDiscover error %d\n",rv); break; } /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) printf("RptEntryGet: rid=%d rv = %d\n",rptentryid,rv); if (rv == SA_OK) { /* walk the RDR list for this RPT entry */ entryid = SAHPI_FIRST_ENTRY; /* OpenHPI plugin sometimes has bad RPT Tag DataLength here. */ // rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; resourceid = rptentry.ResourceId; if (fdebug) printf("rptentry[%d] resourceid=%d\n", rptentryid,resourceid); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_INVENTORY_DATA) { printf("Resource[%d] Tag: %s \thas inventory capability\n", rptentryid,rptentry.ResourceTag.Data); rv_rdr = SA_OK; while ((rv_rdr == SA_OK) && (entryid != SAHPI_LAST_ENTRY)) { rv_rdr = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr); if (fdebug) printf("saHpiRdrGet[%x] rv = %d\n",entryid,rv_rdr); if (rv_rdr == SA_OK) { if (fdebug) printf("Rdr[%x] type = %d tag = %s\n",entryid, rdr.RdrType,rdr.IdString.Data); if (rdr.RdrType == SAHPI_INVENTORY_RDR) { invfound = 1; /*type 3 includes inventory records*/ rdr.IdString.Data[rdr.IdString.DataLength] = 0; idrid = rdr.RdrTypeUnion.InventoryRec.IdrId; buffersize = sizeof(inbuff); if (fdebug) { printf("Rdr[%x] is inventory, IdrId=%x\n",rdr.RecordId,idrid); printf("Inv BufferSize=%d\n", buffersize); } if ( IsTagBmc((char *)rdr.IdString.Data, rdr.IdString.DataLength) ) { /* Get all of the inventory data areas and fields */ memset(inv,0,buffersize); rv_rdr = saHpiIdrInfoGet(sessionid, resourceid, idrid, &idrInfo); if (rv_rdr != SA_OK) { printf("IDR Info error: rv_rdr = %d\n",rv_rdr); } else { /* idrInfo is ok */ if (fdebug) printf("IDR Info: ok \n"); print_epath(&rptentry.ResourceEntity, 1); printf("RDR[%x]: Inventory, IdrId=%x %s\n",rdr.RecordId, idrid,rdr.IdString.Data); print_idrinfo(&idrInfo,4); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } if (!ent_writable(&rptentry.ResourceEntity,&idrInfo)) foundasset = 0; if ((fasset == 1) && (foundasset == 1)) { SaHpiIdrFieldT atagField; atagField.Type = SAHPI_IDR_FIELDTYPE_ASSET_TAG; atagField.ReadOnly = SAHPI_FALSE; atagField.AreaId = atag.areaid; atagField.FieldId = atag.fieldid; strptr=&(atagField.Field); strptr->DataType = SAHPI_TL_TYPE_TEXT; strptr->Language = SAHPI_LANG_ENGLISH; strptr->DataLength = (SaHpiUint8T)atag.tlen; strncpy((char *)strptr->Data, atag.tag, atag.tlen); strptr->Data[atag.tlen] = 0; printf( "Writing new asset tag: %s\n",strptr->Data); rv_rdr = saHpiIdrFieldSet(sessionid, resourceid, atag.idrid, &atagField); printf("Return Write Status = %d\n", rv_rdr); if (rv_rdr == SA_OK) { printf ("Good write - re-reading!\n"); rv_rdr = walkInventory(sessionid, resourceid, &idrInfo); if (fdebug) printf("walkInventory rv_rdr = %d\n",rv_rdr); } /* Good write - re-read */ } /*endif fasset*/ } /*endif RDR tag ok*/ } /* Inventory Data Records - Type 3 */ else if (fdebug) printf("rdr type = %d\n", rdr.RdrType); } /*endif RdrGet ok*/ entryid = nextentryid; } /*end while rdr*/ } /*endif rpt invent capab*/ else if (fdebug) printf("Resource[%d] Tag: %s\n", rptentryid, rptentry.ResourceTag.Data); } /*endif rpt ok*/ rptentryid = nextrptentryid; } /*end rpt loop */ if (fdebug) printf("loop %d inventory found = %d\n",nloops,invfound); } /*end while no inv */ rv = saHpiSessionClose(sessionid); exit(0); }
int main(int argc, char **argv) { int c; int is_state = 0; int is_power = 0; SaErrorT rv; SaHpiSessionIdT sessionid; SaHpiDomainInfoT domainInfo; SaHpiRptEntryT rptentry; SaHpiEntryIdT rptentryid; SaHpiEntryIdT nextrptentryid; SaHpiResourceIdT resourceid; SaHpiPowerStateT in_state = 0; SaHpiPowerStateT current_state; printf("%s ver %s\n", argv[0],progver); while ( (c = getopt( argc, argv,"udcx?")) != EOF ) switch(c) { case 'u': /* power up */ in_state = SAHPI_POWER_ON; is_state = 1; break; case 'd': /* power down */ in_state = SAHPI_POWER_OFF; is_state = 1; break; case 'c': /* power cycle */ in_state = SAHPI_POWER_CYCLE; is_state = 1; break; default: usage(argv[0]); exit(1); } if ( ! is_state) { usage(argv[0]); exit(1); }; 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 error %d\n",rv); exit(-1); } rv = saHpiDiscover(sessionid); if (rv != SA_OK) printf("saHpiDiscover rv = %d\n",rv); rv = saHpiDomainInfoGet(sessionid, &domainInfo); if (rv != SA_OK) printf("saHpiDomainInfoGet rv = %d\n",rv); /* walk the RPT list */ rptentryid = SAHPI_FIRST_ENTRY; while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY)) { SaErrorT rv1; rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry); if (rv != SA_OK) { printf("RptEntryGet: rv = %d\n",rv); break; }; /* walk the RDR list for this RPT entry */ resourceid = rptentry.ResourceId; rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; printf("rptentry[%d] resourceid=%d tag: %s\n", rptentryid,resourceid, (char *)rptentry.ResourceTag.Data); if (rptentry.ResourceCapabilities & SAHPI_CAPABILITY_POWER) { is_power = 1; /* read the current power state */ rv1 = saHpiResourcePowerStateGet(sessionid, resourceid, ¤t_state); if (rv1 != SA_OK) { printf("saHpiResourcePowerStateGet: error = %d\n", rv1); rptentryid = nextrptentryid; continue; } printf("Current power state:"); state2str(current_state); /* set new power state */ switch (in_state) { case SAHPI_POWER_OFF: case SAHPI_POWER_ON: printf("Setting power state to:"); state2str(in_state); rv1 = saHpiResourcePowerStateSet(sessionid, resourceid, in_state); if (rv1 != SA_OK) printf("PowerStateSet status = %d\n",rv1); sleep(2); break; case SAHPI_POWER_CYCLE: printf("Cycling system power\n"); rv1 = saHpiResourcePowerStateSet(sessionid, resourceid, in_state); if (rv1 != SA_OK) printf("PowerStateSet status = %d\n",rv1); printf("Cycling power, please wait a moment...\n"); sleep(8); break; } /* check new state again */ rv1 = saHpiResourcePowerStateGet(sessionid, resourceid, ¤t_state); if (rv1 != SA_OK) { printf("saHpiResourcePowerStateGet: error = %d\n", rv1); break; } else { printf("New power state:"); state2str(current_state); } } rptentryid = nextrptentryid; } rv = saHpiSessionClose(sessionid); if (is_power == 0) printf("No resources with Power capability found\n"); return(0); }
ret_code_t domain_proc(void) { SaHpiDomainInfoT info; SaHpiEntryIdT entryid, nextentryid; SaHpiDrtEntryT drtentry; SaErrorT rv; SaHpiDomainIdT id; SaHpiSessionIdT sessionId; int i, n, first; gpointer ptr; Domain_t *domain = (Domain_t *)NULL; Domain_t *new_domain; term_def_t *term; term = get_next_term(); if (term == NULL) { printf("Domain list:\n"); printf(" ID: %d SessionId: %d", Domain->domainId, Domain->sessionId); rv = saHpiDomainInfoGet(Domain->sessionId, &info); if (rv == SA_OK) { print_text_buffer_text(" Tag: ", &(info.DomainTag), NULL, ui_print); }; printf("\n"); entryid = SAHPI_FIRST_ENTRY; first = 1; while (entryid != SAHPI_LAST_ENTRY) { rv = saHpiDrtEntryGet(Domain->sessionId, entryid, &nextentryid, &drtentry); if (rv != SA_OK) break; if (first) { first = 0; printf(" Domain Reference Table:\n"); }; printf(" ID: %d", drtentry.DomainId); entryid = nextentryid; rv = saHpiSessionOpen(drtentry.DomainId, &sessionId, NULL); if (rv != SA_OK) { printf("\n"); continue; }; rv = saHpiDomainInfoGet(sessionId, &info); if (rv == SA_OK) { print_text_buffer_text(" Tag: ", &(info.DomainTag), NULL, ui_print); }; saHpiSessionClose(sessionId); printf("\n"); } return(HPI_SHELL_OK); }; if (isdigit(term->term[0])) id = (int)atoi(term->term); else return HPI_SHELL_PARM_ERROR; n = g_slist_length(domainlist); for (i = 0; i < n; i++) { ptr = g_slist_nth_data(domainlist, i); if (ptr == (gpointer)NULL) break; domain = (Domain_t *)ptr; if (domain->domainId == id) break; }; if (i >= n) { new_domain = (Domain_t *)malloc(sizeof(Domain_t)); memset(new_domain, 0, sizeof(Domain_t)); new_domain->domainId = id; if (add_domain(new_domain) < 0) { free(new_domain); printf("Can not open domain: %d\n", id); return HPI_SHELL_PARM_ERROR; }; domain = new_domain; }; Domain = domain; set_Subscribe(Domain, prt_flag); add_domain(Domain); return(HPI_SHELL_OK); }
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); }