Send data to OMS Log Analytics with Java code

Here is an example how to send data to OMS Log Analytics directly from your Java code. To get more information how to change the variables and how to see the data in OMS please see the blog post where I do the same in bash and curl – blog post: Send data to OMS Log Analytics with Curl from a Linux server.



2 Responses to Send data to OMS Log Analytics with Java code

  1. Stan October 5, 2017 at 21:20 #

    Thanks for the sample code, very helpful.

    One issue using it is the Date formatting for the timeNow string is not good enough for users that are not in GMT as local timezone. I changed that code to :

    String timeNow = String.format(“%ta, %<td %<tb %<tY %<tT GMT", date );

    Should be:
    SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM YYYY HH:mm:ss zzz");
    String timeNow = sdf.format(date);

    It appears that Azure is not happy with:
    1) times that are older than 15 minutes ago
    2) time zones that are not GMT (PDT in specific)
    If the time is not correct, the call returns a 403 error.

    • Jonathan January 5, 2018 at 14:17 #

      Perfect! Thank you for your help to fix this. You are totally correct.

Leave a Reply