Solved

Check for occurrencies of values into log using Javascript

Posted on 2016-11-29
4
33 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Two decimal 5 41
Prevent certain words from being typed in a form 6 51
XML loaded in a form with dropdown 6 49
Convert complicated date to yyyy-mm-dd format 22 45
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

738 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