Solved

Check for occurrencies of values into log using Javascript

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

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 51

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now