r8590: added server status utility functions for checking on the status of a task...
authorAndrew Tridgell <tridge@samba.org>
Tue, 19 Jul 2005 09:30:53 +0000 (09:30 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:29:42 +0000 (13:29 -0500)
- for stream tasks, returns the number of connections

- for non-stream tasks, returns "RUNNING"

For both, return "DISABLED" or "NOT RESPONDING" appropriately
(This used to be commit 78d6303814382f7835212f5045f12180e396b540)

source4/scripting/libjs/base.js
source4/scripting/libjs/management.js

index 181b3ca95900715111aaf20352933b3c890a0e87..39b62b133e8b21363c67921eff8aee718813c0ec 100644 (file)
@@ -87,3 +87,14 @@ function substitute_var(str, subobj)
        }
        return join("", list);
 }
+
+/*
+  return "s" if a number should be shown as plural
+*/
+function plural(n)
+{
+       if (n == 1) {
+               return "";
+       }
+       return "s";
+}
index 8b042472484afe86e77291e67affec6090935471..7130cdc5dd09b6b606179f52dd9b6f79de488ec0 100644 (file)
@@ -91,3 +91,72 @@ function nbtd_statistics()
        }
        return io.results[0].info.stats;
 }
+
+/*
+  see if a service is enabled
+*/
+function service_enabled(name)
+{
+       var services = lpGet("server services");
+       var i;
+       for (i=0;i<services.length;i++) {
+               if (services[i] == name) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+/*
+  show status of a server
+*/
+function server_status(name)
+{
+       var conn = new Object();
+       var i;
+       var io;
+       var irpc = irpc_init();
+
+       if (!service_enabled(name)) {
+               return "DISABLED";
+       }
+       
+       status = irpc_connect(conn, name + "_server");
+       if (status.is_ok != true) {
+               return "DOWN";
+       }
+
+       var io = irpcObj();
+       status = irpc.irpc_uptime(conn, io);
+       if (status.is_ok != true) {
+               return "NOT RESPONDING";
+       }
+
+       return "RUNNING";
+}
+
+/*
+  show status of a stream server
+*/
+function stream_server_status(name)
+{
+       var conn = new Object();
+       var irpc = irpc_init();
+
+       if (!service_enabled(name)) {
+               return "DISABLED";
+       }
+       status = irpc_connect(conn, name + "_server");
+       if (status.is_ok != true) {
+               return "0 connections";
+       }
+
+       var io = irpcObj();
+       status = irpc.irpc_uptime(conn, io);
+       if (status.is_ok != true) {
+               return "NOT RESPONDING";
+       }
+
+       var n = io.results.length;
+       return sprintf("%u connection%s", n, plural(n));
+}