Skip to content

Commit

Permalink
added input params
Browse files Browse the repository at this point in the history
  • Loading branch information
pvighi committed Aug 28, 2018
1 parent fa23a5a commit f992ce8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,36 @@ object Handler extends Logging {

def runWithEffects(lambdaIO: LambdaIO, stage: Stage, fetchString: StringFromS3): ApiGatewayOp[Operation] = {


ContinueProcessing(
Operation.noHealthcheck(operation)
)
}

def operation(apiGatewayRequest: ApiGatewayRequest) = {

val filterPattern = apiGatewayRequest.queryStringParameters.flatMap(_.get("filterPattern")).get
val minutesAgo = apiGatewayRequest.queryStringParameters.flatMap(_.get("minutesAgo")).getOrElse("60").toInt

val logClient = AWSLogsClientBuilder
.standard()
.withCredentials(aws.CredentialsProvider)
.withRegion(Regions.EU_WEST_1)
.build()

val now = ZonedDateTime.now(ZoneOffset.UTC)
val start = now.minusHours(2).toEpochSecond * 1000

println(s"now is ${now.toEpochSecond}")
val start = now.minusMinutes(minutesAgo).toEpochSecond * 1000
val req = new FilterLogEventsRequest()
.withLogGroupName("membership-workflow-CODE")

.withStartTime(start)
.withEndTime(now.toEpochSecond * 1000)
.withFilterPattern("0032500000wzY0N ERROR")
.withFilterPattern(filterPattern)

val res = logClient.filterLogEvents(req)

val result = ResponseWire.fromEvents(res.getEvents.asScala.toList)

ContinueProcessing(
Operation.noHealthcheck {
Req: ApiGatewayRequest => ApiGatewayResponse(body = result, statusCode = "200")
}
)
ApiGatewayResponse(body = result, statusCode = "200")
}
}

Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package com.gu.newproduct.api.syncerrors

import java.io.{ByteArrayInputStream, ByteArrayOutputStream}
import java.time.{ZoneOffset, ZonedDateTime}

import com.amazonaws.regions.{Region, Regions}
import com.amazonaws.services.logs.model.{FilterLogEventsRequest, GetLogEventsRequest}
import com.amazonaws.services.logs.{AWSLogsClient, AWSLogsClientBuilder}
import com.gu.effects.aws
import play.api.libs.json.{JsString, Json}
import scala.collection.JavaConverters._

//This is just a way to locally run the addSubscription lambda in dev
object SyncErrorsManualTest extends App {
val requestBody =
val requestText =
"""{
|"queryStringParameters" : {
| "filterPattern" : "0032500000x0D9b ERROR",
| "minutesAgo" : "60"
| }
|}
""".stripMargin

val bodyAsJsString = JsString(requestBody)
case class ApiRequest(body: String)
implicit val writes = Json.writes[ApiRequest]
val requestText = Json.prettyPrint(Json.toJson(ApiRequest(requestBody)))

println(s"sending request..")
println(requestText)

Expand Down

0 comments on commit f992ce8

Please sign in to comment.