[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Check for occurrencies of values into log using Javascript

Posted on 2016-11-29
4
Medium Priority
?
38 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 59

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 2000 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 59

Expert Comment

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

650 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