Last active
December 20, 2023 12:55
-
-
Save Storager/2f026a90948ef8b43340c16affb89cb3 to your computer and use it in GitHub Desktop.
Gist description
This file contains hidden or 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
| 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