Skip to content

Commit

Permalink
Merge pull request #56 from AakashKhopade/EndpointChange
Browse files Browse the repository at this point in the history
Updated LogLevel field
  • Loading branch information
AakashKhopade authored Jan 24, 2025
2 parents 364caf9 + 395ceff commit 746d2e5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 43 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Add the package dependencies to your build.gradle or pom.xml

```groovy
dependencies {
implementation('com.logicmonitor:lm-data-sdk:0.0.1-alpha')
implementation('com.logicmonitor:lm-data-sdk:0.0.6-alpha')
}
```

Expand All @@ -40,20 +40,22 @@ dependencies {
<dependency>
<groupId>com.logicmonitor</groupId>
<artifactId>lm-data-sdk</artifactId>
<version>0.0.1-alpha</version>
<version>0.0.6-alpha</version>
</dependency>
```
### Set Configurations
SDK must be configured with LogicMonitor.DataSDK Configuration class. While using LMv1 authentication set LM_ACCESS_ID and
LM_ACCESS_KEY properties, In Case of BearerToken Authentication set LM_BEARER_TOKEN property. Company's name or Account
name <b>must</b> be passed to LM_COMPANY property. All properties can be set using environment variable.

| Environment variable | Description |
|-------------|:------|
| `LM_COMPANY` | Account name (Company Name) is your organization name |
| `LM_ACCESS_ID` | Access id while using LMv1 authentication. |
| `LM_ACCESS_KEY` | Access key while using LMv1 authentication. |
| `LM_BEARER_TOKEN` | BearerToken while using Bearer authentication.|
| Environment variable | Description |
|----------------------|:------------------------------------------------------|
| `LM_COMPANY` | Account name (Company Name) is your organization name |
| `LM_ACCESS_ID` | Access id while using LMv1 authentication. |
| `LM_ACCESS_KEY` | Access key while using LMv1 authentication. |
| `LM_BEARER_TOKEN` | BearerToken while using Bearer authentication. |
| `LM_DOMAIN_NAME` | Configure custom endpoint |


### Read the [Library Documentation](https://logicmonitor.github.io/lm-data-sdk-java/) to use Metrics/Logs ingestion API.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {
}

group = 'com.logicmonitor'
version = '0.0.5-alpha'
version = '0.0.6-alpha'
java.sourceCompatibility = JavaVersion.VERSION_1_8


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected static ApiResponse singleRequest(final LogsInput logsV1)
body.put("message", logsV1.getMessage());
body.put("_lm.resourceId", logsV1.getResourceId());
body.put("timestamp", logsV1.getTimeStamp());
body.put("log_level",logsV1.getLogLevel());
if (logsV1.getMetadata() != null) {
for (Map.Entry<String, String> entry : logsV1.getMetadata().entrySet()) {
body.put(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -145,14 +146,15 @@ protected void doRequest() {
*/
public Optional<ApiResponse> sendLogs(
final String message,
final String logLevel,
final Map<String, String> resourceId,
final Map<String, String> metadata,
long timeStamp)
throws IOException, ApiException {
if (timeStamp == 0L) {
timeStamp = Instant.now().toEpochMilli();
}
final LogsInput logsV1 = new LogsInput(message, resourceId, Long.toString(timeStamp), metadata);
final LogsInput logsV1 = new LogsInput(message, logLevel, resourceId, Long.toString(timeStamp), metadata);

if (batch) {
addRequest(logsV1);
Expand All @@ -170,6 +172,7 @@ private List<Map<String, Object>> createBody() {
body.put("message", logsV1.getMessage());
body.put("_lm.resourceId", logsV1.getResourceId());
body.put("timestamp", logsV1.getTimeStamp());
body.put("log_level",logsV1.getLogLevel());
if (logsV1.getMetadata() != null) {
for (Map.Entry<String, String> entry : logsV1.getMetadata().entrySet()) {
body.put(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class LogsInput implements Input {

private String message;
private String logLevel;
private Map<String, String> resourceId;
private String timeStamp;
private Map<String, String> metadata;
Expand Down
56 changes: 29 additions & 27 deletions data-sdk/src/test/java/com/logicmonitor/sdk/data/api/TestLogs.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
implementation 'org.projectlombok:lombok:1.18.26'
compileOnly 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok:1.18.26'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.16'
}

description = 'examples'
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public static void main(final String[] args) throws InterruptedException {
final Logs logs = new Logs(conf, 10, false, responseInterface);
while (true) {
try {
Optional<ApiResponse> response = logs.sendLogs("Testing log Api", resourceIds, null,0L);
Optional<ApiResponse> response = logs.sendLogs("Testing log Api","WARN", resourceIds, null,0L);
if (response != null && response.isPresent()) {
log.debug(
"Response: Status: " + response.get().getStatusCode() + " Headers: "
"Response: Status: " + response.get().getStatusCode() + " Headers: "
+ response.get().getHeaders() + " Data: " + response.get().getData());
}
response = logs.sendLogs("Testing log Api second call", resourceIds,
null,1674036943L);
response = logs.sendLogs("Testing log Api second call","ERROR", resourceIds,
null,0L);
if (response != null && response.isPresent()) {
log.debug("Response: Status: " + response.get().getStatusCode() + " Headers: "
+ response.get().getHeaders() + " Data: " + response.get().getData());
+ response.get().getHeaders() + " Data: " + response.get().getData());
}
} catch (final ApiException | IOException e) {
log.error("Exception while sending logs.", e);
Expand Down

0 comments on commit 746d2e5

Please sign in to comment.