grok pattern failure and unable to convert to float using logstash - type-conversion

Trouble converting numbers using grok pattern - text doesn't get converted to float. I have read several articles and now hitting a wall. AIRCRAFTLAT is a field queried from DB. Getting _grokparsefailure now. also the field remains text and not a float
filter {
grok {
match => { "AIRCRAFTLAT" => "%{NUMBER:alat:float}" }
}
}

Thanks Carlo and others - I got it - its the caps - should have been "aircraftlat" no caps for my data - its one of those days... :)

Related

Ionic 4 how to show data time wise

I need help i have list of message in which there are 3 fields. message, uid & time.
Its showing data but its mixed like when we enter data some goes in middle of array some goes in start some in end like this.
But i need to show time wise mean the latest or newest time off array will come first or in end like this. Attach the data format also. This is simply how i am getting message from service
getAllMessages(){
this.messageService.getAllMessages().subscribe((data)=>{
this.data = data;
console.log(this.data);
});
}
You need to use a pipe and map operator for this (map needs to be imported), that will then leverage sort method:
import { map } from 'rxjs/operators';
...
getAllMessages() {
this.messageService.getAllMessages().pipe(
map(messages => messages.sort((a:any, b:any) => b.time.seconds - a.time.seconds)
).subscribe(messages => this.data = messages)
}
I assumed you have seconds already so you do not have to transform date obj of any sort in this example. If it is not the case you can adjust this code accordingly I hope.

Where does a variable in a match arm in a loop come from?

I am trying to implement an HTTP client in Rust using this as a starting point. I was sent to this link by the rust-lang.org site via one of their rust-by-example suggestions in their TcpStream page. I'm figuring out how to read from a TcpStream. I'm trying to follow this code:
fn handle_client(mut stream: TcpStream) {
// read 20 bytes at a time from stream echoing back to stream
loop {
let mut read = [0; 1028];
match stream.read(&mut read) {
Ok(n) => {
if n == 0 {
// connection was closed
break;
}
stream.write(&read[0..n]).unwrap();
}
Err(err) => {
panic!(err);
}
}
}
}
Where does the n variable come from? What exactly is it? The author says it reads 20 bytes at a time; where is this coming from?
I haven't really tried anything yet because I want to understand before I do.
I strongly encourage you to read the documentation for the tools you use. In this case, The match Control Flow Operator from The Rust Programming Language explains what you need to know.
From the Patterns that Bind to Values section:
In the match expression for this code, we add a variable called state to the pattern that matches values of the variant Coin::Quarter. When a Coin::Quarter matches, the state variable will bind to the value of that quarter’s state. Then we can use state in the code for that arm, like so:
fn value_in_cents(coin: Coin) -> u8 {
match coin {
Coin::Penny => 1,
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter(state) => {
println!("State quarter from {:?}!", state);
25
},
}
}
If we were to call value_in_cents(Coin::Quarter(UsState::Alaska)), coin would be Coin::Quarter(UsState::Alaska). When we compare that value with each of the match arms, none of them match until we reach Coin::Quarter(state). At that point, the binding for state will be the value UsState::Alaska. We can then use that binding in the println! expression, thus getting the inner state value out of the Coin enum variant for Quarter.
There is an entire chapter about the pattern matching syntax available and where it can be used.
Figured it out, this is what's happening:
match stream.read(&mut read) {
This line is telling the software to pass stream.read(&mut read) to Ok(n) because stream.read returns the number of bytes read. I'm still not sure why they specify 20 bytes at a time as being read.

Reading numerals with Smartsheet Cell.getValue()

I have a smartsheet from which I'm reading data using Java. One of the columns contains TEXT_NUMBER data with no additional formatting. I'm using Cell.getValue() to fetch the contents of this cell.
My problem is, I do not know a priori what the cell contains - it could contain text, or numbers (whole or decimal fractions). Sometimes the decimal fractions could be like 0.45, in which case Smartsheet internally prepends an apostrophe to the text. This is how I'm reading the text part -
String cellValue = Objects.toString(cell.getValue() != null ? cell.getValue() :
cell.getDisplayValue());
This works very well for textual content, but cell.getValue() returns 0.0 for numbers. I don't know how to get numeric data from the smartsheet. For the moment though, I'm using a little hack -
if ("0.0".equals(cellValue))
return cell.getDisplayValue();
But this will fail down the line, where I'm dealing in Java double and Double parsing.
Please, can someone advise on how to deal with numeric data in Smartsheet Cell? Thanks so much.
Decimals like 0.45 will not have an apostrophe prepended, unless you explicitly set the value as a String.
cell.getValue() will return a Double or String as appropriate. You should check the type of the return before calling toString
Something like
Object value = cell.getValue();
if (value instanceof String) {
String s = (String) value;
}
if (value instanceof Double) {
Double d = (Double) value;
}

Scala - Get files based on name pattern

I would like to filter the files based on some patterns like :
- Team_*.txt (e.g.: Team_Orlando.txt);
- Name.*.City.txt (e.g.: Name.Robert.California.txt);
Or any name (the pattern * . * - it has spaces because was broken my text).
All the filters come from a database table and they are dynamic.
I'm trying to avoid use commands from SO like cp or mv. Is possible to filter files using patterns like the above ?
Here is what i've tried but got a regex error:
def getFiles(dir:File, filter:String) = {
(dir.isDirectory, dir.exists) match {
case (true, true) =>
dir.listFiles.filter(f => f.getName.matches(filter))
case _ =>
Array[File]()
}
}
You can use java.nio Files.newDirectoryStream() for that, it will accept pattern in desired format:
val stream = Files.newDirectoryStream(dir, pattern)
Check http://docs.oracle.com/javase/tutorial/essential/io/dirs.html#glob for detailed description.

iPhone/Objective-C - Searching for a specific word within a string

Is there a way to search for specific words within a string in Objective-C?
Let's say I have the following sentence:
thequickbrownfox
If I wanted to search for "quick" within the sentence. What would be the best way to achieve this?
Thanks for your help.
if ([myString rangeOfString:stringToSearch].location != NSNotFound) {
// stringToSearch is present in myString
}
You can use NSString::rangeOfString for this.
From the docs -
Return Value
An NSRange structure giving the location and length in the receiver of the first occurrence of aString. Returns {NSNotFound, 0} if aString is not found or is empty (#"").