Splunk Dev

How can I import croniter in my modular input?

prabhasgupte
Communicator

I want to accept data input interval as cron entry and process it in my modular input.
I am referring this REST API Modular Input app (https://splunkbase.splunk.com/app/1546/) for that. It uses croniter to get next run time of job.

However, I am not being able to import croniter into my modular input script.
I have croniter egg file at SPLUNK_HOME/etc/apps/TA-myta/bin/croniter-0.3.8-py2.7.egg
I have also explicitly added SPLUNK_HOME/etc/apps/TA-myta/bin/croniter-0.3.8-py2.7.egg to sys.path (not needed, but added as an attempt to make it work.)
However, when I try to import croniter, I get ImportError.

How can I fix this?

My code to the point of failure looks as follows. I always get into except block and never see "ready to go":
import sys
from datetime import datetime

import splunk.clilib.cli_common as scc
import splunk.entity as entity

logger = logging.getLogger('TA-myta')

TA_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

egg_dir = TA_ROOT + "/bin/croniter-0.3.8-py2.7.egg"
sys.path.append(egg_dir)
try:
    from croniter import croniter
except:
    logger.error("could not import croniter. Exiting.")
    exit(0)

logger.info("ready to go")

Edit 1:
The splunkd.log has following lines:

03-22-2017 16:27:30.105 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py" ImportError: No module named dateutil.relativedelta
03-22-2017 16:28:30.264 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py" Traceback (most recent call last):
03-22-2017 16:28:30.264 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py"   File "/opt/splunk/etc/apps/TA-myta/bin/myta.py", line 39, in <module>
03-22-2017 16:28:30.265 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py"     from croniter import croniter
03-22-2017 16:28:30.265 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py"   File "/opt/splunk/etc/apps/TA-myta/bin/croniter-0.3.8-py2.7.egg/croniter/__init__.py", line 3, in <module>
03-22-2017 16:28:30.265 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py"     import abc
03-22-2017 16:28:30.265 +0530 ERROR ExecProcessor - message from "python /opt/splunk/etc/apps/TA-myta/bin/myta.py"   File "/opt/splunk/etc/apps/TA-myta/bin/croniter-0.3.8-py2.7.egg/croniter/croniter.py", line 8, in <module>
0 Karma
1 Solution

prabhasgupte
Communicator

Never mind! Got it working!!

I needed to add and import eggs for python_dateutil and six - as dependencies for croniter.

View solution in original post

0 Karma

prabhasgupte
Communicator

Never mind! Got it working!!

I needed to add and import eggs for python_dateutil and six - as dependencies for croniter.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...