# Python for analyzing the Logs

**URL:** <https://community.f5.com/t/python-for-analyzing-the-logs/56655>\
**Category:** Technical Forums\
**Tags:** icontrolrest, devops, ltm, application-delivery\
**Created:** [February 15, 2021, 2:29pm UTC](https://community.f5.com/t/python-for-analyzing-the-logs/56655 "2021-02-15T14:29:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RahulG](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@RahulG](https://community.f5.com/u/RahulG)\
**Post date:** [February 15, 2021, 2:29pm UTC](https://community.f5.com/t/python-for-analyzing-the-logs/56655/1 "2021-02-15T14:29:26Z")

</div>

We are having Tomcat memory issues on multiple F5 devices. We need to create a python script to analyze logs on multiple devices and find if there is a log "java.lang.OutOfMemoryError:&nbsp;" in /var/log/tomcat/catalina.out. Could someone please help me draft this script.

---

<div class="post-metadata">

**Author:** ![jaikumar\_f5](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@jaikumar\_f5](https://community.f5.com/u/jaikumar_f5)\
**Post date:** [February 15, 2021, 2:58pm UTC](https://community.f5.com/t/python-for-analyzing-the-logs/56655/2 "2021-02-15T14:58:04Z")

</div>

Dont you have a centralized logging, like splunk, syslog servers. I’m sure there will be.

Simply use splunk or your monitoring tool to search for the OOM log

---

<div class="post-metadata">

**Author:** ![Satoshi\_Toyosa1](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@Satoshi\_Toyosa1](https://community.f5.com/u/Satoshi_Toyosa1)\
**Post date:** [February 18, 2021, 10:12pm UTC](https://community.f5.com/t/python-for-analyzing-the-logs/56655/3 "2021-02-18T22:12:36Z")

</div>

If I do not want to use an external logging service, I am in a hurry, and my boxes have adequate power and bandwidth, I would use iControl REST POST /mgmt/tm/util/bash to call “cat \<file\> | grep keywords”. Run this against all the boxes one by one.

```tcl
$ curl -sku $PASS https://$HOST/mgmt/tm/util/bash \
  -X POST -H "Content-type: application/json" \
 -d '{"command":"run", "utilCmdArgs": "-c \"cat /var/log/tomcat/catalina.out | grep \\\"Unknown version\\\"\""}' \
  | jq -r '.commandResult'
WARNING: Unknown version string [3.1]. Default version will be used.

```

(I chose “Unknow version” for grepping as my log presently does not have OutOfMemoryError".)

I chose jq for parsing. You can do the same using python, of course. Be careful with the double escaping for double-quotes. We can easily make mistakes (For the above call, I tried three times :-).

For a sophisticated method for deploying logging facility, check [F5 Telemetry Streaming](https://clouddocs.f5.com/products/extensions/f5-telemetry-streaming/latest/).
