You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2014/01/31 00:31:16 UTC

[03/12] git commit: TS-2533 Add three commands previously provided by traffic_shell.

TS-2533 Add three commands previously provided by traffic_shell.

This adds the following command line options:

     --alarms        Show all alarms currently active (show:alarms)
     --status	     Show the current proxy server status (show:status)
     -- clear_alarms Clear selected alarms. Arguments are the name string,
                     the event number, or the string "all".


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/8c47c09a
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/8c47c09a
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/8c47c09a

Branch: refs/heads/5.0.x
Commit: 8c47c09a47e5472b616d7dc2681ea6f0978491b5
Parents: dff82e3
Author: Leif Hedstrom <zw...@apache.org>
Authored: Mon Jan 27 10:29:35 2014 -0700
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Mon Jan 27 14:51:57 2014 -0700

----------------------------------------------------------------------
 CHANGES                                    |  2 +
 cmd/traffic_line/traffic_line.cc           | 91 +++++++++++++++++++++++++
 doc/reference/commands/traffic_line.en.rst | 15 ++++
 3 files changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8c47c09a/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index f1802a4..325773f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 4.2.0
 
+  *) [TS-2533 ] Add three commands previously provided by traffic_shell.
+
   *) [TS-2304] Make the healthcheck plugin watch for file permission changes.
 
   *) [TS-2519] Make build version metrics non-persistent.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8c47c09a/cmd/traffic_line/traffic_line.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_line/traffic_line.cc b/cmd/traffic_line/traffic_line.cc
index f25c95d..0e25105 100644
--- a/cmd/traffic_line/traffic_line.cc
+++ b/cmd/traffic_line/traffic_line.cc
@@ -47,6 +47,9 @@ static int ClearNode;
 static char ZeroCluster[1024];
 static char ZeroNode[1024];
 static char StorageCmdOffline[1024];
+static int ShowAlarms;
+static int ShowStatus;
+static char ClearAlarms[1024];
 static int VersionFlag;
 
 static TSError
@@ -74,6 +77,7 @@ handleArgInvocation()
     TSError err;
     TSRecordEle *rec_ele = TSRecordEleCreate();
     char *name = *ZeroNode ? ZeroNode : ZeroCluster;
