Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag so we can run in one-shot mode from cron #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions influxdbSeedbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,20 @@ def _validate_logging_level(self):

class influxdbSeedbox():

def __init__(self, config=None, silent=None):
def __init__(self, config=None, silent=None, cron=False):

self.config = configManager(silent, config=config)

self.output = self.config.output
self.logger = None
self.delay = self.config.delay
self.cron = cron

self.influx_client = InfluxDBClient(
self.config.influx_address,
self.config.influx_port,
username=self.config.influx_user,
password=self.config.influx_password,
database=self.config.influx_database,
ssl=self.config.influx_ssl,
verify_ssl=self.config.influx_verify_ssl
Expand Down Expand Up @@ -266,6 +269,10 @@ def run(self):
tracker_json = self.tor_client.process_tracker_list()
if tracker_json:
self.write_influx_data(tracker_json)
# Ugly way to run in 'one shot' mode
# useful when wanting to run from cron
if self.cron:
break
time.sleep(self.delay)


Expand All @@ -277,8 +284,9 @@ def main():
parser.add_argument('--config', default='config.ini', dest='config', help='Specify a custom location for the config file')
# Silent flag allows output prior to the config being loaded to also be suppressed
parser.add_argument('--silent', action='store_true', help='Surpress All Output, regardless of config settings')
parser.add_argument('--cron', action='store_true', help='Run from cron, get stats, send to influxdb and quit')
args = parser.parse_args()
monitor = influxdbSeedbox(silent=args.silent, config=args.config)
monitor = influxdbSeedbox(silent=args.silent, config=args.config, cron=args.cron)
monitor.run()


Expand Down