<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[notification on node down status]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm using MyController from about 1 year ago, and I'm adding more and more nodes to my network.<br />
I'd like to receive a notification when one of them is down.<br />
Till now I managed this using the standard rules:<br />
<img src="/assets/uploads/files/1546551592282-4cc9bd57-521b-47c1-a5f7-07e92f791e73-image.png" alt="4cc9bd57-521b-47c1-a5f7-07e92f791e73-image.png" class=" img-fluid img-markdown" /><br />
but it's very annoing to be managed for each new node.<br />
Is there a way to loop thru nodes in a script and the send a pushbullet notification based on the status?<br />
Thank<br />
Daniele</p>
]]></description><link>http://forum.mycontroller.org/topic/386/notification-on-node-down-status</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 07:43:25 GMT</lastBuildDate><atom:link href="http://forum.mycontroller.org/topic/386.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Jan 2019 21:40:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to notification on node down status on Mon, 21 Jan 2019 14:15:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/daniele" aria-label="Profile: Daniele">@<bdi>Daniele</bdi></a> Your code looks super cool and awesome. I just added few HTML template style (you may not like <img src="http://forum.mycontroller.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=49d1c908e56" class="not-responsive emoji emoji-android emoji--wink" style="height:23px;width:auto;vertical-align:middle" title=";)" alt="😉" /> ) and minor tune. Thanks for the awesome code!!</p>
<pre><code class="language-javascript">var myImports = new JavaImporter(java.io, java.lang, java.util,java.lang.Object, org.mycontroller.standalone.utils.McUtils);

with(myImports) {
  var options = new HashMap();
  options.put("orderBy", "Eui");
  options.put("order", "asc");
  options.put("pageLimit", new Long(-1)); // -1 to list all the nodes

  var nodes = mcApi.node().getAll(options);

  var nodesVar = mcApi.variable().get("nodes_state"); // It is good to have key in lowercase and no space
  var nodesOU = JSON.parse(nodesVar.value);
  var nodesOD = JSON.parse(nodesVar.value2);

  var nodesU = [];
  var nodesD = [];

  var subject = "[MyController] Nodes status";
  var tableBody = "";

  for (i = 0; i &lt; nodes.data.length; i++) {

    var nodeStatus = { };
    var _nodeId = nodes.data[i].getId(); // nodeId is unique and internal
    // but still if you want to refer node EUI and gateway id, use the following line and comment above line.
    //var _nodeId = nodes.data[i].getGatewayTable().getId() + '-' + nodes.data[i].getEui();
    var _nodeState = nodes.data[i].getState();
    
    nodeStatus[_nodeId] = _nodeState; // update in to our common map

    if (_nodeState == "UP") {
      nodesU.push(_nodeId);
      var prevState = "";
      for (j = 0; j &lt; nodesOU.length; j++){
        if (nodesOU[j] == _nodeId) prevState = "UP";
      }
      if (prevState != "UP")
        tableBody += "&lt;tr style='color: green;'&gt;&lt;td&gt;" + _nodeId + "&lt;/td&gt;&lt;td&gt;" + nodes.data[i].getName() + "&lt;/td&gt;&lt;td&gt;" + nodes.data[i].getEui() + "&lt;/td&gt;&lt;td&gt;" + _nodeState + "&lt;/td&gt;&lt;td&gt;" + mcApi.utils().friendlyTime(nodes.data[i].getLastSeen()) + "&lt;/td&gt;&lt;/tr&gt;";
    }

    if (_nodeState == "DOWN") {
      nodesD.push(_nodeId);
      var prevState = "";
      for (j = 0; j &lt; nodesOD.length; j++){
        if (nodesOD[j] == nodeId) prevState = "DOWN";
      }
      if (prevState != "DOWN")
        tableBody += "&lt;tr style='color: red;'&gt;&lt;td&gt;" + _nodeId + "&lt;/td&gt;&lt;td&gt;" + nodes.data[i].getName() + "&lt;/td&gt;&lt;td&gt;" + nodes.data[i].getEui() + "&lt;/td&gt;&lt;td&gt;" + _nodeState + "&lt;/td&gt;&lt;td&gt;" + mcApi.utils().friendlyTime(nodes.data[i].getLastSeen()) + "&lt;/td&gt;&lt;/tr&gt;";
    }
  }
  
  if (tableBody.length &gt; 0){
    var pageStart = "Hello,&lt;BR&gt;&lt;BR&gt;";
    var tableStyle = '&lt;table border = "1" cellpadding = "5" style="border-collapse: collapse;border: none;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;th align="left"&gt;Id&lt;/th&gt;&lt;th align="left"&gt;Name&lt;/th&gt;&lt;th align="left"&gt;EUI&lt;/th&gt;&lt;th align="left"&gt;State&lt;/th&gt;&lt;th align="left"&gt;Since&lt;/th&gt;&lt;/tr&gt;';
    var tableEnd = '&lt;/tbody&gt;&lt;/table&gt;';
    var pageEnd = "&lt;BR&gt;&lt;BR&gt;--MyController.org&lt;BR&gt;";
    //  mcApi.operation().sendPushbulletNote(null, "abc@xyz.com", null, subject, message);
    mcApi.operation().sendEmail("abc@xyz.com", subject, pageStart + tableStyle + tableBody + tableEnd + pageEnd);
  }
    
  nodesVar.value = JSON.stringify(nodesU);
  nodesVar.value2 = JSON.stringify(nodesD);
  nodesVar.save();
}
</code></pre>
<p dir="auto">Email will be looking like this,<br />
<img src="/assets/uploads/files/1548079561113-310032a4-3e1b-4191-9c0e-c42d7a1ff5f0-image.png" alt="310032a4-3e1b-4191-9c0e-c42d7a1ff5f0-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>http://forum.mycontroller.org/post/2383</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2383</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Mon, 21 Jan 2019 14:15:19 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Mon, 21 Jan 2019 11:02:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jkandasa" aria-label="Profile: jkandasa">@<bdi>jkandasa</bdi></a> I managed to get the result using a slightly different approach. I saved previous node state in a repository variable, then looped over the nodes list and compared actual state with previous one, sending en email only when state changes.</p>
<p dir="auto">I'm not a java programmer, so any suggestion on the code is more than welcome:</p>
<pre><code>var myImports = new JavaImporter(java.io, java.lang, java.util,java.lang.Object, org.mycontroller.standalone.utils.McUtils);

