Пример #1
0
/**
   Update the Linux instance.
*/
    void StaticDiskPartitionInstance::Update_Linux()
    {
        SCX_LOGTRACE(m_log, L"DiskPartition::Update_Linux():: Entering, DeviceID is:" + m_deviceID);
        
        bool opened = m_deps->open(StrToUTF8(m_deviceID).c_str(), O_RDONLY | O_NONBLOCK);
        if (!opened)
        {
            return; // Failure should already be logged by the open call
        }

        int ret;

        struct hd_geometry geo;
        memset(&geo,0,sizeof(geo));
        ret = m_deps->ioctl(HDIO_GETGEO, &geo);
        if (ret || errno)
        {
            SCX_LOGERROR(m_log, L"Could not read disk geometry : ret=" + StrFrom(ret) + L" errno=" + StrFrom(errno));
            return; //No use going on . . .
        }
        
        u_int64_t sectorSz=0;
        ret = m_deps->ioctl( BLKSSZGET, &sectorSz);
        if (ret || errno)
        {
            SCX_LOGERROR(m_log, L"ioctl BLKSSZGET failed : ret=" + StrFrom(ret) + L" errno=" + StrFrom(errno));
            return;
        }
        
        u_int64_t blockDevBsz=0;
        ret = m_deps->ioctl( BLKBSZGET, &blockDevBsz);
        if (ret || errno)
        {
            SCX_LOGERROR(m_log, L"ioctl BLKBSZGET failed : ret=" + StrFrom(ret) + L" errno=" + StrFrom(errno));
            return;
        }

        unsigned long partitionSize=0;
        ret = m_deps->ioctl( BLKGETSIZE, &partitionSize);
        if (ret || errno)
        {
            SCX_LOGERROR(m_log, L"ioctl BLKGETSIZE failed : ret=" + StrFrom(ret) + L" errno=" + StrFrom(errno));
            return;
        }
         
        // fill in the fields in the instance of PartitionInformation
        m_partitionSize = partitionSize * sectorSz;
        m_blockSize = blockDevBsz;
        m_startingOffset = geo.start;
        m_numberOfBlocks = RoundToUnsignedInt(
            static_cast<double>(m_partitionSize) / 
            static_cast<double>(m_blockSize));
    }
Пример #2
0
//! Number of days in month
//! \param[in]  year    Year of month
//! \param[in]  month   Month of interest
//! \returns    Number of days in month of year
//! \throws     SCXInvalidArgumentException     When month is ouside range
unsigned DaysInMonth(scxyear year, scxmonth month) {
    switch (month) {
    case 1:
        return 31;
    case 2:
        return IsLeapYear(year)? 29: 28;
    case 3:
        return 31;
    case 4:
        return 30;
    case 5:
        return 31;
    case 6:
        return 30;
    case 7:
        return 31;
    case 8:
        return 31;
    case 9:
        return 30;
    case 10:
        return 31;
    case 11:
        return 30;
    case 12:
        return 31;
    default:
        throw SCXInvalidArgumentException(L"month", StrFrom(month), SCXSRCLOCATION);
    }
}
Пример #3
0
/**
    Set user name
*/
    void SCXUser::SetName()
    {
        struct passwd pwd;
        struct passwd *ppwd = NULL;
        long bufSize = sysconf(_SC_GETPW_R_SIZE_MAX);

        // Sanity check - all platforms have this, but never hurts to be certain

        if (bufSize < 1024)
        {
            bufSize = 1024;
        }

        std::vector<char> buf(bufSize);

        // Use reentrant form of getpwuid (it's reentrant, and it pacifies purify)
#if !defined(sun)
        int rc = getpwuid_r(m_uid, &pwd, &buf[0], buf.size(), &ppwd);
        if (rc != 0)
        {
           ppwd = NULL;
        }
#else
        ppwd = getpwuid_r(m_uid, &pwd, &buf[0], buf.size());
#endif

        if (ppwd)
        {
            m_name = StrFromUTF8(ppwd->pw_name);
        }
        else
        {
            m_name = StrFrom(m_uid);
        }
    }
