commit f0acfcc621492fab3cf324e4275f48cdcd438201
Author: Hideo Yamauchi <renayama19661014@ybb.ne.jp>
Date:   Fri Apr 6 10:08:37 2018 +0900

    Mid: alerts: Change timestamp of Alert of snmp.

Index: pacemaker-1.1.19+20180928.0d2680780/extra/alerts/alert_snmp.sh.sample
===================================================================
--- pacemaker-1.1.19+20180928.0d2680780.orig/extra/alerts/alert_snmp.sh.sample
+++ pacemaker-1.1.19+20180928.0d2680780/extra/alerts/alert_snmp.sh.sample
@@ -123,7 +123,12 @@ send_pacemaker_trap() {
 }
 
 if [ "${trap_add_hires_timestamp_oid}" = "true" ]; then
-    hires_timestamp="HOST-RESOURCES-MIB::hrSystemDate s ${CRM_alert_timestamp}"
+# 
+# Please make hires_timestamp with CRM_alert_timestamp_epoch and CRM_alert_timestamp_usec according to Netsnmp's DateAndTime specification.
+# The current format is "%Y-%m-%d,%H:%M:%S.%01N".
+#
+    trap_fmt_timestamp=`date --date="@${CRM_alert_timestamp_epoch}" +"%Y-%m-%d,%H:%M:%S."`$(echo ${CRM_alert_timestamp_usec} | cut -b 1)
+    hires_timestamp="HOST-RESOURCES-MIB::hrSystemDate s ${trap_fmt_timestamp}"
 fi
 
 if [ -z ${SNMP_PERSISTENT_DIR} ]; then
Index: pacemaker-1.1.19+20180928.0d2680780/include/crm/common/alerts_internal.h
===================================================================
--- pacemaker-1.1.19+20180928.0d2680780.orig/include/crm/common/alerts_internal.h
+++ pacemaker-1.1.19+20180928.0d2680780/include/crm/common/alerts_internal.h
@@ -70,11 +70,13 @@ enum crm_alert_keys_e {
     CRM_alert_timestamp,
     CRM_alert_attribute_name,
     CRM_alert_attribute_value,
+    CRM_alert_timestamp_epoch,
+    CRM_alert_timestamp_usec,
     CRM_alert_select_kind,
     CRM_alert_select_attribute_name
 };
 
-#define CRM_ALERT_INTERNAL_KEY_MAX 16
+#define CRM_ALERT_INTERNAL_KEY_MAX 18
 #define CRM_ALERT_NODE_SEQUENCE "CRM_alert_node_sequence"
 
 extern const char *crm_alert_keys[CRM_ALERT_INTERNAL_KEY_MAX][3];
Index: pacemaker-1.1.19+20180928.0d2680780/lib/common/alerts.c
===================================================================
--- pacemaker-1.1.19+20180928.0d2680780.orig/lib/common/alerts.c
+++ pacemaker-1.1.19+20180928.0d2680780/lib/common/alerts.c
@@ -44,7 +44,9 @@ const char *crm_alert_keys[CRM_ALERT_INT
     [CRM_alert_node_sequence] = {"CRM_notify_node_sequence", CRM_ALERT_NODE_SEQUENCE, NULL},		
     [CRM_alert_timestamp]     = {"CRM_notify_timestamp",     "CRM_alert_timestamp",     NULL},
     [CRM_alert_attribute_name]     = {"CRM_notify_attribute_name",     "CRM_alert_attribute_name",     NULL},
-    [CRM_alert_attribute_value]     = {"CRM_notify_attribute_value",     "CRM_alert_attribute_value",     NULL}
+    [CRM_alert_attribute_value]     = {"CRM_notify_attribute_value",     "CRM_alert_attribute_value",     NULL},
+    [CRM_alert_timestamp_epoch]     = {"CRM_notify_timestamp_epoch",     "CRM_alert_timestamp_epoch",     NULL},
+    [CRM_alert_timestamp_usec]     = {"CRM_notify_timestamp_usec",     "CRM_alert_timestamp_usec",     NULL}
 };
 
 void
Index: pacemaker-1.1.19+20180928.0d2680780/lib/lrmd/lrmd_alerts.c
===================================================================
--- pacemaker-1.1.19+20180928.0d2680780.orig/lib/lrmd/lrmd_alerts.c
+++ pacemaker-1.1.19+20180928.0d2680780/lib/lrmd/lrmd_alerts.c
@@ -130,6 +130,9 @@ exec_alert_list(lrmd_t *lrmd, GList *ale
     bool any_success = FALSE, any_failure = FALSE;
     const char *kind_s = crm_alert_flag2text(kind);
     crm_time_hr_t *now = NULL;
+    struct timeval tv_now;
+    char timestamp_epoch[20];
+    char timestamp_usec[7];
 
     params = alert_key2param(params, CRM_alert_kind, kind_s);
     params = alert_key2param(params, CRM_alert_version, VERSION);
@@ -156,6 +159,9 @@ exec_alert_list(lrmd_t *lrmd, GList *ale
 
         if (now == NULL) {
             now = crm_time_hr_new(NULL);
+            if (gettimeofday(&tv_now, NULL) == 0) {
+                now = crm_time_timeval_hr_convert(NULL, &tv_now);
+            }
         }
         crm_info("Sending %s alert via %s to %s",
                  kind_s, entry->id, entry->recipient);
@@ -176,6 +182,11 @@ exec_alert_list(lrmd_t *lrmd, GList *ale
                                               timestamp);
                 free(timestamp);
             }
+
+            snprintf(timestamp_epoch, sizeof(timestamp_epoch), "%ld", tv_now.tv_sec);
+            copy_params = alert_key2param(copy_params, CRM_alert_timestamp_epoch, timestamp_epoch);
+            snprintf(timestamp_usec, sizeof(timestamp_usec), "%06d", now->useconds);
+            copy_params = alert_key2param(copy_params, CRM_alert_timestamp_usec, timestamp_usec);
         }
 
         copy_params = alert_envvar2params(copy_params, entry);
