From 2a9288b9ee8450af09bc4ac66963253fe9078426 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 7 May 2014 15:33:32 +0200
Subject: [PATCH] Implement a read-only mode

---
 README.md                       |  1 +
 action_plugins/serverdensity.py | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/README.md b/README.md
index c91a60b..061e3a5 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ There are plugin parameters to define how the plugin will behave:
 **force** (optional, defaults to False): If an object already exists whether it should be updated
 **cache** (optional, defaults to None): Fully qualified filename for a cache of der Server Density data
 **cleanup** (optional, defaults to False): Decides if undefined alerts in your Ansible inventory available at Server Density should be deleted
+**readonly** (optional, defaults to False): If set to True it will only read the current settings from SD and stores them in a temporary file and does nothing else. This is useful when you want to find out some variable names for alerts or similar things
 
 ##Installation##
 
diff --git a/action_plugins/serverdensity.py b/action_plugins/serverdensity.py
index a7f2803..3736351 100644
--- a/action_plugins/serverdensity.py
+++ b/action_plugins/serverdensity.py
@@ -44,11 +44,21 @@ class ActionModule(object):
         self.force_update = args.get('force', False)
         self.cache_file_name = args.get('cache', None)
         cleanup = args.get('cleanup', False)
+        just_download = args.get('readonly', False)
+
+        if just_download:
+          self.force_update = False
+          self.cache_file_name = os.tmpnam()
+          cleanup = False
 
         result = {}
 
         self.list_all()
 
+        if just_download:
+          vv('Downloaded settings to %s' % self.cache_file_name)
+          return
+
         services = {}
         devicegroup_alerts = {}
         servicegroup_alerts = {}
-- 
GitLab