diff --git a/applicationinsights/data-plane/pom.xml b/applicationinsights/data-plane/pom.xml index 08e1408d7e8d..ab91c8f8fa3d 100644 --- a/applicationinsights/data-plane/pom.xml +++ b/applicationinsights/data-plane/pom.xml @@ -76,6 +76,24 @@ + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + + ${project.build.outputDirectory}/maven.properties + + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java index bc6cedbce349..037e31c90b2c 100644 --- a/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java +++ b/applicationinsights/data-plane/src/test/java/com/microsoft/azure/applicationinsights/query/ApplicationInsightsDataClientTests.java @@ -58,6 +58,8 @@ public void canQuery() { public void canGetMetric() { MetricsResult metricResult = applicationInsightsClient.metrics().get(appId, MetricId.AVAILABILITY_RESULTSAVAILABILITY_PERCENTAGE); // Validate properties + Assert.assertNotNull(metricResult.value().additionalProperties()); + System.out.println(metricResult.value().additionalProperties().keySet()); Assert.assertNotNull(metricResult.value().start()); Assert.assertTrue(metricResult.value().start() instanceof DateTime); } @@ -89,8 +91,6 @@ public void canGetMetricsMetadata() { @Test public void canGetEventsByType() { EventsResults eventsResult = applicationInsightsClient.events().getByType(appId, EventType.AVAILABILITY_RESULTS); - System.out.println(eventsResult.value().get(0)); - System.out.println(eventsResult.value().get(0).id()); Assert.assertNotNull(eventsResult.value().get(0).id()); } @@ -100,11 +100,4 @@ public void canGetEvent() { EventsResults eventsResult = applicationInsightsClient.events().get(appId, EventType.AVAILABILITY_RESULTS, eventId); Assert.assertNotNull(eventsResult.value().get(0).id()); } - - @Test - public void canGetEventsOdataMetadata() { - Object metadata = applicationInsightsClient.events().getOdataMetadata(appId); - // Sanity check - Assert.assertNotNull(metadata); - } } \ No newline at end of file diff --git a/loganalytics/data-plane/README.md b/loganalytics/data-plane/README.md new file mode 100644 index 000000000000..aceb30a278e4 --- /dev/null +++ b/loganalytics/data-plane/README.md @@ -0,0 +1,51 @@ +# Azure Log Analytics + +This project provides client tools or utilities in Java that make it easy to query data in [Azure Log Analytics](https://azure.microsoft.com/en-us/services/log-analytics/). For reference documentation on classes and models, please see the [Azure SDK for Java reference](https://docs.microsoft.com/en-us/java/api/overview/azure/?view=azure-java-stable). + +Azure Log Analytics provides agents for telemtry collection and enables deep analytics via a [rich query language](https://docs.loganalytics.io/index). This SDK provides query access to data already stored in Log Analytics. To start collecting data from different sources, take a look at these [quickstarts](https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-quick-collect-azurevm). + +## Examples + +Please see [here](src/main/java/com/microsoft/azure/loganalytics/samples) for code examples using this SDK. + + +## Download + +### Latest release + +To get the binaries of the official Microsoft Azure Log Analytics SDK as distributed by Microsoft, reade for use within your project, you can use Maven. + +```xml + + com.microsoft.azure + azure-loganalytics + LATEST + +``` + +## Prerequisites + +- A Java Developer Kit (JDK), v 1.7 or later +- Maven + +## Help and Issues + +If you encounter any bugs with these SDKs, please file issues via [Issues](https://github.com/Azure/azure-sdk-for-java/issues) or checkout [StackOverflow for Azure Java SDK](http://stackoverflow.com/questions/tagged/azure-java-sdk). + +## Contribute Code + +If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request + +## More information +- [Azure Java SDKs](https://docs.microsoft.com/java/azure/) +- If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212) + +--- + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. \ No newline at end of file diff --git a/loganalytics/data-plane/pom.xml b/loganalytics/data-plane/pom.xml index ee3869964c3d..6e5cba4acf80 100644 --- a/loganalytics/data-plane/pom.xml +++ b/loganalytics/data-plane/pom.xml @@ -76,6 +76,24 @@ + + org.codehaus.mojo + properties-maven-plugin + 1.0.0 + + + generate-resources + + write-project-properties + + + + ${project.build.outputDirectory}/maven.properties + + + + + org.apache.maven.plugins maven-jar-plugin @@ -141,6 +159,9 @@ **/*Tests.java **/*TestCase.java + + **/LogAnalyticsDataClientTests.java + ${testMode} diff --git a/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java b/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java new file mode 100644 index 000000000000..69c0acd3a295 --- /dev/null +++ b/loganalytics/data-plane/src/main/java/com/microsoft/azure/loganalytics/samples/BasicSample.java @@ -0,0 +1,52 @@ +import java.util.List; +import java.util.stream.Collectors; +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.loganalytics.implementation.LogAnalyticsDataClientImpl; +import com.microsoft.azure.loganalytics.models.QueryBody; +import com.microsoft.azure.loganalytics.models.QueryResults; +import com.microsoft.azure.credentials.ApplicationTokenCredentials; + +/** + * Basic query example + * + */ +public class BasicSample +{ + public static void main( String[] args ) + { + // ApplicationTokenCredentials work well for service principal authentication + ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( + "", + "", + "", + AzureEnvironment.AZURE + ); + + // New up client. Accepts credentials, or a pre-authenticated restClient + LogAnalyticsDataClientImpl client = new LogAnalyticsDataClientImpl(credentials); + + // Prepare information for query + String query = "Heartbeat | take 1"; + String workspaceId = ""; + + // Execute! + QueryResults queryResults = client.query(workspaceId, new QueryBody().withQuery(query)); + + // Process and print results + List row = queryResults.tables().get(0).rows().get(0); + List columnNames = queryResults + .tables() + .get(0) + .columns() + .stream() + .map(elt -> elt.name()) + .collect(Collectors.toList()); + + for (int i = 0; i < row.size(); i++){ + System.out.println("The value of " + columnNames.get(i) + " is " + row.get(i)); + } + + return; + } +} +``` \ No newline at end of file