From 01148749a6e57186877e3578431612c62e348c89 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Mon, 14 Oct 2019 17:10:48 +0200
Subject: [PATCH 1/2] Added secondarygroups macro and updated spanish, english
 and japanses wiki

---
 pandora_console/include/help/en/help_alert_macros.php |  1 +
 pandora_console/include/help/es/help_alert_macros.php |  1 +
 pandora_console/include/help/ja/help_alert_macros.php |  2 ++
 pandora_server/lib/PandoraFMS/Core.pm                 | 10 ++++++++++
 4 files changed, 14 insertions(+)

diff --git a/pandora_console/include/help/en/help_alert_macros.php b/pandora_console/include/help/en/help_alert_macros.php
index 9d730cfcc9..2a16e0b182 100644
--- a/pandora_console/include/help/en/help_alert_macros.php
+++ b/pandora_console/include/help/en/help_alert_macros.php
@@ -77,6 +77,7 @@ Besides the defined module macros, the following macros are available:
 <li>_policy_: Name of the policy that the module belongs to (if applies).</li>
 <li>_prevdata_: Module previous data before the alert has been triggered.</li>
 <li>_rca_: Root cause analysis chain (only for services).</li>
+<li>_secondarygroups_: List of all secondary groups of the agent.</li>
 <li>_server_ip_: Ip of server assigned to agent. </li>
 <li>_server_name_: Name of server assigned to agent. </li>
 <li>_target_ip_: IP address for the module’s target.</li>
diff --git a/pandora_console/include/help/es/help_alert_macros.php b/pandora_console/include/help/es/help_alert_macros.php
index 75e627f19a..e4fa442b2c 100644
--- a/pandora_console/include/help/es/help_alert_macros.php
+++ b/pandora_console/include/help/es/help_alert_macros.php
@@ -77,6 +77,7 @@ Además de las macros de módulo definidas, las siguientes macros están disponi
   <li>_policy_: Nombre de la política a la que pertenece el módulo (si aplica).</li>
   <li>_prevdata_: Dato previo antes de disparase la alerta.</li>
   <li>_rca_: Cadena de análasis de causa raíz (sólo para servicios).</li>
+  <li>_secondarygroups_: Lista de todos los grupos secundarios del agente.</li>
   <li>_server_ip_: Ip del servidor al que el agente está asignado. </li>
   <li>_server_name_: Nombre del servidor al que el agente está asignado. </li>
   <li>_target_ip_: Dirección IP del objetivo del módulo.</li>
diff --git a/pandora_console/include/help/ja/help_alert_macros.php b/pandora_console/include/help/ja/help_alert_macros.php
index 36ff609741..65f598fc8b 100644
--- a/pandora_console/include/help/ja/help_alert_macros.php
+++ b/pandora_console/include/help/ja/help_alert_macros.php
@@ -77,11 +77,13 @@
     <li>_policy_ : モジュールが属するポリシー名 (存在する場合)</li>
     <li>_prevdata_ : アラートを発報する前のモジュールデータ</li>
     <li>_rca_: Root cause analysis chain (only for services).</li>
+    <li>_secondarygroups_: エージェントのすべてのセカンダリグループのリスト</li>
     <li>_server_ip_ : エージェントが割り当てられているサーバ IP。</li>
     <li>_server_name_ : エージェントが割り当てられているサーバ名。 </li>
     <li>_target_ip_ : モジュールの対象IPアドレス</li>
     <li>_target_port_ : モジュールの対象ポート</li>
     <li>_timestamp_ : アラートが発生した日時 (yy-mm-dd hh:mm:ss).</li>
+エージェントのすべてのセカンダリグループのリスト
     <li>_timezone_: _timestamp_ で使用されるタイムゾーン名.</li>
 <p>
 例: Agent _agent_ has fired alert _alert_ with data _data_
diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm
index ef8a9c18bf..94c107f8e3 100644
--- a/pandora_server/lib/PandoraFMS/Core.pm
+++ b/pandora_server/lib/PandoraFMS/Core.pm
@@ -1125,6 +1125,7 @@ sub pandora_execute_action ($$$$$$$$$;$) {
 				_name_tag_ => undef,
 				_all_address_ => undef,
 				'_address_\d+_' => undef,
+				_secondarygroups_ => undef,
 				 );
 	
 	if ((defined ($extra_macros)) && (ref($extra_macros) eq "HASH")) {
@@ -4114,6 +4115,15 @@ sub on_demand_macro($$$$$$;$) {
 		}
 		
 		return(defined($field_value)) ? $field_value : '';
+	} elsif ($macro eq '_secondarygroups_') {
+		my $field_value = '';
+
+		my @groups = get_db_rows ($dbh, 'SELECT tg.nombre from tagent_secondary_group as tsg INNER JOIN tgrupo tg ON tsg.id_group = tg.id_grupo WHERE tsg.id_agent = ?', $module->{'id_agente'});
+		foreach my $element (@groups) {
+			$field_value .= $element->{'nombre'} .",";
+		}
+		chop($field_value);
+		return(defined($field_value)) ? '('.$field_value.')' : '';
 	}
 }
 

From e0ff5bf9cc9c1c4ca9671c7816e82b81e4d7c014 Mon Sep 17 00:00:00 2001
From: Jose Gonzalez <jose.gonzalez@artica.es>
Date: Mon, 14 Oct 2019 17:13:13 +0200
Subject: [PATCH 2/2] Solved an issue with japanese wiki

---
 pandora_console/include/help/ja/help_alert_macros.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/pandora_console/include/help/ja/help_alert_macros.php b/pandora_console/include/help/ja/help_alert_macros.php
index 65f598fc8b..86bf24ad59 100644
--- a/pandora_console/include/help/ja/help_alert_macros.php
+++ b/pandora_console/include/help/ja/help_alert_macros.php
@@ -83,7 +83,6 @@
     <li>_target_ip_ : モジュールの対象IPアドレス</li>
     <li>_target_port_ : モジュールの対象ポート</li>
     <li>_timestamp_ : アラートが発生した日時 (yy-mm-dd hh:mm:ss).</li>
-エージェントのすべてのセカンダリグループのリスト
     <li>_timezone_: _timestamp_ で使用されるタイムゾーン名.</li>
 <p>
 例: Agent _agent_ has fired alert _alert_ with data _data_