pynag / pynag

Python modules and utilities for Nagios plugins and configuration
http://pynag.github.com
GNU General Public License v2.0
177 stars 69 forks source link

Model: Unable to set custom host variables #123

Closed alex-eoi closed 10 years ago

alex-eoi commented 10 years ago

Hi,

when i try to set custom host variables using Model.set_macro(), I get the error: "No support for macro ...". Seems like there is no handling for host variables yet.

alex-eoi commented 10 years ago

Adding this small patch fixes the problem for me:

diff --git a/pynag/Model/__init__.py b/pynag/Model/__init__.py
index f7576a7..1be7bc5 100644
--- a/pynag/Model/__init__.py
+++ b/pynag/Model/__init__.py
@@ -1043,6 +1043,9 @@ class ObjectDefinition(object):
             c[arg_number] = new_value
             self.check_command = '!'.join(c)

+        elif macroname.startswith('$_HOST'):
+            macroname = "_" + macroname[6:-1]
+            self[macroname] = new_value
         elif macroname.startswith('$_SERVICE'):
             macroname = "_" + macroname[9:-1]
             self[macroname] = new_value
palli commented 10 years ago

Thanks a lot Alexander,

If you want your name in the contributor log you can edit the file directly here: https://github.com/pynag/pynag/edit/master/pynag/Model/__init__.py and then send us a pull request.