Highlighted
akshayinnamuri Absent Member.
Absent Member.
1850 views

Timestamp issue -unable to parse the time format


Developing a log file flex connector where in we have a timestamp format 2014-01-25 20:35:33 11:00

when tokenizing time to yyyy-mm-dd hh:mm:ss z for (2014-01-25 20:35:33 11:00) its not getting parsed.

kindly advise if anyone encountered these kind of issue

Labels (2)
Tags (1)
0 Likes
11 Replies
Acclaimed Contributor.. lless Acclaimed Contributor..
Acclaimed Contributor..

Re: Timestamp issue -unable to parse the time format

try yyyy-mm-dd hh:mm:ss ZZ:ZZ

0 Likes
akshayinnamuri Absent Member.
Absent Member.

Re: Timestamp issue -unable to parse the time format

Tried but its unsuccesfull.

0 Likes
Acclaimed Contributor.. lless Acclaimed Contributor..
Acclaimed Contributor..

Re: Timestamp issue -unable to parse the time format

You may use date without 11:00.

Only yyyy-mm-dd hh:mm:ss and correct time zone on connector config.

0 Likes
asheesh.y.kumar Absent Member.
Absent Member.

Re: Timestamp issue -unable to parse the time format

regex: \\d{4}\\-\\d{2}-\\d{2} \\d{2}\:\\d{2}\:\\d{2} \\d{2}\:\\d{2}

format: yyyy-MM-dd HH\:mm\:ss ZZ\:ZZ

it will work

There's a easy way also, if you tell me what's next after time. Or give a sample log

0 Likes
Acclaimed Contributor.. lless Acclaimed Contributor..
Acclaimed Contributor..

Re: Timestamp issue -unable to parse the time format

This regex or token.format for TimeStamp?

0 Likes
asheesh.y.kumar Absent Member.
Absent Member.

Re: Timestamp issue -unable to parse the time format

regex: \\d{4}\\-\\d{2}-\\d{2} \\d{2}\:\\d{2}\:\\d{2} \\d{2}\:\\d{2}

format: yyyy-MM-dd HH\:mm\:ss ZZ\:ZZ

0 Likes
asheesh.y.kumar Absent Member.
Absent Member.

Re: Timestamp issue -unable to parse the time format

Akshay,

Have you tried this ? Let us know.

Thanks

0 Likes
akshayinnamuri Absent Member.
Absent Member.

Re: Timestamp issue -unable to parse the time format

Sorry for delayed response.

I tried without giving any timezone parameter i.e. yyyy-mm-dd hh:mm:ss connector was able to load the log file and parse.

only question came is I have logs from two different countries say example x and y which time zone on connector config I need to configure with and to which parameter of Agent.properties file.


Thanks in advance

0 Likes
Honored Contributor.. DanyK7 Honored Contributor..
Honored Contributor..

Re: Timestamp issue -unable to parse the time format

If you are receiving from 2 devices in 2 different time zones AND you are not parsing the time zone information in the timestamp, you simply won't be able to parse the logs properly. No keywords can help you in the agent.properties

Your choices are:

1) Install 2 smarts, one in timezone X and the other in timezone Y

2) Have both sources use the UTC timezone (best solution - most often impractical)

3) Figure out how to parse the timezone in the timestamp, provided it is always there

Also, should you want to change the timezone in the agent.properties to have an Smart in a différent timezone from the system where it is install, my recommendation is DONT.

Change the startup script so that the TZ environment variable is passed to the SmartConnector process, setting it in a different timezone than the system's default.

Best regards,

0 Likes
nils.guenther@t Honored Contributor.
Honored Contributor.

Re: Timestamp issue -unable to parse the time format

Parsing of timestamp strings is backed by Java's SimpleDateFormat class (look here http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html).

While extremely flexible when dealing with the actual date/time-values it is very picky with the timezone string. See the link for valid formats. To work around this limitation, build a regex that captures your timestamp string into several tokens, then use funtion __concatenate to build a string that has a valid timezone part. Hand that over to date parsing function of your choice with appropriate format string.

To give you an example:

# 2014-01-25 20:35:33 11:00

regex=(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (\\d{2}:\\d{2})

token[0].name=DATETIME

token[1].name=TIMEZONE

event.deviceCustomDate1=__safeToDate(__concatenate(DATETIME," GMT+",TIMEZONE),"yyyy-MM-dd HH:mm:ss z")

That should do the trick.

0 Likes
Honored Contributor.. DanyK7 Honored Contributor..
Honored Contributor..

Re: Timestamp issue -unable to parse the time format

I agree with Nils, timezone are a p* to parse.

I modified a program found of the web.

Might help you create a valid timestamp format and test it outside of

The only difference with this and ___createOptionnalTimeStampFromString function is that in the latter, you can't use single quotes to express fixed text string.

Beside that, this allowed to me create valid time format string and test them beforehand.

For example,

event.endTime=__createOptionalTimeStampFromString(TS,"yyyy-MM-ddTHH:mm:ss.SSSX")

The program. Just play with the format in bold.

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.text.ParseException;

import java.util.Date;

import java.io.IOException;

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class DateFormatExample3 {

    public static void main(String[] args) {

        

       // Make a SimpleDateFormat

        SimpleDateFormat format =

            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");

       

        // Read and parse input, stopping on a blank input line

        BufferedReader reader =

            new BufferedReader(new InputStreamReader(System.in));

        try {

            System.out.print("ENTER DATE STRING TO PARSE: ");

          

            String MydateString = reader.readLine();

                try {

                    Date date = format.parse(MydateString);

                    System.out.println("Original string: " + MydateString);

                    System.out.println("Parsed date    : " +

                        date.toString());

                    System.out.println(); // Skip a line

                }

                catch(ParseException pe) {

                    System.out.println(

                        "ERROR: could not parse date in string \"" +

                        MydateString + "\"");

                }

        }

        catch(IOException ioe) {

            System.out.println("I/O Exception: " + ioe);

        }

    }

}

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.