with(myImports) {
	var options = new HashMap();
	options.put("orderBy", "Eui");
	options.put("order", "asc");
	options.put("pageLimit", new Long(-1)); // -1 to list all the nodes

	var nodes = mcApi.node().getAll(options);

	var nodesVar = mcApi.variable().get("Nodes state");
	var nodesOU = JSON.parse(nodesVar.value);
	var nodesOD = JSON.parse(nodesVar.value2);

	var nodesU = [];
	var nodesD = [];

	var subject = "[MyController] Nodes status";
	var messageU2D = "";
	var messageD2U = "";
	var message = "";

	for (i = 0; i &lt; nodes.data.length; i++) {

		var nodeStatus = new Object();
		nodeStatus['key']   = nodes.data[i].getGatewayTable().getId() + '-' + nodes.data[i].getEui();
		nodeStatus['state'] = nodes.data[i].getState();

		if (nodeStatus['state'] == "UP") {
			nodesU.push(nodeStatus['key']);
			var prevState = "";
			for (j = 0; j &lt; nodesOU.length; j++){
				if (nodesOU[j] == nodeStatus['key']) prevState = "UP";
			}
			if (prevState != "UP")
				messageD2U += nodes.data[i].getEui() + " : " + nodes.data[i].getName() + " : " + mcApi.utils().friendlyTime(nodes.data[i].getLastSeen()) + "&lt;BR&gt;";
		}

		if (nodeStatus['state'] == "DOWN") {
			nodesD.push(nodeStatus['key']);
			var prevState = "";
			for (j = 0; j &lt; nodesOD.length; j++){
				if (nodesOD[j] == nodeStatus['key']) prevState = "DOWN";
			}
			if (prevState != "DOWN")
				messageU2D += nodes.data[i].getEui() + " : " + nodes.data[i].getName() + " : " + mcApi.utils().friendlyTime(nodes.data[i].getLastSeen()) + "&lt;BR&gt;";
		}

	}

	if (messageU2D != ""){
		message += "Nodes DOWN: &lt;BR&gt;";
		message += messageU2D;		
	}

	if (messageD2U != ""){
		message += "Nodes UP: &lt;BR&gt;";
		message += messageD2U;		
	}
	
	if (message != "")
		//  mcApi.operation().sendPushbulletNote(null, "abc@xyz.com", null, subject, message);
		mcApi.operation().sendEmail("abc@xyz.com", subject, message);

	nodesVar.value = JSON.stringify(nodesU);
	nodesVar.value2 = JSON.stringify(nodesD);
	nodesVar.save();
}
</code></pre>
]]></description><link>http://forum.mycontroller.org/post/2378</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2378</guid><dc:creator><![CDATA[Daniele]]></dc:creator><pubDate>Mon, 21 Jan 2019 11:02:33 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Tue, 08 Jan 2019 18:51:26 GMT]]></title><description><![CDATA[<p dir="auto">1.4.0, a snapshot of more or less one month ago</p>
]]></description><link>http://forum.mycontroller.org/post/2369</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2369</guid><dc:creator><![CDATA[Daniele]]></dc:creator><pubDate>Tue, 08 Jan 2019 18:51:26 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Tue, 08 Jan 2019 16:55:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/daniele" aria-label="Profile: Daniele">@<bdi>Daniele</bdi></a> What version of MyController are you using? I will try to come up with a complete solution soon.</p>
]]></description><link>http://forum.mycontroller.org/post/2368</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2368</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Tue, 08 Jan 2019 16:55:53 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Mon, 07 Jan 2019 07:41:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jkandasa" aria-label="Profile: jkandasa">@<bdi>jkandasa</bdi></a> said in <a href="/post/2364">notification on node down status</a>:</p>
<blockquote>
<p dir="auto">put("state", "Down");</p>
</blockquote>
<p dir="auto">I tried, but I still get the same error if I add this line to your script:</p>
<pre><code>var nodes = mcApi.node().getAll(filters);```</code></pre>
]]></description><link>http://forum.mycontroller.org/post/2367</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2367</guid><dc:creator><![CDATA[Daniele]]></dc:creator><pubDate>Mon, 07 Jan 2019 07:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Mon, 07 Jan 2019 05:37:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/daniele" aria-label="Profile: Daniele">@<bdi>Daniele</bdi></a> can you try,</p>
<pre><code>  options.put("state", "Down");
</code></pre>
<p dir="auto">I did some small script, Not complete!</p>
<pre><code class="language-javascript">var myImports = new JavaImporter(java.io, java.lang, java.util, java.text, java.util.HashMap);

with(myImports) {
  // filters
  var filters = new HashMap();
  filters.put("orderBy", "lastSeen");
  filters.put("order", "desc");
  filters.put("state", "Down");  
}
</code></pre>
<p dir="auto">Let me know if you need a complete solution, like how to ignore duplicate, etc.,</p>
]]></description><link>http://forum.mycontroller.org/post/2364</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2364</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Mon, 07 Jan 2019 05:37:58 GMT</pubDate></item><item><title><![CDATA[Reply to notification on node down status on Sun, 06 Jan 2019 17:23:04 GMT]]></title><description><![CDATA[<p dir="auto">I'm following this <a href="https://forum.mycontroller.org/topic/166/help-to-send-email-when-node-goes-down" rel="nofollow ugc">example</a>, changed the notification to pushbullet and added this row to filter only broken nodes:</p>
<pre><code>  options.put("state", "DOWN");
</code></pre>
<p dir="auto">but I receive the error:</p>
<pre><code>  "errorMessage": "java.lang.String cannot be cast to java.lang.Enum"
</code></pre>
<p dir="auto">I'm not a Java programmer, so I'm trying to understand how to use the HashMap looking at the examples I found on your forum.<br />
It's surely a stupid error, but I cannot understand where it is...</p>
<p dir="auto">Thank you for any help<br />
Daniele</p>
]]></description><link>http://forum.mycontroller.org/post/2363</link><guid isPermaLink="true">http://forum.mycontroller.org/post/2363</guid><dc:creator><![CDATA[Daniele]]></dc:creator><pubDate>Sun, 06 Jan 2019 17:23:04 GMT</pubDate></item></channel></rss>