Пример #4
0
 /**
    Returns a formatted string with where an exception occured
 
 */
 wstring SCXCodeLocation::Where() const 
 {
     if (m_File.length())
     {
         // Compose e.g. [my_file.cpp:434]
         return L"[" + m_File + L":" + StrFrom(m_Line) + L"]"; 
     }
     else
     {
         return L"[unknown]";
     }
 }
        void WriteLogFileHeader( SCXHandle<std::wfstream> &stream, int logFileRunningNumber, SCXCalendarTime& procStartTimestamp )
        {
            std::wstringstream continuationLogMsg;
            if ( logFileRunningNumber > 1 )
            {
                continuationLogMsg << L"* Log file number: " << StrFrom(logFileRunningNumber) << std::endl;
            }

            (*stream) << L"*" << std::endl
                      << L"* Microsoft System Center Cross Platform Mongo Extensions" << std::endl
#if !defined(WIN32)
                      << L"* Build number: " << CIMPROV_BUILDVERSION_MAJOR << L"." << CIMPROV_BUILDVERSION_MINOR << L"."
                      << CIMPROV_BUILDVERSION_PATCH << L"-" << CIMPROV_BUILDVERSION_BUILDNR << L" "
                      << CIMPROV_BUILDVERSION_STATUS << std::endl
#endif
                      << L"* Process id: " << StrFrom(SCXProcess::GetCurrentProcessID()) << std::endl
                      << L"* Process started: " << procStartTimestamp.ToExtendedISO8601() << std::endl
                      << continuationLogMsg.str() 
                      << L"*" << std::endl
                      << L"* Log format: <date> <severity>     [<code module>:<line number>:<process id>:<thread id>] <message>" << std::endl
                      << L"*" << std::endl;
        }
    /**
       Write the given list of application server instances to disk.
       
       \param[in] instances - vector of Application Server Instances 
                              to write to disk
       
    */
    void PersistAppServerInstances::WriteToDisk(
            vector<SCXHandle<AppServerInstance> >& instances)
    {
        SCXHandle<SCXPersistDataWriter> pwriter= 
                m_pmedia->CreateWriter(APP_SERVER_PROVIDER);

        pwriter->WriteStartGroup(APP_SERVER_METADATA);
        pwriter->WriteValue(APP_SERVER_NUMBER, 
                StrFrom(instances.size()));
        pwriter->WriteEndGroup(); // Closing APP_METADATA

        int index = 0; 
        for(
                vector<SCXHandle<AppServerInstance> >::iterator instance = instances.begin();
                instance != instances.end();
                ++instance, ++index)
        {
            pwriter->WriteStartGroup(APP_SERVER_INSTANCE);

            pwriter->WriteValue(APP_SERVER_DISK_PATH, (*instance)->GetDiskPath());
            pwriter->WriteValue(APP_SERVER_ID, (*instance)->GetId());
            pwriter->WriteValue(APP_SERVER_HTTP_PORT, (*instance)->GetHttpPort());
            pwriter->WriteValue(APP_SERVER_HTTPS_PORT, (*instance)->GetHttpsPort());
            pwriter->WriteValue(APP_SERVER_PROTOCOL, (*instance)->GetProtocol());
            pwriter->WriteValue(APP_SERVER_IS_DEEP_MONITORED, 
                    StrFrom((*instance)->GetIsDeepMonitored()));
            pwriter->WriteValue(APP_SERVER_TYPE, (*instance)->GetType());
            pwriter->WriteValue(APP_SERVER_VERSION, (*instance)->GetVersion());
            pwriter->WriteValue(APP_SERVER_PROFILE, (*instance)->GetProfile());
            pwriter->WriteValue(APP_SERVER_CELL, (*instance)->GetCell());
            pwriter->WriteValue(APP_SERVER_NODE, (*instance)->GetNode());
            pwriter->WriteValue(APP_SERVER_SERVER, (*instance)->GetServer());

            pwriter->WriteEndGroup(); // Closing this instance
        }
        
        pwriter->DoneWriting();
    }
