Solved

Check for occurrencies of values into log using Javascript

Posted on 2016-11-29
4
34 Views
Last Modified: 2016-11-29
Hi all,

I have the following log:

Name   Index Model         Serial-Number Power-Feed State   Connectivity-State Enabled-State Input Battery-Charge BBU-Load Voltage FW-Version Part-Number Brick-Name Index Cluster-Name Index
X1-XXX 1     Xxxxx 5X 9999 X999X99999    XXX-A      healthy connected          enabled       on    80             21       231     02.08.0016 999-999-999 X1         1     xxxxxxxx09   1    
X2-XXX 2     Xxxxx 5X 9999 X999X99999    XXX-B      healthy connected          enabled       on    100            22       232     02.08.0016 999-999-999 X2         2     xxxxxxxx09   1    

Open in new window


And I'd need to check if in the log I always have the good values: healthy, connected, more than 80 battery-charge and more than 230 voltage.

Probably a simple count would be fine because the 4 values always have to be there.

How can I do this in Javascript?
0
Comment
Question by:ltpitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41905735
Where is the log data?
0
 
LVL 1

Author Comment

by:ltpitt
ID: 41905742
Hi Julian!

You can find it in my question above.

Try this link if you cannot view it:
https://www.experts-exchange.com/viewCodeSnippet.jsp?codeSnippetId=10-28986076-1
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41905817
Somethign like that :

var log = "Name   Index Model         Serial-Number Power-Feed State   Connectivity-State Enabled-State Input Battery-Charge BBU-Load Voltage FW-Version Part-Number Brick-Name Index Cluster-Name Index\nX1-XXX 1     Xxxxx 5X 9999 X999X99999    XXX-A      healthy connected          enabled       on    80             21       231     02.08.0016 999-999-999 X1         1     xxxxxxxx09   1    \nX2-XXX 2     Xxxxx 5X 9999 X999X99999    XXX-B      healthy connected          enabled       on    100            22       232     02.08.0016 999-999-999 X2         2     xxxxxxxx09   1    \n";
var lines = str.split("\n");
for(var i=1;i<lines.length;i++) { 
    var name = str.split("\n")[1].substr(0,7).replace(/^\s|\s$/g,"");
     var status = str.split("\n")[i].substr(52,8).replace(/^\s|\s$/g,"");
     var connected = str.split("\n")[1].substr(60,19).replace(/^\s|\s$/g,"");
     var battery = str.split("\n")[1].substr(99,15) * 1;
     var voltage = str.split("\n")[1].substr(123,8) * 1;
     if( status == "healthy" && connected = "connected" && battery>=80 && voltage >= 230) {
            alert("good");
            // do something or nothing when good
     }
     else {
            alert("error with machine : " + name);
            // do something or nothing when error
     }
}

Open in new window

0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41905879
No I meant - where does it live - how does the JavaScript access it?
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question