svn commit: samba r8590 - in branches/SAMBA_4_0/source/scripting/libjs: .

tridge at samba.org tridge at samba.org
Tue Jul 19 09:30:54 GMT 2005


Author: tridge
Date: 2005-07-19 09:30:53 +0000 (Tue, 19 Jul 2005)
New Revision: 8590

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8590

Log:
added server status utility functions for checking on the status of a task via irpc

- for stream tasks, returns the number of connections

- for non-stream tasks, returns "RUNNING"

For both, return "DISABLED" or "NOT RESPONDING" appropriately

Modified:
   branches/SAMBA_4_0/source/scripting/libjs/base.js
   branches/SAMBA_4_0/source/scripting/libjs/management.js


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/libjs/base.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/base.js	2005-07-19 09:29:30 UTC (rev 8589)
+++ branches/SAMBA_4_0/source/scripting/libjs/base.js	2005-07-19 09:30:53 UTC (rev 8590)
@@ -87,3 +87,14 @@
 	}
 	return join("", list);
 }
+
+/*
+  return "s" if a number should be shown as plural
+*/
+function plural(n)
+{
+	if (n == 1) {
+		return "";
+	}
+	return "s";
+}

Modified: branches/SAMBA_4_0/source/scripting/libjs/management.js
===================================================================
--- branches/SAMBA_4_0/source/scripting/libjs/management.js	2005-07-19 09:29:30 UTC (rev 8589)
+++ branches/SAMBA_4_0/source/scripting/libjs/management.js	2005-07-19 09:30:53 UTC (rev 8590)
@@ -91,3 +91,72 @@
 	}
 	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));
+}



More information about the samba-cvs mailing list