Alarms Tool v2

In this example below you will see how to do a Alarms Tool v2 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by BankSea, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright BankSea ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Alarms Tool v2</title>
  
  
  
  
  
</head>

<body>

  <div>
  <textarea id='alarmsInput'></textarea>
  <p>
    <input onclick='alarmsProcess()' type='submit'>
  </p>
</div>
<div class='table' id='table'></div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/BankSea/alarms-tool-v2-ZJvpOE */
/*global $, jQuery*/
function alarmsProcess() {
  "use strict";
  var Alarms = {}, JSONAlarms = {};
  function josnifyAlarms() {
    JSONAlarms = $("#alarmsInput").val().split(/\n/);
    for (var i = 0; i < JSONAlarms.length; ++i) {
      var alarm = { owner: "", item: "", time: "" };
      JSONAlarms[i] = JSONAlarms[i].split(/\t/);
      alarm.owner = JSONAlarms[i][2];
      alarm.item = JSONAlarms[i][4];
      alarm.time = JSONAlarms[i][5].slice(11, 16);
      JSONAlarms[i] = alarm;
    }
  }
  function defineAlarms() {
    var upOrDown = /Node Unreachable Alert|Connectivity Restored/;
    var ccm = /\d+[A-Za-z]+/;
    var ccmid = /\d+[A-Za-z]+\d+/;
    var ip = /\d+\.\d+\.\d+\.\d+/;
    var splitItem = [];
    for (var i = 0; i < JSONAlarms.length; ++i) {
      if (upOrDown.test(JSONAlarms[i].item)) {
        if (/Node Unreachable/.test(JSONAlarms[i].item)) {
          JSONAlarms[i].type = "Node Down";
          splitItem = JSONAlarms[i].item.split(/Alert: | is Down - /);
        }
        if (/Connectivity Restored/.test(JSONAlarms[i].item)) {
          JSONAlarms[i].type = "Node Up";
          splitItem = JSONAlarms[i].item.split(/Reset: | is Up /);
        }
        JSONAlarms[i].node = splitItem[1];
        JSONAlarms[i].ip = splitItem[2];
        delete JSONAlarms[i].item;
      } else if (/Device reloaded/.test(JSONAlarms[i].item)) {
        JSONAlarms[i].type = "Reload";
        JSONAlarms[i].node = JSONAlarms[i].item.split(
          /M ET |[ ]\d+\.\d+\.\d+\.\d+/
        )[1];
        JSONAlarms[i].ip = JSONAlarms[i].item.match(ip)[0];
        delete JSONAlarms[i].item;
      } else {
      }
      if (JSONAlarms[i].node !== undefined) {
        JSONAlarms[i].ccm = JSONAlarms[i].node.match(ccm)[0];
        if (ccmid.test(JSONAlarms[i].node)) {
          JSONAlarms[i].ccmid = JSONAlarms[i].node.match(ccmid)[0];
        }
      }
    }
  }
  function defineEvents() {
    var events = {};
    var eventCCMIDs = [];
    for (var i = 0; i < JSONAlarms.length; i++) {
      if (typeof JSONAlarms[i].ccmid !== "undefined" && eventCCMIDs.includes(JSONAlarms[i].ccmid) == !1) {
        eventCCMIDs.push(JSONAlarms[i].ccmid);
      }
    }
    for (var i=0; i<eventCCMIDs.length; i++) {
      //var event = { type: "", severity: "", age: "", alarms: [] };
      events[eventCCMIDs[i]] = {alarms: []}
    }
    for (var i = 0; i < JSONAlarms.length; i++) {
      if (typeof JSONAlarms[i].ccmid !== "undefined") {
        events[(JSONAlarms[i].ccmid)].alarms.push(JSONAlarms[i])
      }
    }
		
	console.log(events)
  }
  // call functions
  josnifyAlarms();
  defineAlarms();
  defineEvents();
  console.log(JSONAlarms)
}

Comments