add optional timestamps to manager events (issue #5535, simplified)
authorKevin P. Fleming <kpfleming@digium.com>
Tue, 3 Jan 2006 22:07:12 +0000 (22:07 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Tue, 3 Jan 2006 22:07:12 +0000 (22:07 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7750 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configs/manager.conf.sample
manager.c

index ff37f8a..cdca9bc 100644 (file)
@@ -20,6 +20,10 @@ enabled = no
 port = 5038
 bindaddr = 0.0.0.0
 ;displayconnects = yes
 port = 5038
 bindaddr = 0.0.0.0
 ;displayconnects = yes
+;
+; Add a Unix epoch timestamp to events (not action responses)
+;
+;timestampevents = yes
 
 ;[mark]
 ;secret = mysecret
 
 ;[mark]
 ;secret = mysecret
index 77f74bd..a1ee73b 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -84,6 +84,7 @@ static int enabled = 0;
 static int portno = DEFAULT_MANAGER_PORT;
 static int asock = -1;
 static int displayconnects = 1;
 static int portno = DEFAULT_MANAGER_PORT;
 static int asock = -1;
 static int displayconnects = 1;
+static int timestampevents = 0;
 
 static pthread_t t;
 AST_MUTEX_DEFINE_STATIC(sessionlock);
 
 static pthread_t t;
 AST_MUTEX_DEFINE_STATIC(sessionlock);
@@ -1521,8 +1522,15 @@ int manager_event(int category, char *event, char *fmt, ...)
                        continue;
 
                if (ast_strlen_zero(tmp)) {
                        continue;
 
                if (ast_strlen_zero(tmp)) {
+                       struct timeval now;
+
                        ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n",
                                         event, authority_to_str(category, auth, sizeof(auth)));
                        ast_build_string(&tmp_next, &tmp_left, "Event: %s\r\nPrivilege: %s\r\n",
                                         event, authority_to_str(category, auth, sizeof(auth)));
+                       if (timestampevents) {
+                               now = ast_tvnow();
+                               ast_build_string(&tmp_next, &tmp_left, "Timestamp: %ld.%06lu\r\n",
+                                                now.tv_sec, now.tv_usec);
+                       }
                        va_start(ap, fmt);
                        ast_build_string_va(&tmp_next, &tmp_left, fmt, ap);
                        va_end(ap);
                        va_start(ap, fmt);
                        ast_build_string_va(&tmp_next, &tmp_left, fmt, ap);
                        va_end(ap);
@@ -1704,11 +1712,12 @@ int init_manager(void)
                }
                ast_log(LOG_NOTICE, "Use of portno in manager.conf deprecated.  Please use 'port=%s' instead.\n", val);
        }
                }
                ast_log(LOG_NOTICE, "Use of portno in manager.conf deprecated.  Please use 'port=%s' instead.\n", val);
        }
-       /* Parsing the displayconnects */
-       if ((val = ast_variable_retrieve(cfg, "general", "displayconnects"))) {
-                       displayconnects = ast_true(val);;
-       }
-                               
+
+       if ((val = ast_variable_retrieve(cfg, "general", "displayconnects")))
+               displayconnects = ast_true(val);
+
+       if ((val = ast_variable_retrieve(cfg, "general", "timestampevents")))
+               timestampevents = ast_true(val);
        
        ba.sin_family = AF_INET;
        ba.sin_port = htons(portno);
        
        ba.sin_family = AF_INET;
        ba.sin_port = htons(portno);