Пример #7
0
    /**
       Returns the line number where an exception occured, else returns "unknown"

    */
    wstring SCXCodeLocation::WhichLine() const
    {

        // Return line number if present
        if (m_File.length())
        {
            return StrFrom(m_Line);
        }
        else
        {
            return L"unknown";
        }
        
    }
    /**
     From the necessary file, read the domains and return a unique list
     of potential domains.
     
     */
    vector<SCXFilePath> WebLogicFileReader::GetDomains()
    {
        SCX_LOGTRACE(m_log, L"WebLogicFileReader::GetDomains");

        vector<SCXFilePath> domains;

        // Logic necessary for reading WebLogic 11g domains
        SCXFilePath domainRegistryXml;
        domainRegistryXml.SetDirectory(m_installationPath);
        domainRegistryXml.SetFilename(
                WEBLOGIC_DOMAIN_REGISTRY_XML_FILENAME);
        
        if (DoesDomainRegistryXmlExist(domainRegistryXml))
        {
            ReadDomainRegistryXml(domainRegistryXml, domains);
        }

        // Logic necessary for reading WebLogic 10g domains
        SCXFilePath nodemanagerDomains;
        nodemanagerDomains.SetDirectory(m_installationPath);
        nodemanagerDomains.AppendDirectory(WEBLOGIC_NODEMANAGER_DOMAINS_DIRECTORY);
        nodemanagerDomains.SetFilename(WEBLOGIC_NODEMANAGER_DOMAINS_FILENAME);

        if (DoesNodemanagerDomainsExist(nodemanagerDomains))
        {
            ReadNodemanagerDomains(nodemanagerDomains, domains);
        }
        
        // There may be duplicates in the list, it is necessary to
        // sort the list of domains and return only the unique instances.
        sort(domains.begin(), domains.end(), SortPath());
        vector<SCXFilePath>::iterator tmp = 
                unique(domains.begin(), domains.end());
        domains.resize(tmp-domains.begin());
                
        SCX_LOGTRACE(m_log, 
                wstring(L"WebLogicFileReader::GetDomains() - ").
                append(L"Found ").append(StrFrom(domains.size())).append(L" domain(s)"));

        return domains;
    }
Пример #9
0
    /**
        Constructor

        Parameters:  procNumber - Number of processor, used as base for instance name
                     isTotal - Whether the instance represents a Total value of a collection
    */
    CPUInstance::CPUInstance(unsigned int procNumber, size_t sampleSize, bool isTotal)
      : EntityInstance(isTotal),
        m_UserCPU_tics(sampleSize),
        m_NiceCPU_tics(sampleSize),
        m_SystemCPUTime_tics(sampleSize),
        m_IdleCPU_tics(sampleSize),
        m_IOWaitTime_tics(sampleSize),
        m_IRQTime_tics(sampleSize),
        m_SoftIRQTime_tics(sampleSize),
        m_Total_tics(sampleSize)
   {
        m_log = SCXLogHandleFactory::GetLogHandle(L"scx.core.common.pal.system.cpu.cpuinstance");

        if (isTotal)
        {
            m_procName = L"_Total";
        }
        else
        {
            // The name of an instance is the processor number
            m_procName = StrFrom(procNumber);
        }

        SCX_LOGTRACE(m_log, wstring(L"CPUInstance default constructor - ").append(m_procName));

        m_procNumber = procNumber;

        // Init data
        m_processorTime = 0;
        m_idleTime = 0;
        m_userTime = 0;
        m_niceTime = 0;
        m_privilegedTime = 0;
        m_iowaitTime = 0;
        m_interruptTime = 0;
        m_dpcTime = 0;
        m_queueLength = 0;
    }
