def status(): """Run check on Elasticsearch.""" schedule_log("Starting Elasticsearch Monitor") command_text = 'curl http://127.0.0.1:9200/_stats' schedule_log('Running: %s' % command_text) output, error = safe_run(command_text) try: data = json.loads(output) schedule_log('Loaded json, saving.') save(True, output, mongo_database(), mongo_collection(), output) except Exception as ex: schedule_log('Reporting as failed.') schedule_log('%s' % ex) schedule_log(output) error = '%s' if error: save(False, {}, mongo_database(), mongo_collection(), error) schedule_log('Finished')
def status(): """Run PM2 Monitor.""" schedule_log("Starting URL checker") status = True output = '' data = {'results': []} urls = get_parameters() schedule_log('Got %s URLs' % len(urls)) schedule_log('%s' % urls) for url in urls: schedule_log('Checking: %s' % url) try: get_code = urlopen(url).getcode() schedule_log('Got code: %s' % get_code) data['results'].append({'url': url, 'status': get_code}) if get_code != 200: status = False except Exception as ex: status = False schedule_log('Exception: %s' % ex) data['results'].append({'url': url, 'status': '%s' % ex}) save(status, data, mongo_database(), mongo_collection(), output) schedule_log("Finished")
def status(): """Run PM2 Monitor.""" schedule_log("Starting PM2 Monitor") output = run('pm2 ls') data = run('pm2 jlist') schedule_log('Jlist returned: %s' % data) try: save(True, json.loads(data), mongo_database(), mongo_collection(), output) except Exception as ex: schedule_log('%s' % ex) save(False, {}, mongo_database(), mongo_collection(), output) schedule_log("Finished")
def status(): """Run check on memory.""" schedule_log("Starting Memory Monitor") command_text = 'free' output, error = safe_run(command_text) try: data = convert(output) save(True, data, mongo_database(), mongo_collection(), output) except Exception as ex: schedule_log('Reporting as failed.') schedule_log('%s' % ex) error = '%s' if error: save(False, {}, mongo_database(), mongo_collection(), error) schedule_log("Finished")
def status(): """Run check on disk.""" setup_environment() schedule_log("Starting Disk Monitor") command_text = 'df' output, error = safe_run(command_text) data = {} try: data = convert(output) except Exception as ex: error = ex if error: save(False, {}, mongo_database(), mongo_collection(), error) else: save(True, data, mongo_database(), mongo_collection(), output) schedule_log('Finished')
def status(): """Run postgres isready.""" schedule_log("Starting pg_isready") command_text = 'pg_isready' output, error = safe_run(command_text) try: data = convert(output) if data[1] == 'accepting connections': save(True, data, mongo_database(), mongo_collection(), output) else: save(False, data, mongo_database(), mongo_collection(), '') except Exception as ex: schedule_log('Reporting as failed.') schedule_log('%s' % ex) error = '%s' if error: save(False, {}, mongo_database(), mongo_collection(), error) schedule_log("Finished")
def status(): """Run check on CouchDB.""" schedule_log("Starting CouchDB Monitor") databases = get_parameters() store_data = [] for database_name in databases: schedule_log(database_name) command_text = 'curl http://127.0.0.1:5984/%s' % database_name schedule_log('Running: %s' % command_text) output, error = safe_run(command_text) schedule_log('Parsing JSON') try: data = json.loads(output) schedule_log('Loaded json, saving.') store_data.append(data) except Exception as ex: schedule_log('Reporting as failed.') schedule_log('%s' % ex) schedule_log(output) error = '%s' if error: save(False, store_data, mongo_database(), mongo_collection(), error) else: save(True, store_data, mongo_database(), mongo_collection(), output) schedule_log('Finished')
def status(): """Run APT status.""" schedule_log("Starting APT Status") output = run('/usr/lib/update-notifier/apt-check --human-readable', pty=False) data = convert(output) status = True for item in data: if item['qty'] > 0: status = False save(status, data, mongo_database(), mongo_collection(), output) schedule_log("Finished")