Changeset 76aafc4 in nscp for modules


Ignore:
Timestamp:
10/26/06 07:03:39 (7 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
7aef770
Parents:
70f2d7b
Message:

* empty log message *

Location:
modules
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • modules/CheckSystem/CheckSystem.cpp

    rf42280d r76aafc4  
    117117            std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 
    118118            std::cout << "testing: " << counter << ": "; 
     119            std::list<std::string> errors; 
     120            std::list<std::string> status; 
    119121            std::string error; 
     122            bool bStatus = true; 
    120123            if (PDH::Enumerations::validate(counter, error)) { 
    121               std::cout << " found "; 
     124              status.push_back("open"); 
    122125            } else { 
    123               std::cout << " *NOT* found (" << error << ") " << std::endl; 
    124               break; 
     126              errors.push_back("NOT found: " + error); 
     127              bStatus = false; 
    125128            } 
    126             bool bOpend = false; 
    127             try { 
     129            if (bStatus) { 
     130              PDH::PDHCounter *pCounter = NULL; 
    128131              PDH::PDHQuery pdh; 
    129               PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
    130               pdh.addCounter(counter, &cDouble); 
    131               pdh.open(); 
    132               pdh.gatherData(); 
    133               pdh.close(); 
    134               bOpend = true; 
    135             } catch (const PDH::PDHException e) { 
    136               std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
    137               break; 
     132              try { 
     133                PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
     134                pCounter = pdh.addCounter(counter, &cDouble); 
     135                pdh.open(); 
     136 
     137                if (pCounter != NULL) { 
     138                  try { 
     139                    PDH::PDHCounterInfo info = pCounter->getCounterInfo(); 
     140                    errors.push_back("CounterName: " + info.szCounterName); 
     141                    errors.push_back("ExplainText: " + info.szExplainText); 
     142                    errors.push_back("FullPath: " + info.szFullPath); 
     143                    errors.push_back("InstanceName: " + info.szInstanceName); 
     144                    errors.push_back("MachineName: " + info.szMachineName); 
     145                    errors.push_back("ObjectName: " + info.szObjectName); 
     146                    errors.push_back("ParentInstance: " + info.szParentInstance); 
     147                    errors.push_back("Type: " + strEx::itos(info.dwType)); 
     148                    errors.push_back("Scale: " + strEx::itos(info.lScale)); 
     149                    errors.push_back("Default Scale: " + strEx::itos(info.lDefaultScale)); 
     150                    errors.push_back("Status: " + strEx::itos(info.CStatus)); 
     151                    status.push_back("described"); 
     152                  } catch (const PDH::PDHException e) { 
     153                    errors.push_back("Describe failed: " + e.getError()); 
     154                    bStatus = false; 
     155                  } 
     156                } 
     157 
     158                pdh.gatherData(); 
     159                pdh.close(); 
     160                status.push_back("queried"); 
     161              } catch (const PDH::PDHException e) { 
     162                errors.push_back("Query failed: " + e.getError()); 
     163                bStatus = false; 
     164                try { 
     165                  pdh.gatherData(); 
     166                  pdh.close(); 
     167                  bStatus = true; 
     168                } catch (const PDH::PDHException e) { 
     169                  errors.push_back("Query failed (again!): " + e.getError()); 
     170                } 
     171              } 
     172 
    138173            } 
    139             std::cout << " open "; 
    140             std::cout << std::endl; 
     174            if (!bStatus) { 
     175              std::list<std::string>::const_iterator cit = status.begin(); 
     176              for (;cit != status.end(); ++cit) { 
     177                std::cout << *cit << ", "; 
     178              } 
     179              std::cout << std::endl; 
     180              std::cout << "  | Log" << std::endl; 
     181              std::cout << "--+------  --    -" << std::endl; 
     182              cit = errors.begin(); 
     183              for (;cit != errors.end(); ++cit) { 
     184                std::cout << "  | " << *cit << std::endl; 
     185              } 
     186            } else { 
     187              std::list<std::string>::const_iterator cit = status.begin(); 
     188              for (;cit != status.end(); ++cit) { 
     189                std::cout << *cit << ", ";; 
     190              } 
     191              std::cout << std::endl; 
     192            } 
    141193          } 
    142194        } 
  • modules/CheckSystem/PDHCollector.cpp

    raabbd97 r76aafc4  
    120120 
    121121  DWORD waitStatus = 0; 
     122  bool first = true; 
    122123  do { 
    123124    MutexLock mutex(mutexHandler); 
     
    128129        pdh.gatherData(); 
    129130      } catch (const PDH::PDHException &e) { 
    130         NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     131        if (first) {  // If this is the first run an error will be thrown since the data is not yet avalible 
     132                // This is "ok" but perhaps another solution would be better, but this works :) 
     133          first = false; 
     134        } else { 
     135          NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     136        } 
    131137      } 
    132138    }  
  • modules/NRPEListener/NRPEListener.cpp

    rf42280d r76aafc4  
    2828  return ret; 
    2929} 
     30bool getCacheAllowedHosts() { 
     31  int val = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 
     32  if (val == -1) 
     33    val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 
     34  return val==1?true:false; 
     35} 
    3036 
    3137bool NRPEListener::loadModule() { 
     
    3339  timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,NRPE_SETTINGS_TIMEOUT_DEFAULT); 
    3440  std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); 
    35   std::list<std::string>::iterator it; 
    36   for (it = commands.begin(); it != commands.end(); it++) { 
    37     strEx::token t = strEx::getToken(*it, '='); 
    38     if (t.first.substr(0,7) == "command") { 
    39       strEx::token t2 = strEx::getToken(t.first, '['); 
    40       t2 = strEx::getToken(t2.second, ']'); 
    41       t.first = t2.first; 
    42     } 
    43     if (t.first.empty() || t.second.empty()) { 
     41  std::list<std::string>::const_iterator it; 
     42  for (it = commands.begin(); it != commands.end(); ++it) { 
     43    std::string command_name; 
     44    if (((*it).length() > 7)&&((*it).substr(0,7) == "command")) { 
     45      strEx::token t = strEx::getToken((*it), '['); 
     46      t = strEx::getToken(t.second, ']'); 
     47      command_name = t.first; 
     48    } else { 
     49      command_name = (*it); 
     50    } 
     51    std::string s = NSCModuleHelper::getSettingsString(NRPE_HANDLER_SECTION_TITLE, (*it), ""); 
     52    if (command_name.empty() || s.empty()) { 
    4453      NSC_LOG_ERROR_STD("Invalid command definition: " + (*it)); 
    4554    } else { 
    46       addCommand(t.first.c_str(), t.second); 
    47     } 
    48   } 
    49  
    50   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
     55      addCommand(command_name.c_str(), s); 
     56    } 
     57  } 
     58 
     59  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 
    5160  try { 
    5261    unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT); 
  • modules/NSClientListener/NSClientListener.cpp

    raabbd97 r76aafc4  
    3838  return ret; 
    3939} 
     40bool getCacheAllowedHosts() { 
     41  int val = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 
     42  if (val == -1) 
     43    val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 
     44  return val==1?true:false; 
     45} 
    4046 
    4147bool NSClientListener::loadModule() { 
    42   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
     48  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 
    4349  unsigned short port = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 
    4450  std::string host = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT); 
Note: See TracChangeset for help on using the changeset viewer.