summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/libjs/base.js11
-rw-r--r--source4/scripting/libjs/management.js69
2 files changed, 80 insertions, 0 deletions
diff --git a/source4/scripting/libjs/base.js b/source4/scripting/libjs/base.js
index 181b3ca959..39b62b133e 100644
--- a/source4/scripting/libjs/base.js
+++ b/source4/scripting/libjs/base.js
@@ -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";
+}
diff --git a/source4/scripting/libjs/management.js b/source4/scripting/libjs/management.js
index 8b04247248..7130cdc5dd 100644
--- a/source4/scripting/libjs/management.js
+++ b/source4/scripting/libjs/management.js
@@ -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));
+}