Пример #10
0
    bool StaticDiskPartitionInstance::GetBootDrivePath(wstring& bootpathStr)
    {
        SCX_LOGTRACE(m_log, L"DiskPartition::GetBootDrivePath():: Entering . . .");

        bootpathStr.clear();

        // buffer to store lines read from process output
        wstring curLine;
        wstring bootInterfacePath;

        // Determine Solaris boot disk using 'prtconf' and 'ls /dev/dsk'
        // cmdString stores the current process we are running via SCXProcess::Run()
#if defined(sparc)
#if PF_MAJOR == 5 && (PF_MINOR  == 9 || PF_MINOR == 10)
        wstring cmdPrtString = L"/usr/sbin/prtconf -pv"; 
#elif PF_MAJOR == 5 && PF_MINOR  == 11
        wstring cmdPrtString = L"/sbin/prtconf -pv"; 
#else
#error "Platform not supported"
#endif
#else// sparc
        wstring cmdPrtString = L"/usr/bin/grep bootpath /boot/solaris/bootenv.rc"; 
#endif

        std::string prtconfResult;
        std::string finalResult;
        std::istringstream processInputPrt;
        std::ostringstream processOutputPrt;
        std::ostringstream processErrPrt;

        try 
        {
            int retCode = m_deps->Run(cmdPrtString, processInputPrt, processOutputPrt, processErrPrt, 15000);
            if (retCode)
            {
                SCX_LOGERROR(m_log, L"Error returned from prtconf, unable to determine boot partition. Error code=" + StrFrom(retCode));
                return false;
            }
            prtconfResult = processOutputPrt.str();
            SCX_LOGTRACE(m_log, L"  Got this output from " + cmdPrtString + L" : " + StrFromUTF8(prtconfResult) );
            size_t lengthCaptured = prtconfResult.length();

            // Truncate trailing newline if there in captured output                  
            if (lengthCaptured > 0)
            {
                if (prtconfResult[lengthCaptured - 1] == '\n')
                {
                    prtconfResult[lengthCaptured - 1] = '\0';
                }
            }

        }
        catch(SCXCoreLib::SCXException &e)
        {
            SCX_LOGERROR(m_log, L"Unable to determine boot partition using prtconf ..." + e.What());
            return false;
        }

        SCXRegexPtr solPrtconfPatternPtr(NULL);

        std::vector<wstring> matchingVector;

        // Let's build our RegEx:
        try
        {
            SCX_LOGTRACE(m_log, L"  Using this regex on PrtConf output: " + c_SolPrtconfPattern );
            solPrtconfPatternPtr = new SCXCoreLib::SCXRegex(c_SolPrtconfPattern);
        }
        catch(SCXCoreLib::SCXInvalidRegexException &e)
        {
            SCX_LOGERROR(m_log, L"Exception caught in compiling regex: " + e.What());
            return false;
        }

        std::istringstream stringStrmPrtconf(prtconfResult);
        vector<wstring>  allLines;                       // all lines read from prtconf output
        allLines.clear();
        SCXStream::NLFs nlfs;
        SCXCoreLib::SCXStream::ReadAllLinesAsUTF8(stringStrmPrtconf, allLines, nlfs);

        for(vector<wstring>::iterator it = allLines.begin(); it != allLines.end(); it++)
        {
            curLine.assign(*it);
            matchingVector.clear();

            // Let's get the Boot partition interface and drive letter from prtconf
            if (solPrtconfPatternPtr->ReturnMatch(curLine, matchingVector, 0))
            {
                bootInterfacePath = matchingVector[1];
                SCX_LOGTRACE(m_log, L"Found match of PrtConfPattern : " + bootInterfacePath);
                break;
            }
        }

        if (bootInterfacePath.size() == 0)
        {
            std::wstringstream warningMsg;
            if (matchingVector.size() > 0)
            {
                warningMsg << L"Couldn't find Boot Partition, regular expression error message was: " << matchingVector[0];
            }
            else 
            {
                warningMsg << L"Couldn't find Boot Partition.";
            }
            SCX_LOG(m_log, suppressor.GetSeverity(warningMsg.str()), warningMsg.str());
            return false;
        }

        // Replace "disk" by "disk" or "sd" to normalize the boot interface path
        wstring from(L"disk");
        size_t start_pos = bootInterfacePath.find(from);
        if(start_pos != std::string::npos)
        {
            bootInterfacePath.replace(start_pos, from.length(), L"(disk|sd)");
        }

        wstring solLsPattern(c_SolLsPatternBeg);
        solLsPattern += bootInterfacePath;

        // Now we need to build up our pattern to find the bootdisk, using our results from above:
        SCXRegexPtr solLsPatternPtr(NULL);

        //Let's build our RegEx:
        try
        {
            SCX_LOGTRACE(m_log, L"  Using this regex on ls -l /dev/dsk output: " + solLsPattern );
            solLsPatternPtr = new SCXCoreLib::SCXRegex(solLsPattern);
        }
        catch(SCXCoreLib::SCXInvalidRegexException &e)
        {
            SCX_LOGERROR(m_log, L"Exception caught in compiling LS Pattern regex: " + e.What());
            return false;
        }

        // Retrieve the bootdrive using the bootInterface and driveLetter
        wstring cmdStringLs = L"/usr/bin/ls -l /dev/dsk";
        std::string devDskResult;

        std::istringstream processInputLs;
        std::ostringstream processOutputLs;
        std::ostringstream processErrLs;
        curLine.clear();

        try 
        {
            SCXCoreLib::SCXProcess::Run(cmdStringLs, processInputLs, processOutputLs, processErrLs, 15000);
            devDskResult = processOutputLs.str();
            SCX_LOGTRACE(m_log, L"  Got this output from " + cmdStringLs + L" : " + StrFromUTF8(devDskResult) );

            size_t lengthCaptured = devDskResult.length();

            // Truncate trailing newline if there in captured output
            if (lengthCaptured > 0)
            {
                if (devDskResult[lengthCaptured - 1] == '\n')
                {
                    devDskResult[lengthCaptured - 1] = '\0';
                }
            }

        }
        catch(SCXCoreLib::SCXException &e)
        {
            SCX_LOGERROR(m_log, L"Unable to determine boot partition..." + e.What());
            return false;
        }

        std::istringstream stringStrmDevDsk(devDskResult);
        allLines.clear();
        SCXCoreLib::SCXStream::ReadAllLinesAsUTF8(stringStrmDevDsk, allLines, nlfs);

        wstring bootDisk(L"");
        for(vector<wstring>::iterator it = allLines.begin(); it != allLines.end(); it++)
        {
            curLine.assign(*it);
            curLine.push_back('\n');
            matchingVector.clear();

            // Let's get the boot drive
            if (solLsPatternPtr->ReturnMatch(curLine, matchingVector, 0))
            {
                bootDisk = matchingVector[1];  //e.g. "c1t0d0s0"
                break;
            }
        }

        //Check the results
        if (bootDisk.size() == 0)
        {
            std::wstringstream warningMsg;
            if (matchingVector.size() > 0)
            {
                warningMsg << L"Couldn't find Boot Drive, regular expression error message was: " << matchingVector[0];
            }
            else
            {
                warningMsg << L"Couldn't find Boot Drive.";
            }
            SCX_LOG(m_log, suppressor.GetSeverity(warningMsg.str()), warningMsg.str());
            return false;
        }     

        bootpathStr = L"/dev/dsk/" + bootDisk; //e.g. "/dev/dsk/c1t0d0s0"

        return true;
    }