Skip to content

Instantly share code, notes, and snippets.

@Storager
Last active December 20, 2023 12:55
Show Gist options
  • Select an option

  • Save Storager/2f026a90948ef8b43340c16affb89cb3 to your computer and use it in GitHub Desktop.

Select an option

Save Storager/2f026a90948ef8b43340c16affb89cb3 to your computer and use it in GitHub Desktop.
Gist description
package org.zoo
import java.time.*
import java.time.format.DateTimeFormatter
def testDmesg(String kMesg = "") {
LocalDateTime endDate = LocalDateTime.now()
LocalDateTime startDate = convertDates("Tue Dec 19 06:30:55 2023")
// println startDate
getDmesg(startDate, endDate, kMesg)
}
def convertDates(String cDate){
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd H:m:s yyyy")
return LocalDateTime.parse(cDate, formatter)
}
def parseLines(String line) {
return convertDates(line.minus("[").split("]")[0])
}
def getDmesg(LocalDateTime sDate, LocalDateTime eDate, String kernelEvent = "Out of memory:") {
def dmesgCent = sh(script: "dmesg -T", returnStdout: true).trim()
String dmesgOutVar = "===================== DMESG OUTPUT ============================================\n"
if(dmesgCent.contains(kernelEvent)){
println "Event ${kernelEvent} found during the pileline execution"
}
dmesgCent.split('\n').each {
if( !it.equals("") && eDate > parseLines(it) && parseLines(it) > sDate) {
dmesgOutVar = dmesgOutVar + it + "\n"
}
}
println dmesgOutVar
println "===================== END DMESG OUTPUT ============================================"
}
return this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment