Solved

Check for occurrencies of values into log using Javascript

Posted on 2016-11-29
4
25 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
  • 2
4 Comments
 
LVL 52

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 52

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now