From 24ae02386a588c968097b7e1d31e97ebe4d29e7c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 13 May 2015 09:46:59 +0200 Subject: [PATCH] Implement the basename and dirname script functions refs #9256 --- doc/20-library-reference.md | 2 ++ doc/7-icinga-template-library.md | 3 ++- itl/command-nscp-local.conf | 4 ++-- lib/base/scriptutils.cpp | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/20-library-reference.md b/doc/20-library-reference.md index b5fa91839..6b78192d2 100644 --- a/doc/20-library-reference.md +++ b/doc/20-library-reference.md @@ -19,6 +19,8 @@ log(severity, facility, value) | Writes a message to the log. `severity` can be typeof(value) | Returns the type object for a value. get_time() | Returns the current UNIX timestamp. parse_performance_data(pd) | Parses a performance data string and returns an array describing the values. +dirname(path) | Returns the directory portion of the specified path. +basename(path) | Returns the filename portion of the specified path. exit(integer) | Terminates the application. ## Object Accessor Functions diff --git a/doc/7-icinga-template-library.md b/doc/7-icinga-template-library.md index fb6cfc053..f9daa340e 100644 --- a/doc/7-icinga-template-library.md +++ b/doc/7-icinga-template-library.md @@ -1063,7 +1063,8 @@ file: const NscpPath = "C:\\Program Files (x86)\\NSClient++" -By default the check commands assume that NSClient++ is installed in "C:\Program Files\NSClient++". +By default Icinga 2 uses the Microsoft Installer API to determine where NSClient++ is installed. It should +not be necessary to manually set this constant. Note that it is not necessary to run NSClient++ as a Windows service for these commands to work. diff --git a/itl/command-nscp-local.conf b/itl/command-nscp-local.conf index f65520502..9f1a3f5b2 100644 --- a/itl/command-nscp-local.conf +++ b/itl/command-nscp-local.conf @@ -18,13 +18,13 @@ ******************************************************************************/ if (!globals.contains("NscpPath")) { - NscpPath = msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}") + NscpPath = dirname(msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}")) } object CheckCommand "nscp-local" { import "plugin-check-command" - command = [ NscpPath, "client" ] + command = [ "$nscp_path$\\nscp.exe", "client" ] arguments = { "--log" = "$nscp_log_level$" diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index afdfa61bf..1ac249fbf 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -54,6 +54,8 @@ REGISTER_SAFE_SCRIPTFUNCTION(string, &ScriptUtils::CastString); REGISTER_SAFE_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber); REGISTER_SAFE_SCRIPTFUNCTION(bool, &ScriptUtils::CastBool); REGISTER_SAFE_SCRIPTFUNCTION(get_time, &Utility::GetTime); +REGISTER_SAFE_SCRIPTFUNCTION(basename, &Utility::BaseName); +REGISTER_SAFE_SCRIPTFUNCTION(dirname, &Utility::DirName); #ifdef _WIN32 REGISTER_SAFE_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim); #endif /* _WIN32 */ @@ -282,4 +284,4 @@ String ScriptUtils::MsiGetComponentPathShim(const String& component) MsiGetComponentPath(productCode, component.CStr(), path, &szPath); return path; } -#endif /* _WIN32 */ \ No newline at end of file +#endif /* _WIN32 */ -- 2.40.0