Changeset 7443b58 in nscp
- Timestamp:
- 03/24/11 21:38:31 (2 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2
- Children:
- 2d69ab6
- Parents:
- 569a179
- Files:
-
- 2 added
- 1 deleted
- 35 edited
-
helpers/installers/installer/CMakeLists.txt (modified) (1 diff)
-
include/checkHelpers.hpp (modified) (17 diffs)
-
include/nscapi/macros.hpp (modified) (2 diffs)
-
include/nscapi/nscapi_core_wrapper.cpp (modified) (2 diffs)
-
include/nscapi/nscapi_core_wrapper.hpp (modified) (1 diff)
-
include/nscapi/nscapi_plugin_wrapper.hpp (modified) (2 diffs)
-
include/settings/settings_old.hpp (modified) (10 diffs)
-
include/utils.h (modified) (2 diffs)
-
modules/CheckDisk/CheckDisk.cpp (modified) (14 diffs)
-
modules/CheckDisk/CheckDisk.h (modified) (2 diffs)
-
modules/CheckEventLog/CheckEventLog.cpp (modified) (1 diff)
-
modules/CheckEventLog/CheckEventLog.h (modified) (1 diff)
-
modules/CheckExternalScripts/CheckExternalScripts.cpp (modified) (3 diffs)
-
modules/CheckExternalScripts/CheckExternalScripts.h (modified) (2 diffs)
-
modules/CheckHelpers/CheckHelpers.cpp (modified) (1 diff)
-
modules/CheckHelpers/CheckHelpers.h (modified) (1 diff)
-
modules/CheckNSCP/CheckNSCP.cpp (modified) (1 diff)
-
modules/CheckNSCP/CheckNSCP.h (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (10 diffs)
-
modules/CheckSystem/CheckSystem.cpp.bak (deleted)
-
modules/CheckSystem/CheckSystem.h (modified) (1 diff)
-
modules/CheckSystem/PDHCollector.cpp (modified) (11 diffs)
-
modules/CheckSystem/PDHCollector.h (modified) (5 diffs)
-
modules/CheckTaskSched/CheckTaskSched.cpp (modified) (1 diff)
-
modules/CheckTaskSched/CheckTaskSched.h (modified) (1 diff)
-
modules/CheckTaskSched2/CheckTaskSched2.cpp (modified) (1 diff)
-
modules/CheckTaskSched2/CheckTaskSched2.h (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.cpp (modified) (1 diff)
-
modules/CheckWMI/CheckWMI.h (modified) (1 diff)
-
modules/LUAScript/LUAScript.cpp (modified) (2 diffs)
-
modules/LUAScript/LUAScript.h (modified) (2 diffs)
-
modules/NRPEClient/NRPEClient.cpp (modified) (1 diff)
-
modules/NRPEClient/NRPEClient.h (modified) (1 diff)
-
modules/NRPEServer/handler_impl.cpp (modified) (3 diffs)
-
scripts/check_files.vbs (added)
-
scripts/check_updates.vbs (added)
-
scripts/lib/NagiosPlugins.vbs (modified) (7 diffs)
-
service/CMakeLists.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
helpers/installers/installer/CMakeLists.txt
r197b263 r7443b58 41 41 42 42 ADD_DEPENDENCIES(${TARGET} ${MAIN_NSCP_TARGET} ${ALL_MODULE_NAMES} ${ALL_TOOL_NAMES} ${ALL_INSTALLERS_DLLS_NAMES}) 43 44 SET_TARGET_PROPERTIES(${TARGET} PROPERTIES FOLDER "installers") -
include/checkHelpers.hpp
r1ecd26f r7443b58 23 23 #include <string> 24 24 #include <strEx.h> 25 #include <math.h> 25 26 26 27 #define MAKE_PERFDATA_SIMPLE(alias, value, unit) _T("'") + alias + _T("'=") + value + unit 27 #define MAKE_PERFDATA(alias, value, unit, warn, crit) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit + _T("; ")28 #define MAKE_PERFDATA_EX(alias, value, unit, warn, crit, xmin, xmax) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit + _T(";") + xmin + _T(";") + xmax + _T("; ")28 #define MAKE_PERFDATA(alias, value, unit, warn, crit) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit 29 #define MAKE_PERFDATA_EX(alias, value, unit, warn, crit, xmin, xmax) _T("'") + alias + _T("'=") + value + unit + _T(";") + warn + _T(";") + crit + _T(";") + xmin + _T(";") + xmax 29 30 30 31 namespace checkHolders { … … 109 110 {} 110 111 CheckContainer(std::wstring data_, TContents warn_, TContents crit_) 111 : data(data_), warn(warn_), crit(crit_), show(showUnknown) 112 : data(data_), warn(warn_), crit(crit_), show(showUnknown), perfData(true) 112 113 {} 113 CheckContainer(std::wstring name_, std::wstring alias_, TContents warn_, TContents crit_)114 : data(data_), alias(alias_), warn(warn_), crit(crit_), show(showUnknown) 114 CheckContainer(std::wstring data_, std::wstring alias_, TContents warn_, TContents crit_) 115 : data(data_), alias(alias_), warn(warn_), crit(crit_), show(showUnknown), perfData(true) 115 116 {} 116 117 CheckContainer(const TThisType &other) 117 : data(other.data), alias(other.alias), warn(other.warn), crit(other.crit), show(other.show) 118 : data(other.data), alias(other.alias), warn(other.warn), crit(other.crit), show(other.show), perfData(other.perfData) 119 118 120 {} 121 CheckContainer<TContents>& operator =(const CheckContainer<TContents> &other) { 122 warn = other.warn; 123 crit = other.crit; 124 data = other.data; 125 alias = other.alias; 126 show = other.show; 127 perfData = other.perfData; 128 return *this; 129 } 119 130 std::wstring getAlias() { 120 131 if (alias.empty()) … … 174 185 }; 175 186 187 template <class TContents> 188 struct MagicCheckContainer : public CheckContainer<TContents> { 189 typedef CheckContainer<TContents> tParent; 190 191 MagicCheckContainer() : tParent() {} 192 MagicCheckContainer(std::wstring data_, TContents warn_, TContents crit_) : tParent(data_, warn_, crit_) {} 193 MagicCheckContainer(std::wstring data_, std::wstring alias_, TContents warn_, TContents crit_) : tParent(data_, alias_, warn_, crit_) {} 194 MagicCheckContainer(const TThisType &other) : tParent(other) {} 195 196 MagicCheckContainer<TContents>& operator =(const MagicCheckContainer<TContents> &other) { 197 tParent::operator =(other); 198 return *this; 199 } 200 201 202 void set_magic(double magic) { 203 warn.max_.set_magic(magic); 204 warn.min_.set_magic(magic); 205 crit.max_.set_magic(magic); 206 crit.min_.set_magic(magic); 207 } 208 209 }; 176 210 177 211 template <class value_type> … … 625 659 return (value*100)/total; 626 660 } 661 662 TTypeValue adjust_upper_magic(TTypeValue percentage, double normal, double magic) { 663 if (magic == 0) 664 return percentage; 665 return 100 - ( (100 - percentage) * pow(total / normal, magic) / (value / normal) ); 666 } 667 TTypeValue adjust_lower_magic(TTypeValue percentage, double normal, double magic) { 668 if (magic == 0) 669 return percentage; 670 return ( (percentage) * pow(total / normal, magic) / (value / normal) ); 671 } 672 673 627 674 }; 628 675 … … 651 698 if (p != std::wstring::npos) { 652 699 if (isUpper_) 653 pParent_->setPercentageUpper(value );700 pParent_->setPercentageUpper(value.substr(0, p)); 654 701 else 655 pParent_->setPercentageLower(value );702 pParent_->setPercentageLower(value.substr(0, p)); 656 703 } else { 657 704 if (isUpper_) … … 672 719 InternalValue upper; 673 720 InternalValue lower; 674 675 NumericPercentageBounds() : type_(none), upper(true), lower(false) { 721 double normal_size; 722 double magic; 723 724 NumericPercentageBounds() : type_(none), upper(true), lower(false), magic(0), normal_size(20*1024*1024) { 676 725 upper.setParent(this); 677 726 lower.setParent(this); 678 727 } 679 728 680 NumericPercentageBounds(const NumericPercentageBounds &other) { 729 NumericPercentageBounds(const NumericPercentageBounds &other) 730 : type_(other.type_) 731 , value_(other.value_) 732 , magic(other.magic) 733 , normal_size(other.normal_size) 734 , upper(other.upper) 735 , lower(other.lower) 736 { 737 upper.setParent(this); 738 lower.setParent(this); 739 740 } 741 742 NumericPercentageBounds& operator =(const NumericPercentageBounds &other) { 681 743 type_ = other.type_; 682 744 value_ = other.value_; 745 magic = other.magic; 746 normal_size = other.normal_size; 747 upper = other.upper; 748 lower = other.lower; 749 upper.setParent(this); 750 lower.setParent(this); 751 return *this; 683 752 } 684 753 checkResultType check(TType value) const { 685 754 if (type_ == percentage_lower) { 686 if (value.getLowerPercentage() == value _)755 if (value.getLowerPercentage() == value.adjust_lower_magic(value_, normal_size, magic)) 687 756 return same; 688 else if (value.getLowerPercentage() > value _)757 else if (value.getLowerPercentage() > value.adjust_lower_magic(value_, normal_size, magic)) 689 758 return above; 690 759 } else if (type_ == percentage_upper) { 691 if (value.getUpperPercentage() == value _)760 if (value.getUpperPercentage() == value.adjust_upper_magic(value_, normal_size, magic)) 692 761 return same; 693 else if (value.getUpperPercentage() > value _)762 else if (value.getUpperPercentage() > value.adjust_upper_magic(value_, normal_size, magic)) 694 763 return above; 695 764 } else if (type_ == value_lower) { … … 727 796 return value_; 728 797 } 798 void set_magic(double magic_) { 799 magic = magic_; 800 } 801 729 802 std::wstring gatherPerfData(std::wstring alias, TType &value, typename TType::TValueType warn, typename TType::TValueType crit) { 730 803 unsigned int value_p, warn_p, crit_p; 731 TType::TValueType value_v,warn_v, crit_v;804 TType::TValueType warn_v, crit_v; 732 805 if (type_ == percentage_upper) { 733 value_p = value.getUpperPercentage();734 warn_p = warn;735 crit_p = crit;736 warn_v = static_cast< double>(value.total)*static_cast<double>(warn)/100.0;737 crit_v = value.total*(double(crit)/100);;806 value_p = static_cast<unsigned int>(value.getUpperPercentage()); 807 warn_p = static_cast<unsigned int>(warn); 808 crit_p = static_cast<unsigned int>(crit); 809 warn_v = static_cast<unsigned int>(static_cast<double>(value.total)*static_cast<double>(warn)/100.0); 810 crit_v = static_cast<unsigned int>(value.total*(double(crit)/100)); 738 811 } else if (type_ == percentage_lower) { 739 value_p = value.getLowerPercentage();740 warn_p = warn;741 crit_p = crit;742 warn_v = static_cast< double>(value.total)*static_cast<double>(warn)/100.0;743 crit_v = value.total*(double(crit)/100);812 value_p = static_cast<unsigned int>(value.getLowerPercentage()); 813 warn_p = static_cast<unsigned int>(warn); 814 crit_p = static_cast<unsigned int>(crit); 815 warn_v = static_cast<unsigned int>(static_cast<double>(value.total)*static_cast<double>(warn)/100.0); 816 crit_v = static_cast<unsigned int>(value.total*(double(crit)/100)); 744 817 } else if (type_ == value_upper) { 745 value_p = value.getUpperPercentage();746 warn_p = 100-(warn*100/value.total);747 crit_p = 100-(crit*100/value.total);748 warn_v = warn;749 crit_v = crit;818 value_p = static_cast<unsigned int>(value.getUpperPercentage()); 819 warn_p = static_cast<unsigned int>(100-(warn*100/value.total)); 820 crit_p = static_cast<unsigned int>(100-(crit*100/value.total)); 821 warn_v = static_cast<unsigned int>(warn); 822 crit_v = static_cast<unsigned int>(crit); 750 823 } else { 751 value_p = value.getLowerPercentage();752 warn_p = 100-(warn*100/value.total);753 crit_p = 100-(crit*100/value.total);754 warn_v = warn;755 crit_v = crit;824 value_p = static_cast<unsigned int>(value.getLowerPercentage()); 825 warn_p = static_cast<unsigned int>(100-(warn*100/value.total)); 826 crit_p = static_cast<unsigned int>(100-(crit*100/value.total)); 827 warn_v = static_cast<unsigned int>(warn); 828 crit_v = static_cast<unsigned int>(crit); 756 829 } 757 830 std::wstring unit = THandler::get_perf_unit(min(warn_v, min(crit_v, value.value))); … … 765 838 std::wstring gatherPerfData(std::wstring alias, TType &value) { 766 839 unsigned int value_p; 767 TType::TValueType value_v;768 840 if (type_ == percentage_upper) { 769 value_p = value.getUpperPercentage();841 value_p = static_cast<unsigned int>(value.getUpperPercentage()); 770 842 } else if (type_ == percentage_lower) { 771 value_p = value.getLowerPercentage();843 value_p = static_cast<unsigned int>(value.getLowerPercentage()); 772 844 } else if (type_ == value_upper) { 773 value_p = value.getUpperPercentage();845 value_p = static_cast<unsigned int>(value.getUpperPercentage()); 774 846 } else { 775 value_p = value.getLowerPercentage();847 value_p = static_cast<unsigned int>(value.getLowerPercentage()); 776 848 } 777 849 std::wstring unit = THandler::get_perf_unit(value.value); … … 853 925 class MaxMinStateBounds { 854 926 public: 855 TNumericHolder max ;856 TNumericHolder min ;927 TNumericHolder max_; 928 TNumericHolder min_; 857 929 TStateHolder state; 858 930 typedef MaxMinStateBounds<TValueType, TNumericHolder, TStateHolder > TMyType; … … 861 933 862 934 MaxMinStateBounds() {} 863 MaxMinStateBounds(const MaxMinStateBounds &other) { 935 MaxMinStateBounds(const MaxMinStateBounds &other) : state(other.state), max_(other.max_), min_(other.min_) {} 936 MaxMinStateBounds & operator =(const MaxMinStateBounds &other) { 864 937 state = other.state; 865 max = other.max; 866 min = other.min; 938 max_ = other.max_; 939 min_ = other.min_; 940 return *this; 867 941 } 868 942 bool hasBounds() { 869 return state.hasBounds() || max .hasBounds() || min.hasBounds();943 return state.hasBounds() || max_.hasBounds() || min_.hasBounds(); 870 944 } 871 945 … … 889 963 if (state.hasBounds()) { 890 964 // @todo 891 } else if (max .hasBounds()) {892 return max .gatherPerfData(alias, value.count, warn.max.getPerfBound(value.count), crit.max.getPerfBound(value.count));893 } else if (min .hasBounds()) {894 return min .gatherPerfData(alias, value.count, warn.min.getPerfBound(value.count), crit.min.getPerfBound(value.count));965 } else if (max_.hasBounds()) { 966 return max_.gatherPerfData(alias, value.count, warn.max_.getPerfBound(value.count), crit.max_.getPerfBound(value.count)); 967 } else if (min_.hasBounds()) { 968 return min_.gatherPerfData(alias, value.count, warn.min_.getPerfBound(value.count), crit.min_.getPerfBound(value.count)); 895 969 } 896 970 return _T(""); … … 903 977 message = lable + _T(": ") + formatState(TStateHolder::toStringShort(value.state), type); 904 978 return true; 905 } else if ((max .hasBounds())&&(max.check(value.count) != below)) {979 } else if ((max_.hasBounds())&&(max_.check(value.count) != below)) { 906 980 message = lable + _T(": ") + formatAbove(TNumericHolder::toStringShort(value.count), type); 907 981 return true; 908 } else if ((min .hasBounds())&&(min.check(value.count) != above)) {982 } else if ((min_.hasBounds())&&(min_.check(value.count) != above)) { 909 983 message = lable + _T(": ") + formatBelow(TNumericHolder::toStringShort(value.count), type); 910 984 return true; 911 985 } else { 912 NSC_ DEBUG_MSG_STD(_T("Missing bounds for check: ") + lable);986 NSC_LOG_MESSAGE_STD(_T("Missing bounds for check: ") + lable); 913 987 //std::cout << "No bounds specified..." << std::endl; 914 988 } … … 1012 1086 class MaxMinBounds { 1013 1087 public: 1014 THolder max ;1015 THolder min ;1088 THolder max_; 1089 THolder min_; 1016 1090 typedef MaxMinBounds<THolder > TMyType; 1017 1091 … … 1020 1094 1021 1095 MaxMinBounds() {} 1022 MaxMinBounds(const MaxMinBounds &other) { 1023 max = other.max; 1024 min = other.min; 1096 MaxMinBounds(const MaxMinBounds &other) : max_(other.max_), min_(other.min_) {} 1097 MaxMinBounds& operator=(const MaxMinBounds &other) { 1098 max_ = other.max_; 1099 min_ = other.min_; 1100 return *this; 1025 1101 } 1026 1102 bool hasBounds() { 1027 return max .hasBounds() || min.hasBounds();1103 return max_.hasBounds() || min_.hasBounds(); 1028 1104 } 1029 1105 static std::wstring toStringLong(typename THolder::TValueType &value) { … … 1034 1110 } 1035 1111 std::wstring gatherPerfData(std::wstring alias, typename THolder::TValueType &value, TMyType &warn, TMyType &crit) { 1036 if (max .hasBounds()) {1037 return max .gatherPerfData(alias, value, warn.max.getPerfBound(value), crit.max.getPerfBound(value));1038 } else if (min .hasBounds()) {1039 return min .gatherPerfData(alias, value, warn.min.getPerfBound(value), crit.min.getPerfBound(value));1112 if (max_.hasBounds()) { 1113 return max_.gatherPerfData(alias, value, warn.max_.getPerfBound(value), crit.max_.getPerfBound(value)); 1114 } else if (min_.hasBounds()) { 1115 return min_.gatherPerfData(alias, value, warn.min_.getPerfBound(value), crit.min_.getPerfBound(value)); 1040 1116 } else { 1041 1117 NSC_LOG_MESSAGE_STD(_T("Missing bounds for maxmin-bounds check: ") + alias); 1042 return min .gatherPerfData(alias, value, 0, 0);1118 return min_.gatherPerfData(alias, value, 0, 0); 1043 1119 } 1044 1120 return _T(""); … … 1049 1125 } 1050 1126 bool check(typename THolder::TValueType &value, std::wstring lable, std::wstring &message, ResultType type) { 1051 if ((max .hasBounds())&&(max.check(value) != below)) {1127 if ((max_.hasBounds())&&(max_.check(value) != below)) { 1052 1128 message = lable + _T(": ") + formatAbove(THolder::toStringLong(value), type); 1053 1129 return true; 1054 } else if ((min .hasBounds())&&(min.check(value) != above)) {1130 } else if ((min_.hasBounds())&&(min_.check(value) != above)) { 1055 1131 message = lable + _T(": ") + formatBelow(THolder::toStringLong(value), type); 1056 1132 return true; … … 1141 1217 return eq.gatherPerfData(alias, value, warn.eq.getPerfBound(value), crit.eq.getPerfBound(value)); 1142 1218 } else { 1143 NSC_ DEBUG_MSG_STD(_T("Missing bounds for: ") + alias);1219 NSC_LOG_MESSAGE_STD(_T("Missing bounds for: ") + alias); 1144 1220 return _T(""); 1145 1221 } -
include/nscapi/macros.hpp
r1ecd26f r7443b58 28 28 ////////////////////////////////////////////////////////////////////////// 29 29 // Logging calls for the core wrapper 30 30 /* 31 31 #define NSC_LOG_ERROR_STD(msg) NSC_LOG_ERROR(((std::wstring)msg).c_str()) 32 32 #define NSC_LOG_ERROR(msg) NSC_ANY_MSG(msg,NSCAPI::error) … … 42 42 43 43 #define NSC_ANY_MSG(msg, type) GET_CORE()->Message(type, __FILE__, __LINE__, msg) 44 */ 45 #define NSC_LOG_ERROR_STD(msg) 46 #define NSC_LOG_ERROR(msg) 47 48 #define NSC_LOG_CRITICAL_STD(msg) 49 #define NSC_LOG_CRITICAL(msg) 50 51 #define NSC_LOG_MESSAGE_STD(msg) 52 #define NSC_LOG_MESSAGE(msg) 53 54 #define NSC_DEBUG_MSG_STD(msg) 55 #define NSC_DEBUG_MSG(msg) 56 57 #define NSC_ANY_MSG(msg, type) 58 44 59 45 60 ////////////////////////////////////////////////////////////////////////// -
include/nscapi/nscapi_core_wrapper.cpp
r1ecd26f r7443b58 246 246 if (!fNSAPIInject) 247 247 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 248 boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tok(buffer, boost::escaped_list_separator<wchar_t>(L'\\', spliwchar_t, L'\"')); 248 std::list<std::wstring> arglist; 249 if (escape) { 250 boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tok(buffer, boost::escaped_list_separator<wchar_t>(L'\\', spliwchar_t, L'\"')); 251 BOOST_FOREACH(std::wstring s, tok) 252 arglist.push_back(s); 253 } else { 254 std::wstring split; 255 split.push_back(spliwchar_t); 256 boost::tokenizer<boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tok(buffer, boost::escaped_list_separator<wchar_t>(_T(""), split, _T("\""))); 257 BOOST_FOREACH(std::wstring s, tok) 258 arglist.push_back(s); 259 } 260 return InjectSimpleCommand(command.c_str(), arglist, message, perf); 261 } 262 263 NSCAPI::nagiosReturn nscapi::core_wrapper::InjectNRPECommand(const std::wstring command, const std::wstring buffer, std::wstring & message, std::wstring & perf) { 264 if (!fNSAPIInject) 265 throw nscapi::nscapi_exception(_T("NSCore has not been initiated...")); 266 boost::tokenizer<boost::char_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tok(buffer, boost::char_separator<wchar_t>(_T("!"))); 249 267 std::list<std::wstring> arglist; 250 268 BOOST_FOREACH(std::wstring s, tok) … … 252 270 return InjectSimpleCommand(command.c_str(), arglist, message, perf); 253 271 } 272 273 254 274 /** 255 275 * Ask the core to shutdown (only works when run as a service, o/w does nothing ? -
include/nscapi/nscapi_core_wrapper.hpp
r1ecd26f r7443b58 139 139 NSCAPI::nagiosReturn InjectSplitAndCommand(const wchar_t* command, wchar_t* buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf); 140 140 NSCAPI::nagiosReturn InjectSplitAndCommand(const std::wstring command, const std::wstring buffer, wchar_t splitChar, std::wstring & message, std::wstring & perf, bool escape = false); 141 NSCAPI::nagiosReturn InjectNRPECommand(const std::wstring command, const std::wstring buffer, std::wstring & message, std::wstring & perf); 141 142 void StopService(void); 142 143 void Exit(void); -
include/nscapi/nscapi_plugin_wrapper.hpp
rc760fc9 r7443b58 232 232 } 233 233 std::wstring msg, perf; 234 NSCAPI::nagiosReturn ret = handleCommand(command .c_str(), args, msg, perf);234 NSCAPI::nagiosReturn ret = handleCommand(command, args, msg, perf); 235 235 236 236 PluginCommand::ResponseMessage response_message; … … 251 251 } 252 252 253 virtual NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0;253 virtual NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) = 0; 254 254 }; 255 255 -
include/settings/settings_old.hpp
r569a179 r7443b58 82 82 key_map keys_; 83 83 void add_mapping(std::wstring path_new, std::wstring path_old) { 84 get_core()->get_logger()->debug(__FILE__, __LINE__, _T("Mapping: ") + path_new + _T(" to ") + path_old);85 84 sections_[path_new] = path_old; 86 85 } … … 127 126 virtual std::wstring get_real_string(settings_core::key_path_type key) { 128 127 key = map_key(key); 129 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second);130 128 return internal_get_value(key.first, key.second); 131 129 } … … 133 131 134 132 std::wstring internal_get_value(std::wstring path, std::wstring key, int bufferSize = 1024) { 135 get_core()->get_logger()->quick_debug(path + _T("//") + key);136 133 if (!has_key_int(path, key)) 137 134 throw KeyNotFoundException(key); … … 192 189 if (buffer == NULL) 193 190 throw settings_exception(_T("internal_read_keys_from_section:: Failed to allocate memory for buffer!")); 194 unsigned int count = ::GetPrivateProfileSection(section.c_str(), buffer, bufferLength -2, get_file_name().c_str());191 unsigned int count = ::GetPrivateProfileSection(section.c_str(), buffer, bufferLength, get_file_name().c_str()); 195 192 if (count == bufferLength-2) { 196 193 delete [] buffer; … … 234 231 try { 235 232 key = map_key(key); 236 get_core()->get_logger()->quick_debug(key.first + _T("//") + key.second + _T("//") + value.get_string());237 233 WritePrivateProfileString(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), get_file_name().c_str()); 238 234 } catch (settings_exception e) { … … 257 253 /// @author mickem 258 254 virtual void get_real_sections(std::wstring path, string_list &list) { 259 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Get sections for: ")) + path);260 261 255 unsigned int path_length = path.length(); 262 256 //string_list lst = get_mapped_sections(path); … … 276 270 if (pos != std::wstring::npos) 277 271 key.first.first = key.first.first.substr(0,pos); 278 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: ")) + key.first.first);279 272 list.push_back(key.first.first); 280 273 } else if (key.first.first.length() > path_length && path == key.first.first.substr(0, path_length)) { … … 333 326 if (has_key_int(key.second.first, key.second.second)) 334 327 list.push_back(key.first.second); 335 } else {336 //get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("Found: TODO FOO fix sub sections")) + key.first.first);337 328 } 338 329 } … … 341 332 if (key.first == path) { 342 333 section_cache_type::const_iterator it = section_cache_.find(key.second); 343 get_core()->get_logger()->debug(__FILE__, __LINE__, std::wstring(_T("=============>>>>>>>>>>>")) + key.first + _T(" >>>> ") + key.second);344 334 if (it == section_cache_.end()) { 345 335 std::set<std::wstring> list = internal_read_keys_from_section(key.second); … … 355 345 356 346 void int_read_section(std::wstring section, string_list &list, unsigned int bufferLength = BUFF_LEN) { 357 //get_core()->get_logger()->debug(__FILE__, __LINE__, _T("Reading (OLD) section: ") + section);358 // @TODO this is not correct!359 347 TCHAR* buffer = new TCHAR[bufferLength+1]; 360 348 if (buffer == NULL) -
include/utils.h
rf0e6036 r7443b58 38 38 39 39 #define MAP_OPTIONS_DISK_ALL(obj, postfix, pfUpper, pfLower) \ 40 else if (p__.first == _T("MaxWarn") pfUpper) { obj.warn.max .upper = p__.second; } \41 else if (p__.first == _T("MaxCrit") pfUpper) { obj.crit.max .upper = p__.second; } \42 else if (p__.first == _T("MinWarn") pfUpper) { obj.warn.min .upper = p__.second; } \43 else if (p__.first == _T("MinCrit") pfUpper) { obj.crit.min .upper = p__.second; } \44 else if (p__.first == _T("MaxWarn") pfLower) { obj.warn.max .lower = p__.second; } \45 else if (p__.first == _T("MaxCrit") pfLower) { obj.crit.max .lower = p__.second; } \46 else if (p__.first == _T("MinWarn") pfLower) { obj.warn.min .lower = p__.second; } \47 else if (p__.first == _T("MinCrit") pfLower) { obj.crit.min .lower = p__.second; } \48 else if (p__.first == _T("MaxWarn") postfix) { obj.warn.max .lower = p__.second; } \49 else if (p__.first == _T("MaxCrit") postfix) { obj.crit.max .lower = p__.second; } \50 else if (p__.first == _T("MinWarn") postfix) { obj.warn.min .upper = p__.second; } \51 else if (p__.first == _T("MinCrit") postfix) { obj.crit.min .upper = p__.second; }40 else if (p__.first == _T("MaxWarn") pfUpper) { obj.warn.max_.upper = p__.second; } \ 41 else if (p__.first == _T("MaxCrit") pfUpper) { obj.crit.max_.upper = p__.second; } \ 42 else if (p__.first == _T("MinWarn") pfUpper) { obj.warn.min_.upper = p__.second; } \ 43 else if (p__.first == _T("MinCrit") pfUpper) { obj.crit.min_.upper = p__.second; } \ 44 else if (p__.first == _T("MaxWarn") pfLower) { obj.warn.max_.lower = p__.second; } \ 45 else if (p__.first == _T("MaxCrit") pfLower) { obj.crit.max_.lower = p__.second; } \ 46 else if (p__.first == _T("MinWarn") pfLower) { obj.warn.min_.lower = p__.second; } \ 47 else if (p__.first == _T("MinCrit") pfLower) { obj.crit.min_.lower = p__.second; } \ 48 else if (p__.first == _T("MaxWarn") postfix) { obj.warn.max_.lower = p__.second; } \ 49 else if (p__.first == _T("MaxCrit") postfix) { obj.crit.max_.lower = p__.second; } \ 50 else if (p__.first == _T("MinWarn") postfix) { obj.warn.min_.upper = p__.second; } \ 51 else if (p__.first == _T("MinCrit") postfix) { obj.crit.min_.upper = p__.second; } 52 52 53 53 #define MAP_OPTIONS_NUMERIC_ALL(obj, postfix) \ 54 else if (p__.first == (_T("MaxWarn") postfix)) { obj.warn.max = p__.second; } \55 else if (p__.first == (_T("MaxCrit") postfix)) { obj.crit.max = p__.second; } \56 else if (p__.first == (_T("MinWarn") postfix)) { obj.warn.min = p__.second; } \57 else if (p__.first == (_T("MinCrit") postfix)) { obj.crit.min = p__.second; }54 else if (p__.first == (_T("MaxWarn") postfix)) { obj.warn.max_ = p__.second; } \ 55 else if (p__.first == (_T("MaxCrit") postfix)) { obj.crit.max_ = p__.second; } \ 56 else if (p__.first == (_T("MinWarn") postfix)) { obj.warn.min_ = p__.second; } \ 57 else if (p__.first == (_T("MinCrit") postfix)) { obj.crit.min_ = p__.second; } 58 58 59 59 #define MAP_OPTIONS_EXACT_NUMERIC_ALL(obj, postfix) \ … … 75 75 #define MAP_OPTIONS_STR(value, obj) \ 76 76 else if (p__.first == value) { obj = p__.second; } 77 #define MAP_OPTIONS_DOUBLE(value, obj) \ 78 else if (p__.first == value) { obj = strEx::stod(p__.second); } 79 77 80 #define MAP_OPTIONS_STR2INT(value, obj) \ 78 81 else if (p__.first == value) { obj = _wtoi(p__.second.c_str()); } -
modules/CheckDisk/CheckDisk.cpp
r1f24a1c r7443b58 31 31 #include "file_finder.hpp" 32 32 #include "filter.hpp" 33 #include <char_buffer.hpp> 33 34 34 35 namespace sh = nscapi::settings_helper; … … 50 51 get_core()->registerCommand(_T("CheckFileSize"), _T("Check or directory a file and verify its size.")); 51 52 get_core()->registerCommand(_T("CheckDriveSize"), _T("Check the size (free-space) of a drive or volume.")); 52 get_core()->registerCommand(_T("CheckFile2"), _T("Check various aspects of a file and/or folder.")); 53 get_core()->registerCommand(_T("CheckFile2"), _T("(deprecated) Check various aspects of a file and/or folder.")); 54 get_core()->registerCommand(_T("CheckFiles"), _T("Check various aspects of a file and/or folder.")); 53 55 54 56 sh::settings_registry settings(get_settings_proxy()); … … 88 90 89 91 92 class volume_helper { 93 94 typedef HANDLE (WINAPI *typeFindFirstVolumeW)( __out_ecount(cchBufferLength) LPWSTR lpszVolumeName, __in DWORD cchBufferLength); 95 typedef BOOL (WINAPI *typeFindNextVolumeW)( __inout HANDLE hFindVolume, __out_ecount(cchBufferLength) LPWSTR lpszVolumeName, __in DWORD cchBufferLength); 96 typedef HANDLE (WINAPI *typeFindFirstVolumeMountPointW)( __in LPCWSTR lpszRootPathName, __out_ecount(cchBufferLength) LPWSTR lpszVolumeMountPoint, __in DWORD cchBufferLength ); 97 typedef BOOL (WINAPI *typeGetVolumeNameForVolumeMountPointW)( __in LPCWSTR lpszVolumeMountPoint, __out_ecount(cchBufferLength) LPWSTR lpszVolumeName, __in DWORD cchBufferLength ); 98 typeFindFirstVolumeW ptrFindFirstVolumeW; 99 typeFindNextVolumeW ptrFindNextVolumeW; 100 typeFindFirstVolumeMountPointW ptrFindFirstVolumeMountPointW; 101 typeGetVolumeNameForVolumeMountPointW ptrGetVolumeNameForVolumeMountPointW; 102 HMODULE hLib; 103 104 public: 105 typedef std::map<std::wstring,std::wstring> map_type; 106 107 public: 108 volume_helper() : ptrFindFirstVolumeW(NULL) { 109 hLib = ::LoadLibrary(_TEXT("KERNEL32")); 110 if (hLib) { 111 // Find PSAPI functions 112 ptrFindFirstVolumeW = (typeFindFirstVolumeW)::GetProcAddress(hLib, "FindFirstVolumeW"); 113 ptrFindNextVolumeW = (typeFindNextVolumeW)::GetProcAddress(hLib, "FindNextVolumeW"); 114 ptrFindFirstVolumeMountPointW = (typeFindFirstVolumeMountPointW)::GetProcAddress(hLib, "FindFirstVolumeMountPointW"); 115 ptrGetVolumeNameForVolumeMountPointW = (typeGetVolumeNameForVolumeMountPointW)::GetProcAddress(hLib, "GetVolumeNameForVolumeMountPointW"); 116 } 117 } 118 119 ~volume_helper() { 120 121 } 122 123 HANDLE FindFirstVolume(std::wstring &volume) { 124 if (ptrFindFirstVolumeW == NULL) 125 return INVALID_HANDLE_VALUE; 126 char_buffer buffer(1024); 127 HANDLE h = ptrFindFirstVolumeW(buffer.unsafe_get_buffer(), buffer.length()); 128 if (h != INVALID_HANDLE_VALUE) 129 volume = buffer.unsafe_get_buffer(); 130 return h; 131 } 132 BOOL FindNextVolume(HANDLE hVolume, std::wstring &volume) { 133 if (ptrFindFirstVolumeW == NULL || hVolume == INVALID_HANDLE_VALUE) 134 return FALSE; 135 char_buffer buffer(1024); 136 BOOL r = ptrFindNextVolumeW(hVolume, buffer.unsafe_get_buffer(), buffer.length()); 137 if (r) 138 volume = buffer.unsafe_get_buffer(); 139 return r; 140 } 141 142 void getVolumeInformation(std::wstring volume, std::wstring &name) { 143 char_buffer volumeName(1024); 144 char_buffer fileSysName(1024); 145 DWORD maximumComponentLength, fileSystemFlags; 146 147 if (!GetVolumeInformation(volume.c_str(), volumeName.unsafe_get_buffer(), volumeName.length(), 148 NULL, &maximumComponentLength, &fileSystemFlags, fileSysName.unsafe_get_buffer(), fileSysName.length())) { 149 NSC_LOG_ERROR_STD(_T("Failed to get volume information: ") + volume); 150 } else { 151 name = volumeName.unsafe_get_buffer(); 152 } 153 } 154 155 156 bool GetVolumeNameForVolumeMountPoint(std::wstring volumeMountPoint, std::wstring &volumeName) { 157 char_buffer buffer(1024); 158 if (ptrGetVolumeNameForVolumeMountPointW(volumeMountPoint.c_str(), buffer.unsafe_get_buffer(), buffer.length())) { 159 volumeName = buffer; 160 return true; 161 } 162 return false; 163 } 164 std::wstring GetVolumeNameForVolumeMountPoint(std::wstring volumeMountPoint) { 165 std::wstring volumeName; 166 GetVolumeNameForVolumeMountPoint(volumeMountPoint, volumeName); 167 return volumeName; 168 } 169 170 map_type get_volumes(map_type alias) { 171 map_type ret; 172 std::wstring volume; 173 HANDLE hVol = FindFirstVolume(volume); 174 if (hVol == INVALID_HANDLE_VALUE) { 175 NSC_LOG_ERROR_STD(_T("Failed to enumerate volumes")); 176 return ret; 177 } 178 BOOL bFlag = TRUE; 179 while (bFlag) { 180 map_type::iterator it = alias.find(volume); 181 if (it != alias.end()) 182 ret[volume] = (*it).second; 183 else 184 ret[volume] = get_title(volume); 185 bFlag = FindNextVolume(hVol, volume); 186 } 187 return ret; 188 } 189 190 std::wstring get_title(std::wstring volume) { 191 std::wstring title; 192 getVolumeInformation(volume, title); 193 return title; 194 } 195 196 197 }; 90 198 91 199 … … 112 220 std::list<DriveContainer> drives; 113 221 std::wstring strCheckAll; 222 bool ignore_unreadable = false; 223 float magic = 0; 114 224 115 225 MAP_OPTIONS_BEGIN(args) … … 122 232 MAP_OPTIONS_BOOL_VALUE(_T("FilterType"), bFilterRemote, _T("REMOTE")) 123 233 MAP_OPTIONS_BOOL_VALUE(_T("FilterType"), bFilterNoRootDir, _T("NO_ROOT_DIR")) 234 MAP_OPTIONS_BOOL_TRUE(_T("ignore-unreadable"), ignore_unreadable) 124 235 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 125 236 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 126 237 //MAP_OPTIONS_BOOL_TRUE(CHECK_ALL, bCheckAll) 127 238 MAP_OPTIONS_STR(CHECK_ALL, strCheckAll) 239 MAP_OPTIONS_DOUBLE(_T("magic"), magic) 128 240 MAP_OPTIONS_BOOL_TRUE(CHECK_ALL_OTHERS, bCheckAllOthers) 129 241 MAP_OPTIONS_SECONDARY_BEGIN(_T(":"), p2) … … 143 255 144 256 if (strCheckAll == _T("volumes")) { 257 volume_helper helper; 258 volume_helper::map_type volume_alias; 145 259 146 260 DWORD bufSize = GetLogicalDriveStrings(0, NULL)+5; … … 149 263 while (buffer[0] != 0) { 150 264 std::wstring drv = buffer; 151 152 UINT drvType = GetDriveType(drv.c_str()); 265 volume_alias[helper.GetVolumeNameForVolumeMountPoint(drv)] = drv; 266 buffer = &buffer[drv.size()]; 267 buffer++; 268 } 269 } else { 270 NSC_LOG_ERROR_STD(_T("Failed to get buffer size: ") + error::lookup::last_error()); 271 } 272 273 volume_helper::map_type volumes = helper.get_volumes(volume_alias); 274 BOOST_FOREACH(volume_helper::map_type::value_type v, volumes) { 275 UINT drvType = GetDriveType(v.first.c_str()); 153 276 if ( 154 277 ((!bFilter)&&(drvType == DRIVE_FIXED)) || … … 159 282 ((bFilter)&&(bFilterNoRootDir)&&(drvType==DRIVE_NO_ROOT_DIR)) 160 283 ) 161 drives.push_back(DriveContainer( drv, tmpObject.warn, tmpObject.crit));284 drives.push_back(DriveContainer(v.first, v.second, tmpObject.warn, tmpObject.crit)); 162 285 else 163 NSC_DEBUG_MSG_STD(_T("Ignoring drive: ") + drv); 164 165 buffer = &buffer[drv.size()]; 166 buffer++; 167 } 168 } else { 169 NSC_LOG_ERROR_STD(_T("Failed to get buffer size: ") + error::lookup::last_error()); 286 NSC_DEBUG_MSG_STD(_T("Ignoring drive: ") + v.second); 170 287 } 171 288 } … … 232 349 drive.perfData = bPerfData; 233 350 UINT drvType = GetDriveType(drive.data.c_str()); 351 std::wstring error; 234 352 235 353 if ((!bFilter)&&!((drvType == DRIVE_FIXED)||(drvType == DRIVE_NO_ROOT_DIR))) { … … 245 363 message = _T("UNKNOWN: Drive does not match the current filter: ") + drive.getAlias() + _T(" (add FilterType=") + get_filter(drvType) + _T(" to check this drive)"); 246 364 return NSCAPI::returnUNKNOWN; 247 } 248 249 ULARGE_INTEGER freeBytesAvailableToCaller; 250 ULARGE_INTEGER totalNumberOfBytes; 251 ULARGE_INTEGER totalNumberOfFreeBytes; 252 if (!GetDiskFreeSpaceEx(drive.data.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 253 message = _T("CRITICAL: Could not get free space for: ") + drive.getAlias() + _T(" ") + drive.data + _T(" reason: ") + error::lookup::last_error(); 254 return NSCAPI::returnCRIT; 365 } 366 367 ULARGE_INTEGER freeBytesAvailableToCaller; 368 ULARGE_INTEGER totalNumberOfBytes; 369 ULARGE_INTEGER totalNumberOfFreeBytes; 370 if (!GetDiskFreeSpaceEx(drive.data.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { 371 DWORD err = GetLastError(); 372 if (!ignore_unreadable || err != ERROR_ACCESS_DENIED) { 373 message = _T("CRITICAL: Could not get free space for: ") + drive.getAlias() + _T(" ") + drive.data + _T(" reason: ") + error::lookup::last_error(err); 374 return NSCAPI::returnCRIT; 375 } 376 drive.setDefault(tmpObject); 377 error = drive.getAlias() + _T(": unreadable"); 378 freeBytesAvailableToCaller.QuadPart = 0; 379 totalNumberOfFreeBytes.QuadPart = 0; 380 totalNumberOfBytes.QuadPart = 0; 255 381 } 256 382 … … 262 388 message += strEx::itos(totalNumberOfBytes.QuadPart); 263 389 } else { 264 checkHolders::PercentageValueType<checkHolders::disk_size_type, checkHolders::disk_size_type> value; 265 std::wstring tstr; 266 value.value = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 267 value.total = totalNumberOfBytes.QuadPart; 268 drive.setDefault(tmpObject); 269 drive.runCheck(value, returnCode, message, perf); 390 if (error.empty()) { 391 checkHolders::PercentageValueType<checkHolders::disk_size_type, checkHolders::disk_size_type> value; 392 std::wstring tstr; 393 value.value = totalNumberOfBytes.QuadPart-totalNumberOfFreeBytes.QuadPart; 394 value.total = totalNumberOfBytes.QuadPart; 395 drive.setDefault(tmpObject); 396 drive.set_magic(magic); 397 drive.runCheck(value, returnCode, message, perf); 398 } else { 399 strEx::append_list(message, error, _T(", ")); 400 } 270 401 } 271 402 } … … 308 439 MAP_OPTIONS_STR_AND(_T("File"), tmpObject.data, paths.push_back(tmpObject)) 309 440 MAP_OPTIONS_SHOWALL(tmpObject) 310 MAP_OPTIONS_STR(_T("MaxWarn"), tmpObject.warn.max )311 MAP_OPTIONS_STR(_T("MinWarn"), tmpObject.warn.min )312 MAP_OPTIONS_STR(_T("MaxCrit"), tmpObject.crit.max )313 MAP_OPTIONS_STR(_T("MinCrit"), tmpObject.crit.min )441 MAP_OPTIONS_STR(_T("MaxWarn"), tmpObject.warn.max_) 442 MAP_OPTIONS_STR(_T("MinWarn"), tmpObject.warn.min_) 443 MAP_OPTIONS_STR(_T("MaxCrit"), tmpObject.crit.max_) 444 MAP_OPTIONS_STR(_T("MinCrit"), tmpObject.crit.min_) 314 445 MAP_OPTIONS_BOOL_TRUE(_T("debug"), debug) 315 446 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) … … 533 664 return NSCAPI::returnUNKNOWN; 534 665 } 535 //file_finder::file_filter_function_ex finder;536 666 file_finder::PathContainer tmpObject; 537 667 std::list<std::wstring> paths; … … 634 764 635 765 636 NSCAPI::nagiosReturn CheckDisk::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {637 if (command == _T(" CheckFileSize")) {766 NSCAPI::nagiosReturn CheckDisk::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 767 if (command == _T("checkfilesize")) { 638 768 return CheckFileSize(arguments, message, perf); 639 } else if (command == _T(" CheckDriveSize")) {769 } else if (command == _T("checkdrivesize")) { 640 770 return CheckDriveSize(arguments, message, perf); 641 } else if (command == _T(" CheckFiles")) {771 } else if (command == _T("checkfiles")) { 642 772 return CheckFiles(arguments, message, perf); 643 } else if (command == _T(" CheckSingleFile")) {773 } else if (command == _T("checksinglefile")) { 644 774 return CheckSingleFile(arguments, message, perf); 645 } else if (command == _T("get FileAge")) {775 } else if (command == _T("getfileage")) { 646 776 return getFileAge(arguments, message, perf); 647 777 } -
modules/CheckDisk/CheckDisk.h
r1f24a1c r7443b58 51 51 bool hasMessageHandler(); 52 52 std::wstring get_filter(unsigned int drvType); 53 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);53 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 54 54 55 55 // Check commands … … 61 61 62 62 private: 63 typedef checkHolders:: CheckContainer<checkHolders::MaxMinPercentageBoundsDiskSize> DriveContainer;63 typedef checkHolders::MagicCheckContainer<checkHolders::MaxMinPercentageBoundsDiskSize> DriveContainer; 64 64 }; -
modules/CheckEventLog/CheckEventLog.cpp
r1f24a1c r7443b58 627 627 }; 628 628 629 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {630 if (command != _T(" CheckEventLog"))629 NSCAPI::nagiosReturn CheckEventLog::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 630 if (command != _T("checkeventlog")) 631 631 return NSCAPI::returnIgnored; 632 632 simple_timer time; -
modules/CheckEventLog/CheckEventLog.h
r5e12ba6 r7443b58 57 57 bool hasCommandHandler(); 58 58 bool hasMessageHandler(); 59 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);59 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 60 60 }; -
modules/CheckExternalScripts/CheckExternalScripts.cpp
rc760fc9 r7443b58 136 136 137 137 138 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {138 NSCAPI::nagiosReturn CheckExternalScripts::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 139 139 command_list::const_iterator cit = commands.find(command); 140 140 bool isAlias = false; … … 151 151 int i=1; 152 152 BOOST_FOREACH(std::wstring str, arguments) { 153 if ( isAlias ||allowNasty_) {153 if (!isAlias && !allowNasty_) { 154 154 if (str.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 155 155 NSC_LOG_ERROR(_T("Request string contained illegal metachars!")); … … 157 157 } 158 158 } 159 strEx::replace(args, _T("$ARG") + strEx::itos(i ) + _T("$"), str);159 strEx::replace(args, _T("$ARG") + strEx::itos(i++) + _T("$"), str); 160 160 } 161 161 } 162 162 if (isAlias) { 163 return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 163 try { 164 return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, true); 165 } catch (boost::escaped_list_error &e) { 166 NSC_LOG_MESSAGE(_T("Failed to parse alias expression: ") + strEx::string_to_wstring(e.what())); 167 NSC_LOG_MESSAGE(_T("We will now try parsing the old syntax instead...")); 168 return GET_CORE()->InjectSplitAndCommand(cd.command, args, ' ', message, perf, false); 169 } 164 170 } else { 165 171 int result = process::executeProcess(process::exec_arguments(root_, cd.command + _T(" ") + args, timeout), message, perf); -
modules/CheckExternalScripts/CheckExternalScripts.h
r497b779 r7443b58 36 36 } 37 37 }; 38 typedef std::map<st rEx::wci_string, command_data> command_list;38 typedef std::map<std::wstring, command_data> command_list; 39 39 command_list commands; 40 40 command_list alias; … … 68 68 bool hasCommandHandler(); 69 69 bool hasMessageHandler(); 70 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);70 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 71 71 std::wstring getConfigurationMeta(); 72 72 -
modules/CheckHelpers/CheckHelpers.cpp
r1ecd26f r7443b58 82 82 } 83 83 84 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {84 NSCAPI::nagiosReturn CheckHelpers::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 85 85 if (command == _T("checkversion")) { 86 86 message = GET_CORE()->getApplicationVersionString(); -
modules/CheckHelpers/CheckHelpers.h
r1ecd26f r7443b58 48 48 bool hasCommandHandler(); 49 49 bool hasMessageHandler(); 50 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);50 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 51 51 52 52 // Check commands -
modules/CheckNSCP/CheckNSCP.cpp
rc760fc9 r7443b58 145 145 } 146 146 147 NSCAPI::nagiosReturn CheckNSCP::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {147 NSCAPI::nagiosReturn CheckNSCP::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 148 148 if (command == _T("check_nscp")) { 149 149 return check_nscp(arguments, message, perf); -
modules/CheckNSCP/CheckNSCP.h
rc760fc9 r7443b58 51 51 bool hasMessageHandler(); 52 52 void handleMessage(int msgType, const std::string file, int line, std::string message); 53 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);53 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 54 54 std::string render(int msgType, const std::string file, int line, std::string message); 55 55 NSCAPI::nagiosReturn check_nscp( std::list<std::wstring> arguments, std::wstring & msg, std::wstring & perf ); -
modules/CheckSystem/CheckSystem.cpp
rc760fc9 r7443b58 66 66 bool CheckSystem::loadModuleEx(std::wstring alias, NSCAPI::moduleLoadMode mode) { 67 67 PDHCollector::system_counter_data *data = new PDHCollector::system_counter_data; 68 data->check_intervall = 10; 68 69 try { 70 typedef std::map<std::wstring,std::wstring> counter_map_type; 69 71 std::map<std::wstring,std::wstring> service_mappings; 70 bool default_counters; 72 std::map<std::wstring,std::wstring> counters; 73 bool default_counters = true; 71 74 72 75 sh::settings_registry settings(get_settings_proxy()); … … 81 84 (_T("pdh"), _T("PDH COUNTER INFORMATION"), _T("")) 82 85 83 //(_T("pdh/counter"), _T("PDH COUNTERS"), _T("")) 86 (_T("pdh/counters"), sh::wstring_map_path(&counters) 87 , _T("PDH COUNTERS"), _T("")) 84 88 85 89 ; … … 87 91 88 92 settings.alias().add_key_to_settings() 89 (_T("default"), sh::bool_key(&default_counters ),93 (_T("default"), sh::bool_key(&default_counters, true), 90 94 _T("HOSTNAME"), _T("The host name of this host if set to blank (default) the windows name of the computer will be used.")) 91 95 // … … 113 117 typedef PDHCollector::system_counter_data::counter cnt; 114 118 if (default_counters) { 115 data->counters.push_back(cnt(_T("cpu load"), _T("\\238(_total)\\6"), cnt::type_int64, cnt::format_large, cnt::rrd)); 116 data->counters.push_back(cnt(_T("memory commit bytes"), _T("\\4\26"), cnt::type_int64, cnt::format_large, cnt::value)); 117 data->counters.push_back(cnt(_T("memory commit limit"), _T("\\4\\30"), cnt::type_int64, cnt::format_large, cnt::value)); 118 data->counters.push_back(cnt(_T("uptime"), _T("\\2\\674"), cnt::type_int64, cnt::format_large, cnt::value)); 119 data->counters.push_back(cnt(PDH_SYSTEM_KEY_CPU, _T("\\238(_total)\\6"), cnt::type_int64, cnt::format_large, cnt::rrd)); 120 data->counters.push_back(cnt(PDH_SYSTEM_KEY_MCB, _T("\\4\\26"), cnt::type_int64, cnt::format_large, cnt::value)); 121 data->counters.push_back(cnt(PDH_SYSTEM_KEY_MCL, _T("\\4\\30"), cnt::type_int64, cnt::format_large, cnt::value)); 122 data->counters.push_back(cnt(PDH_SYSTEM_KEY_UPT, _T("\\2\\674"), cnt::type_int64, cnt::format_large, cnt::value)); 123 } 124 BOOST_FOREACH(counter_map_type::value_type c, counters) { 125 data->counters.push_back(cnt(c.first, c.second, cnt::type_int64, cnt::format_large, cnt::value)); 119 126 } 120 127 … … 388 395 * @return 389 396 */ 390 NSCAPI::nagiosReturn CheckSystem::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) {397 NSCAPI::nagiosReturn CheckSystem::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &msg, std::wstring &perf) { 391 398 CheckSystem::returnBundle rb; 392 if (command == _T("check CPU")) {399 if (command == _T("checkcpu")) { 393 400 return checkCPU(arguments, msg, perf); 394 } else if (command == _T("check UpTime")) {401 } else if (command == _T("checkuptime")) { 395 402 return checkUpTime(arguments, msg, perf); 396 } else if (command == _T("check ServiceState")) {403 } else if (command == _T("checkservicestate")) { 397 404 return checkServiceState(arguments, msg, perf); 398 } else if (command == _T("check ProcState")) {405 } else if (command == _T("checkprocstate")) { 399 406 return checkProcState(arguments, msg, perf); 400 } else if (command == _T("check Mem")) {407 } else if (command == _T("checkmem")) { 401 408 return checkMem(arguments, msg, perf); 402 } else if (command == _T("check Counter")) {409 } else if (command == _T("checkcounter")) { 403 410 return checkCounter(arguments, msg, perf); 404 } else if (command == _T("list CounterInstances")) {411 } else if (command == _T("listcounterinstances")) { 405 412 return listCounterInstances(arguments, msg, perf); 406 } else if (command == _T("check SingleRegEntry")) {413 } else if (command == _T("checksingleregentry")) { 407 414 return checkSingleRegEntry(arguments, msg, perf); 408 415 } … … 459 466 MAP_OPTIONS_BEGIN(arguments) 460 467 MAP_OPTIONS_NUMERIC_ALL(tmpObject, _T("")) 461 MAP_OPTIONS_STR(_T("warn"), tmpObject.warn.max )462 MAP_OPTIONS_STR(_T("crit"), tmpObject.crit.max )468 MAP_OPTIONS_STR(_T("warn"), tmpObject.warn.max_) 469 MAP_OPTIONS_STR(_T("crit"), tmpObject.crit.max_) 463 470 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 464 471 MAP_OPTIONS_STR_AND(_T("time"), tmpObject.data, list.push_back(tmpObject)) … … 523 530 MAP_OPTIONS_BEGIN(arguments) 524 531 MAP_OPTIONS_NUMERIC_ALL(bounds, _T("")) 525 MAP_OPTIONS_STR(_T("warn"), bounds.warn.min )526 MAP_OPTIONS_STR(_T("crit"), bounds.crit.min )532 MAP_OPTIONS_STR(_T("warn"), bounds.warn.min_) 533 MAP_OPTIONS_STR(_T("crit"), bounds.crit.min_) 527 534 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 528 535 MAP_OPTIONS_STR(_T("Alias"), bounds.data) … … 891 898 key = (*entry).command_line; 892 899 else 893 key = (*entry).filename;900 key = boost::to_lower_copy((*entry).filename); 894 901 NSPROCLST::iterator it = ret.find(key); 895 902 if (it == ret.end()) { … … 1098 1105 MAP_OPTIONS_STR(_T("InvalidStatus"), invalidStatus) 1099 1106 MAP_OPTIONS_STR_AND(_T("Counter"), tmpObject.data, counters.push_back(tmpObject)) 1100 MAP_OPTIONS_STR(_T("MaxWarn"), tmpObject.warn.max )1101 MAP_OPTIONS_STR(_T("MinWarn"), tmpObject.warn.min )1102 MAP_OPTIONS_STR(_T("MaxCrit"), tmpObject.crit.max )1103 MAP_OPTIONS_STR(_T("MinCrit"), tmpObject.crit.min )1107 MAP_OPTIONS_STR(_T("MaxWarn"), tmpObject.warn.max_) 1108 MAP_OPTIONS_STR(_T("MinWarn"), tmpObject.warn.min_) 1109 MAP_OPTIONS_STR(_T("MaxCrit"), tmpObject.crit.max_) 1110 MAP_OPTIONS_STR(_T("MinCrit"), tmpObject.crit.min_) 1104 1111 MAP_OPTIONS_BOOL_FALSE(IGNORE_PERFDATA, bPerfData) 1105 1112 MAP_OPTIONS_STR(_T("Alias"), tmpObject.data) … … 1129 1136 CounterContainer counter = (*cit); 1130 1137 try { 1131 std::wstring tstr; 1132 if (bExpandIndex) { 1133 PDH::PDHResolver::expand_index(counter.data); 1134 } 1135 if (!PDH::PDHResolver::validate(counter.data, tstr, bForceReload)) { 1136 NSC_LOG_ERROR_STD(_T("ERROR: Counter not found: ") + counter.data + _T(": ") + tstr); 1137 if (bNSClient) { 1138 1139 1140 double value = 0; 1141 if (counter.data.find('\\') == std::wstring::npos) { 1142 PDHCollector *pObject = pdhThread.getThread(); 1143 if (!pObject) { 1144 msg = _T("ERROR: PDH Collection thread not running."); 1145 return NSCAPI::returnUNKNOWN; 1146 } 1147 value = pObject->get_double(counter.data); 1148 if (value == -1) { 1149 msg = _T("ERROR: Failed to get counter value: ") + counter.data; 1150 return NSCAPI::returnUNKNOWN; 1151 } 1152 } else { 1153 std::wstring tstr; 1154 if (bExpandIndex) { 1155 PDH::PDHResolver::expand_index(counter.data); 1156 } 1157 if (!PDH::PDHResolver::validate(counter.data, tstr, bForceReload)) { 1138 1158 NSC_LOG_ERROR_STD(_T("ERROR: Counter not found: ") + counter.data + _T(": ") + tstr); 1139 //msg = _T("0"); 1140 } else { 1141 msg = _T("CRIT: Counter not found: ") + counter.data + _T(": ") + tstr; 1142 return NSCAPI::returnCRIT; 1159 if (bNSClient) { 1160 NSC_LOG_ERROR_STD(_T("ERROR: Counter not found: ") + counter.data + _T(": ") + tstr); 1161 //msg = _T("0"); 1162 } else { 1163 msg = _T("CRIT: Counter not found: ") + counter.data + _T(": ") + tstr; 1164 return NSCAPI::returnCRIT; 1165 } 1143 1166 } 1144 } 1145 PDH::PDHQuery pdh; 1146 typedef boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > ptr_lsnr_type; 1147 ptr_lsnr_type cDouble(new PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE>()); 1148 //boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > cDouble; 1149 pdh.addCounter(counter.data, cDouble); 1150 pdh.open(); 1151 if (bCheckAverages) { 1152 pdh.collect(); 1153 Sleep(1000); 1154 } 1155 pdh.gatherData(); 1156 pdh.close(); 1157 double value = cDouble->getValue(); 1167 PDH::PDHQuery pdh; 1168 typedef boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > ptr_lsnr_type; 1169 ptr_lsnr_type cDouble(new PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE>()); 1170 //boost::shared_ptr<PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> > cDouble; 1171 pdh.addCounter(counter.data, cDouble); 1172 pdh.open(); 1173 if (bCheckAverages) { 1174 pdh.collect(); 1175 Sleep(1000); 1176 } 1177 pdh.gatherData(); 1178 pdh.close(); 1179 value = cDouble->getValue(); 1180 } 1181 1182 1158 1183 if (bNSClient) { 1159 1184 if (!msg.empty()) -
modules/CheckSystem/CheckSystem.h
r5e12ba6 r7443b58 76 76 bool hasCommandHandler(); 77 77 bool hasMessageHandler(); 78 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);78 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 79 79 int commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 80 80 -
modules/CheckSystem/PDHCollector.cpp
r5e12ba6 r7443b58 23 23 24 24 25 PDHCollector::PDHCollector() : hStopEvent_(NULL) , data_(NULL){25 PDHCollector::PDHCollector() : hStopEvent_(NULL)/*, data_(NULL)*/ { 26 26 std::wstring subsystem = SETTINGS_GET_STRING(check_system::PDH_SUBSYSTEM); 27 27 if (subsystem == setting_keys::check_system::PDH_SUBSYSTEM_FAST) { … … 37 37 if (hStopEvent_) 38 38 CloseHandle(hStopEvent_); 39 delete data_;40 } 41 42 boost::shared_ptr<PDHCollectors::PDHCollector> PDHCollector::system_counter_data::counter:: get_counter(int check_intervall) {39 // delete data_; 40 } 41 42 boost::shared_ptr<PDHCollectors::PDHCollector> PDHCollector::system_counter_data::counter::create(int check_intervall) { 43 43 if (data_type == type_uint64 && data_format == format_large && collection_strategy == value) { 44 44 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>); … … 46 46 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>); 47 47 } else if (data_type == type_int64 && data_format == format_large && collection_strategy == rrd) { 48 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>(get_ length(check_intervall)));48 return boost::shared_ptr<PDHCollectors::PDHCollector>(new PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex>(get_buffer_length(check_intervall))); 49 49 } 50 50 return boost::shared_ptr<PDHCollectors::PDHCollector>(); … … 73 73 } 74 74 75 data_ = reinterpret_cast<system_counter_data*>(lpParameter); 76 75 system_counter_data *data = reinterpret_cast<system_counter_data*>(lpParameter); 76 77 check_intervall_ = data->check_intervall; 77 78 PDH::PDHQuery pdh; 78 79 bool bInit = true; 79 80 80 81 { 82 SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 81 83 WriteLock lock(&mutex_, true, 5000); 82 84 if (!lock.IsLocked()) { … … 86 88 pdh.removeAllCounters(); 87 89 NSC_DEBUG_MSG_STD(_T("Loading counters...")); 88 BOOST_FOREACH(system_counter_data::counter c, data_->counters) { 89 NSC_DEBUG_MSG_STD(_T("Loading counter: ") + c.alias + _T(" = ") + c.path); 90 collector_ptr collector = c.get_counter(data_->check_intervall); 91 if (collector) { 92 counters_[c.alias] = collector; 93 pdh.addCounter(c.path, collector); 94 } else { 95 NSC_LOG_ERROR_STD(_T("Failed to load counter: ") + c.alias + _T(" = ") + c.path); 90 BOOST_FOREACH(system_counter_data::counter c, data->counters) { 91 try { 92 NSC_DEBUG_MSG_STD(_T("Loading counter: ") + c.alias + _T(" = ") + c.path); 93 collector_ptr collector = c.create(check_intervall_); 94 if (collector) { 95 counters_[c.alias] = collector; 96 pdh.addCounter(c.path, collector); 97 } else { 98 NSC_LOG_ERROR_STD(_T("Failed to load counter: ") + c.alias + _T(" = ") + c.path); 99 } 100 } catch (...) { 101 NSC_LOG_ERROR_STD(_T("EXCEPTION: Failed to load counter: ") + c.alias + _T(" = ") + c.path); 96 102 } 97 103 } 98 //SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT));99 // pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_LIM), &memCmtLim);100 // pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_MEM_CMT_BYT), &memCmt);101 // pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_SYSUP), &upTime);102 // pdh.addCounter(SETTINGS_GET_STRING(check_system::PDH_CPU), &cpu);103 104 try { 104 105 pdh.open(); … … 109 110 } 110 111 } 112 data = NULL; 113 delete data; 111 114 112 115 DWORD waitStatus = 0; … … 137 140 NSC_LOG_ERROR_STD(*cit); 138 141 } 139 } while (((waitStatus = WaitForSingleObject(hStopEvent_, data_->check_intervall*100)) == WAIT_TIMEOUT));142 } while (((waitStatus = WaitForSingleObject(hStopEvent_, check_intervall_*100)) == WAIT_TIMEOUT)); 140 143 } else { 141 144 NSC_LOG_ERROR_STD(_T("No performance counters were found we will not wait for the end instead...")); … … 179 182 } 180 183 184 double PDHCollector::get_avg_value(std::wstring counter, unsigned int delta) { 185 ReadLock lock(&mutex_, true, 5000); 186 if (!lock.IsLocked()) { 187 NSC_LOG_ERROR(_T("Failed to get Mutex for: ") + counter); 188 return 0; 189 } 190 191 counter_map::iterator it = counters_.find(counter); 192 if (it == counters_.end()) 193 return 0; 194 collector_ptr ptr = (*it).second; 195 return ptr->get_average(delta); 196 } 197 181 198 182 199 /** … … 196 213 */ 197 214 int PDHCollector::getCPUAvrage(std::wstring time) { 198 unsigned int mseconds = strEx::stoui_as_time(time, 100); 199 ReadLock lock(&mutex_, true, 5000); 200 if (!lock.IsLocked()) { 201 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 202 return -1; 203 } 204 try { 205 return static_cast<int>(cpu.getAvrage(mseconds / (100))); 215 int frequency; 216 { 217 ReadLock lock(&mutex_, true, 5000); 218 if (!lock.IsLocked()) { 219 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 220 return -1; 221 } 222 frequency = check_intervall_*100; 223 224 } 225 try { 226 unsigned int mseconds = strEx::stoui_as_time(time, frequency); 227 return static_cast<int>(get_avg_value(PDH_SYSTEM_KEY_CPU, mseconds/frequency)); 206 228 } catch (PDHCollectors::PDHException &e) { 207 229 NSC_LOG_ERROR(_T("Failed to get CPU value: ") + e.getError()); … … 219 241 */ 220 242 long long PDHCollector::getUptime() { 243 try { 244 return get_int_value(PDH_SYSTEM_KEY_UPT); 245 } catch (PDHCollectors::PDHException &e) { 246 NSC_LOG_ERROR(_T("Failed to get UPTIME value: ") + e.getError()); 247 return -1; 248 } catch (...) { 249 NSC_LOG_ERROR(_T("Failed to get UPTIME value")); 250 return -1; 251 } 252 } 253 /** 254 * Memory commit limit (your guess is as good as mine to what this is :) 255 * @return Some form of memory check 256 */ 257 unsigned long long PDHCollector::getMemCommitLimit() { 258 try { 259 return get_int_value(PDH_SYSTEM_KEY_MCL); 260 } catch (PDHCollectors::PDHException &e) { 261 NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value: ") + e.getError()); 262 return -1; 263 } catch (...) { 264 NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value")); 265 return -1; 266 } 267 } 268 /** 269 * 270 * Memory committed bytes (your guess is as good as mine to what this is :) 271 * @return Some form of memory check 272 */ 273 unsigned long long PDHCollector::getMemCommit() { 274 try { 275 return get_int_value(PDH_SYSTEM_KEY_MCB); 276 } catch (PDHCollectors::PDHException &e) { 277 NSC_LOG_ERROR(_T("Failed to get MEM_CMT value: ") + e.getError()); 278 return -1; 279 } catch (...) { 280 NSC_LOG_ERROR(_T("Failed to get MEM_CMT value")); 281 return -1; 282 } 283 } 284 285 double PDHCollector::get_double(std::wstring counter) { 221 286 ReadLock lock(&mutex_, true, 5000); 222 287 if (!lock.IsLocked()) { … … 225 290 } 226 291 try { 227 return upTime.getValue(); 228 } catch (PDHCollectors::PDHException &e) { 229 NSC_LOG_ERROR(_T("Failed to get UPTIME value: ") + e.getError()); 230 return -1; 231 } catch (...) { 232 NSC_LOG_ERROR(_T("Failed to get UPTIME value")); 233 return -1; 234 } 235 } 236 /** 237 * Memory commit limit (your guess is as good as mine to what this is :) 238 * @return Some form of memory check 239 */ 240 unsigned long long PDHCollector::getMemCommitLimit() { 241 ReadLock lock(&mutex_, true, 5000); 242 if (!lock.IsLocked()) { 243 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 244 return -1; 245 } 246 try { 247 return memCmtLim.getValue(); 248 } catch (PDHCollectors::PDHException &e) { 249 NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value: ") + e.getError()); 250 return -1; 251 } catch (...) { 252 NSC_LOG_ERROR(_T("Failed to get MEM_CMT_LIMIT value")); 253 return -1; 254 } 255 } 256 /** 257 * 258 * Memory committed bytes (your guess is as good as mine to what this is :) 259 * @return Some form of memory check 260 */ 261 unsigned long long PDHCollector::getMemCommit() { 262 ReadLock lock(&mutex_, true, 5000); 263 if (!lock.IsLocked()) { 264 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 265 return -1; 266 } 267 try { 268 return memCmt.getValue(); 269 } catch (PDHCollectors::PDHException &e) { 270 NSC_LOG_ERROR(_T("Failed to get MEM_CMT value: ") + e.getError()); 271 return -1; 272 } catch (...) { 273 NSC_LOG_ERROR(_T("Failed to get MEM_CMT value")); 274 return -1; 275 } 276 } 292 counter_map::iterator it = counters_.find(counter); 293 if (it == counters_.end()) { 294 NSC_LOG_ERROR(_T("COunter not found: ") + counter); 295 return -1; 296 } 297 return (*it).second->get_double(); 298 } catch (PDHCollectors::PDHException &e) { 299 NSC_LOG_ERROR(_T("Failed to get double value: ") + e.getError()); 300 return -1; 301 } catch (...) { 302 NSC_LOG_ERROR(_T("Failed to get double value")); 303 return -1; 304 } 305 } -
modules/CheckSystem/PDHCollector.h
r5e12ba6 r7443b58 26 26 #include <boost/unordered_map.hpp> 27 27 #include <boost/shared_ptr.hpp> 28 29 30 #define PDH_SYSTEM_KEY_CPU _T("cpu") 31 #define PDH_SYSTEM_KEY_MCB _T("memory commit bytes") 32 #define PDH_SYSTEM_KEY_MCL _T("memory commit limit") 33 #define PDH_SYSTEM_KEY_UPT _T("uptime") 34 28 35 29 36 /** … … 73 80 std::wstring alias; 74 81 std::wstring path; 82 std::wstring buffer_size; 75 83 collection_strategy_struct collection_strategy; 76 std::wstring buffer_size;77 84 78 boost::shared_ptr<PDHCollectors::PDHCollector> get_counter(int check_intervall);85 boost::shared_ptr<PDHCollectors::PDHCollector> create(int check_intervall); 79 86 80 int get_length(int check_intervall) { 81 unsigned int i = strEx::stoui_as_time(buffer_size, check_intervall*100); 82 if (check_intervall == 0) 87 int get_buffer_length(int check_intervall) { 88 try { 89 unsigned int i = strEx::stoui_as_time(buffer_size, check_intervall*100); 90 if (check_intervall == 0) 91 return 100; // TODO fix this! 92 return i/(check_intervall*100)+10; 93 } catch (...) { 83 94 return 100; // TODO fix this! 84 return i/(check_intervall*100)+10; 95 } 96 85 97 } 86 98 87 // PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim;88 // PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmt;89 // PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> upTime;90 // PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> cpu;91 99 92 100 }; … … 99 107 private: 100 108 101 system_counter_data *data_;109 //system_counter_data *data_; 102 110 MutexRW mutex_; 103 111 HANDLE hStopEvent_; … … 105 113 typedef boost::unordered_map<std::wstring,collector_ptr > counter_map; 106 114 counter_map counters_; 107 // int checkIntervall_; 108 // bool dontCollect_; 109 110 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 111 PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmt; 112 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> upTime; 113 PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> cpu; 115 int check_intervall_; 114 116 115 117 public: … … 127 129 128 130 __int64 get_int_value(std::wstring counter); 129 130 131 private: 132 // bool isRunning(void); 133 // void startRunning(void); 134 // void stopRunning(void); 135 131 double get_avg_value(std::wstring counter, unsigned int delta); 132 double get_double(std::wstring counter); 136 133 }; 137 134 -
modules/CheckTaskSched/CheckTaskSched.cpp
r1f24a1c r7443b58 141 141 } 142 142 143 NSCAPI::nagiosReturn CheckTaskSched::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {144 if (command == _T(" CheckTaskSched"))143 NSCAPI::nagiosReturn CheckTaskSched::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 144 if (command == _T("checktasksched")) 145 145 return TaskSchedule(arguments, message, perf); 146 146 return NSCAPI::returnIgnored; -
modules/CheckTaskSched/CheckTaskSched.h
r1ecd26f r7443b58 51 51 bool hasCommandHandler(); 52 52 bool hasMessageHandler(); 53 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);53 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 54 54 int CheckTaskSched::commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 55 55 -
modules/CheckTaskSched2/CheckTaskSched2.cpp
r4c18192 r7443b58 141 141 } 142 142 143 NSCAPI::nagiosReturn CheckTaskSched2::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {144 if (command == _T(" CheckTaskSched"))143 NSCAPI::nagiosReturn CheckTaskSched2::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 144 if (command == _T("checktasksched")) 145 145 return TaskSchedule(arguments, message, perf); 146 146 return NSCAPI::returnIgnored; -
modules/CheckTaskSched2/CheckTaskSched2.h
r4c18192 r7443b58 51 51 bool hasCommandHandler(); 52 52 bool hasMessageHandler(); 53 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);53 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 54 54 int commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 55 55 -
modules/CheckWMI/CheckWMI.cpp
r1ecd26f r7443b58 264 264 265 265 266 NSCAPI::nagiosReturn CheckWMI::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {267 if (command == _T(" CheckWMI")) {266 NSCAPI::nagiosReturn CheckWMI::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 267 if (command == _T("checkwmi")) { 268 268 return CheckSimpleWMI(arguments, message, perf); 269 } else if (command == _T(" CheckWMIValue")) {269 } else if (command == _T("checkwmivalue")) { 270 270 return CheckSimpleWMIValue(arguments, message, perf); 271 271 } -
modules/CheckWMI/CheckWMI.h
r1ecd26f r7443b58 50 50 bool hasCommandHandler(); 51 51 bool hasMessageHandler(); 52 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);52 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 53 53 int CheckWMI::commandLineExec(const TCHAR* command,const unsigned int argLen,TCHAR** args); 54 54 -
modules/LUAScript/LUAScript.cpp
rc760fc9 r7443b58 80 80 void LUAScript::register_command(script_wrapper::lua_script* script, std::wstring command, std::wstring function) { 81 81 NSC_LOG_MESSAGE(_T("Script loading: ") + script->get_script() + _T(": ") + command); 82 strEx::wci_string bstr = command.c_str(); 83 commands_[bstr] = lua_func(script, function); 82 commands_[command] = lua_func(script, function); 84 83 } 85 84 … … 148 147 149 148 150 NSCAPI::nagiosReturn LUAScript::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) {151 if (command == _T(" LuaReload")) {149 NSCAPI::nagiosReturn LUAScript::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) { 150 if (command == _T("luareload")) { 152 151 return reload(message)?NSCAPI::returnOK:NSCAPI::returnCRIT; 153 152 } -
modules/LUAScript/LUAScript.h
r87cf3c4 r7443b58 41 41 }; 42 42 43 typedef std::map<st rEx::wci_string,lua_func> cmd_list;43 typedef std::map<std::wstring,lua_func> cmd_list; 44 44 typedef std::list<script_wrapper::lua_script*> script_list; 45 45 … … 72 72 bool hasMessageHandler(); 73 73 bool loadScript(const std::wstring script); 74 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);74 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 75 75 //NSCAPI::nagiosReturn RunLUA(const unsigned int argLen, TCHAR **char_args, std::wstring &message, std::wstring &perf); 76 76 //NSCAPI::nagiosReturn extract_return(Lua_State &L, int arg_count, std::wstring &message, std::wstring &perf); -
modules/NRPEClient/NRPEClient.cpp
rc760fc9 r7443b58 153 153 return false; 154 154 } 155 NSCAPI::nagiosReturn NRPEClient::handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf)155 NSCAPI::nagiosReturn NRPEClient::handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf) 156 156 { 157 157 command_list::const_iterator cit = commands.find(strEx::blindstr(command.c_str())); -
modules/NRPEClient/NRPEClient.h
rc760fc9 r7443b58 122 122 bool hasCommandHandler(); 123 123 bool hasMessageHandler(); 124 NSCAPI::nagiosReturn handleCommand(const st rEx::wci_string command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf);124 NSCAPI::nagiosReturn handleCommand(const std::wstring command, std::list<std::wstring> arguments, std::wstring &message, std::wstring &perf); 125 125 int commandLineExec(const unsigned int argLen,TCHAR** args); 126 126 std::wstring getConfigurationMeta(); -
modules/NRPEServer/handler_impl.cpp
r294b37b r7443b58 11 11 std::wstring msg, perf; 12 12 13 if ( allowArgs_) {13 if (!allowArgs_) { 14 14 if (!cmd.second.empty()) { 15 15 NSC_LOG_ERROR(_T("Request contained arguments (not currently allowed, check the allow_arguments option).")); … … 17 17 } 18 18 } 19 if ( allowNasty_) {19 if (!allowNasty_) { 20 20 if (cmd.first.find_first_of(NASTY_METACHARS) != std::wstring::npos) { 21 21 NSC_LOG_ERROR(_T("Request command contained illegal metachars!")); … … 33 33 try { 34 34 NSC_DEBUG_MSG_STD(_T("Running command: ") + cmd.first); 35 ret = nscapi::plugin_singleton->get_core()->Inject SplitAndCommand(cmd.first, cmd.second, '!', msg, perf);35 ret = nscapi::plugin_singleton->get_core()->InjectNRPECommand(cmd.first, cmd.second, msg, perf); 36 36 NSC_DEBUG_MSG_STD(_T("Running command: ") + cmd.first + _T(" = ") + msg); 37 37 } catch (...) { -
scripts/lib/NagiosPlugins.vbs
r9661f81 r7443b58 114 114 Public Function get_threshold (threshold) 115 115 ' Simple function to return the warning and critical threshold 116 If threshold = LCase("warning")Then116 If LCase(threshold) = "warning" Then 117 117 get_threshold = threshold_warning 118 118 End IF 119 119 120 If threshold = LCase("critical")Then120 If LCase(threshold) = "critical" Then 121 121 get_threshold = threshold_critical 122 122 End If … … 136 136 End Function 137 137 138 138 139 140 Public Function get_threshold_perfdat(string) 141 142 Dim cintw0 143 Dim cintw 144 Dim x 145 Dim colon 146 147 cintw0=get_threshold(string) 148 x=Replace(cintw0,"~","") 149 cintw0=Replace(x,"@","") 150 151 colon=Instr(cintw0,":") 152 153 If (colon > 1) Then 154 cintw=Left(cintw0,colon-1) 155 Else 156 If (colon=1) Then 157 cintw=Mid(cintw0,2) 158 Else 159 cintw=cintw0 160 End If 161 End If 162 163 get_threshold_perfdat=cintw 164 165 End Function 166 167 139 168 Public Function check_threshold (value) 140 169 ' Verify the thresholds for warning and critical … … 152 181 check_threshold = 0 153 182 183 value = CDbl(value) 184 154 185 Set re = New RegExp 155 186 re.IgnoreCase = True … … 232 263 Set threshold = re.Execute(threshold) 233 264 234 If threshold(0) < 0 Or threshold(0) > value Then 265 If value < 0 Or value > CDbl(threshold(0)) Then 266 parse_range = 1 267 Else 235 268 parse_range = 0 236 Else237 parse_range = 1238 269 End If 239 270 … … 242 273 re.Pattern = "^([0-9]+):$" 243 274 Set threshold = re.Execute(threshold) 244 If value > threshold(0) Then 245 parse_range = 0 246 Else 247 parse_range = 1 248 End If 249 250 Case 3 251 ' outside the range infinity <- value 252 re.Pattern = "^~:([0-9]+)$" 253 Set threshold = re.Execute(threshold) 254 If value < threshold(0) Then 255 parse_range = 0 256 Else 257 parse_range = 1 258 End If 259 260 Case 4 261 ' outside the range of value:value 262 re.Pattern = "^([0-9]+):([0-9]+)$" 263 Set threshold = re.Execute(threshold) 275 264 276 265 277 For Each thres In threshold 266 If value < thres.SubMatches(0) Or value > thres.SubMatches(1) Then 278 'Wscript.Echo "SubMatches(0): " & thres.SubMatches(0) & " val: " & value 279 If value < CDbl(thres.SubMatches(0)) Then 267 280 parse_range = 1 268 281 Else … … 271 284 Next 272 285 286 287 288 Case 3 289 ' outside the range infinity <- value 290 re.Pattern = "^~:([0-9]+)$" 291 Set threshold = re.Execute(threshold) 292 293 For Each thres In threshold 294 If value > CDbl(thres.SubMatches(0)) Then 295 parse_range = 1 296 Else 297 parse_range = 0 298 End If 299 Next 300 301 302 Case 4 303 ' outside the range of value:value 304 re.Pattern = "^([0-9]+):([0-9]+)$" 305 Set threshold = re.Execute(threshold) 306 307 For Each thres In threshold 308 If value < CDbl(thres.SubMatches(0)) Or value > CDbl(thres.SubMatches(1)) Then 309 parse_range = 1 310 Else 311 parse_range = 0 312 End If 313 Next 314 273 315 Case 5 274 316 re.Pattern = "^@([0-9]+):([0-9]+)$" … … 276 318 277 319 For Each thres In threshold 278 If value > thres.SubMatches(0) And value < thres.SubMatches(1) Then279 Wscript.Echo "Bigger than " & thres.SubMatches(0) & " and smaller than " & thres.SubMatches(1)320 If value >= CDbl(thres.SubMatches(0)) And value <= CDbl(thres.SubMatches(1)) Then 321 'Wscript.Echo "Bigger than " & thres.SubMatches(0) & " and smaller than " & thres.SubMatches(1) 280 322 parse_range = 1 281 323 Else -
service/CMakeLists.txt
r1f24a1c r7443b58 82 82 ) 83 83 SET(service_SRCS ${service_SRCS} 84 ${ NSCP_INCLUDEDIR}/service/unix_service.hpp84 ${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest 85 85 ) 86 86 87 87 ADD_DEFINITIONS(-D_WIN32_DCOM) 88 89 90 # SET( 91 # CMAKE_LINKER_FLAGS 92 # /MANIFEST 93 # /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest" 94 # ) 95 # SET( 96 # CMAKE_MODULE_LINKER_FLAG 97 # /MANIFEST 98 # /MANIFESTFILE:"${CMAKE_CURRENT_SOURCE_DIR}/NSClient++.manifest" 99 # ) 88 100 89 101 ENDIF(WIN32) … … 96 108 ADD_DEFINITIONS(-DUSE_BREAKPAD) 97 109 ENDIF(BREAKPAD_FOUND) 98 99 110 100 111 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../files/old-settings.map ${CMAKE_CURRENT_BINARY_DIR}/old-settings.map COPYONLY) … … 114 125 SET_TARGET_PROPERTIES(${TARGET} PROPERTIES FOLDER "core") 115 126 SET_TARGET_PROPERTIES(${TARGET}_VERSION PROPERTIES FOLDER "core") 127 #IF(WIN32) 128 # SET_TARGET_PROPERTIES(${TARGET} PROPERTIES LINK_FLAGS "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\" /SUBSYSTEM:WINDOWS") 129 #ENDIF(WIN32) 116 130 117 131 SOURCE_GROUP("Common Files" REGULAR_EXPRESSION .*include/.*)
Note: See TracChangeset
for help on using the changeset viewer.