+
     if ((err = TSRecordGet(name, rec_ele)) != TS_ERR_OKAY) {
       fprintf(stderr, "%s: %s\n", programName, TSGetErrorMessage(err));
       TSRecordEleDestroy(rec_ele);
@@ -87,6 +91,87 @@ handleArgInvocation()
     return TS_ERR_FAIL;
   } else if (*StorageCmdOffline) {
     return TSStorageDeviceCmdOffline(StorageCmdOffline);
+  } else if (ShowAlarms == 1) {
+    // Show all active alarms, this was moved from the old traffic_shell implementation (show:alarms).
+    TSList events = TSListCreate();
+
+    if (TS_ERR_OKAY != TSActiveEventGetMlt(events)) {
+      TSListDestroy(events);
+      fprintf(stderr, "Error Retrieving Alarm List\n");
+      return TS_ERR_FAIL;
+    }
+
+    int count = TSListLen(events);
+
+    if (count > 0) {
+      printf("Active Alarms\n");
+      for (int i = 0; i < count; i++) {
+        char* name = static_cast<char *>(TSListDequeue(events));
+        printf("  %d. %s\n", i + 1, name);
+      }
+    } else {
+      printf("\nNo active alarms.\n");
+    }
+    TSListDestroy(events);
+    return TS_ERR_OKAY;
+  } else if (*ClearAlarms != '\0') {
+    // Clear (some) active alarms, this was moved from the old traffic_shell implementation (config:alarm)
+    TSList events = TSListCreate();
+    size_t len = strlen(ClearAlarms);
+
+    if (TS_ERR_OKAY != TSActiveEventGetMlt(events)) {
+      TSListDestroy(events);
+      fprintf(stderr, "Error Retrieving Alarm List\n");
+      return TS_ERR_FAIL;
+    }
+
+    int count = TSListLen(events);
+
+    if (count == 0) {
+      printf("No Alarms to resolve\n");
+      TSListDestroy(events);
+      return TS_ERR_OKAY;
+    }
+
+    int errors = 0;
+    bool all = false;
+    int num = -1;
+
+    if ((3 == len) && (0 == strncasecmp(ClearAlarms, "all", len))) {
+      all = true;
+    } else  {
+      num = strtol(ClearAlarms, NULL, 10) - 1;
+      if (num <= 0)
+        num = -1;
+    }
+
+    for (int i = 0; i < count; i++) {
+      char* name = static_cast<char*>(TSListDequeue(events));
+
+      if (all || ((num > -1) && (num == i)) || ((strlen(name) == len) && (0 == strncasecmp(ClearAlarms, name, len)))) {
+        if (TS_ERR_OKAY != TSEventResolve(name)) {
+          fprintf(stderr, "Errur: Unable to resolve alarm %s\n", name);
+          ++errors;
+        }
+        if (num > 0) // If a specific event number was specified, we can stop now
+          break;
+      }
+    }
+    TSListDestroy(events);
+    return (errors > 0 ? TS_ERR_FAIL: TS_ERR_OKAY);
+  } else if (ShowStatus == 1) {
+    switch (TSProxyStateGet()) {
+    case TS_PROXY_ON:
+      printf("Proxy -- on\n");
+      break;
+    case TS_PROXY_OFF:
+      printf("Proxy -- off\n");
+      break;
+    case TS_PROXY_UNDEFINED:
+      printf("Proxy status undefined\n");
+      break;
+    }
+    return TS_ERR_OKAY;
   } else if (*ReadVar != '\0') {        // Handle a value read
     if (*SetVar != '\0' || *VarValue != '\0') {
       fprintf(stderr, "%s: Invalid Argument Combination: Can not read and set values at the same time\n", programName);
@@ -166,6 +251,9 @@ main(int /* argc ATS_UNUSED */, char **argv)
   ZeroNode[0] = '\0';
   VersionFlag = 0;
   *StorageCmdOffline = 0;
+  ShowAlarms = 0;
+  ShowStatus = 0;
+  ClearAlarms[0] = '\0';
 
   // build the application information structure
   appVersionInfo.setup(PACKAGE_NAME,"traffic_line", PACKAGE_VERSION, __DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
@@ -190,6 +278,9 @@ main(int /* argc ATS_UNUSED */, char **argv)
     {"zero_cluster", 'Z', "Zero Specific Statistic (cluster wide)", "S1024", &ZeroCluster, NULL, NULL},
     {"zero_node", 'z', "Zero Specific Statistic (local node)", "S1024", &ZeroNode, NULL, NULL},
     {"offline", '-', "Mark cache storage offline", "S1024", &StorageCmdOffline, NULL, NULL},
+    {"alarms", '-', "Show all alarms", "F", &ShowAlarms, NULL, NULL},
+    {"clear_alarms", '-', "Clear specified, or all,  alarms", "S1024", &ClearAlarms, NULL, NULL},
+    {"status", '-', "Show proxy server status", "F", &ShowStatus, NULL, NULL},
     {"version", 'V', "Print Version Id", "T", &VersionFlag, NULL, NULL},
   };
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8c47c09a/doc/reference/commands/traffic_line.en.rst
----------------------------------------------------------------------
diff --git a/doc/reference/commands/traffic_line.en.rst b/doc/reference/commands/traffic_line.en.rst
index 213cd40..8f8425b 100644
--- a/doc/reference/commands/traffic_line.en.rst
+++ b/doc/reference/commands/traffic_line.en.rst
@@ -120,6 +120,21 @@ Options
    used this storage to other storage. This has exactly the same effect as a disk failure for that storage. This does
    not persist across restarts of the :program:`traffic_server` process.
 
+.. option:: --alarms
+
+   List all alarm events that have not been acknowledged (cleared).
+
+.. option:: --clear_alarms [all | #event | name]
+
+   Clear (acknowledge) an alarm event. The arguments are "all" for all current
+   alarms, a specific alarm number (e.g. ''1''), or an alarm string identifier
+   (e.g. ''MGMT_ALARM_PROXY_CONFIG_ERROR'').
+
+.. option:: --status
+
+   Show the current proxy server status, indicating if we're running or not.
+
+
 .. traffic-line-performance-statistics
 
 Performance Statistics