forked from spinnaker/gate
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d5b886
commit 786064c
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/SplunkLogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.netflix.spinnaker.gate.controllers; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/splunk") | ||
@ConditionalOnProperty("splunk.log.enabled") | ||
public class SplunkLogController { | ||
private static final Logger log = LoggerFactory.getLogger(SplunkLogController.class); | ||
|
||
// Sample baseURL = https://hostURL?paramsKey=paramsValue&index=CLUSTER_NAME%20pod=POD_NAME | ||
@Value("${splunk.log.baseURL}") | ||
private String baseURL; | ||
|
||
@Value("${splunk.log.clusterName}") | ||
private String clusterName; | ||
|
||
@ApiOperation("Retrieve splunk logs") | ||
@GetMapping("/logs/{podName}") | ||
public ResponseEntity<byte[]> getSplunkLogs(@PathVariable("podName") String podName) | ||
throws IOException { | ||
String logUrl = baseURL.replace("CLUSTER_NAME", clusterName).replace("POD_NAME", podName); | ||
log.info("Inside SplunkLogController - getSplunkLogs(), splunk Log URL : " + logUrl); | ||
|
||
try (InputStream in = new URL(logUrl).openStream()) { | ||
byte[] fileContents = in.readAllBytes(); | ||
return ResponseEntity.ok() | ||
.header("Content-Disposition", "attachment; filename=log.zip") | ||
.body(fileContents); | ||
} | ||
} | ||
} |