#!/usr/bin/python

import sys
import os.path
import stat

sys.path.append("/usr/lib")
from mongodb_health.basecheck import *

instance=sys.argv[1]
__MONGO_MONITOR="/etc/mongo-monitor.conf"
user=None
password=None
if os.path.exists(__MONGO_MONITOR):
    filestat = os.stat(__MONGO_MONITOR)
    if stat.S_IMODE(filestat.st_mode)==384 and filestat.st_gid == 0 and filestat.st_uid == 0:
        file = open(__MONGO_MONITOR)
        user=file.readline().strip()
        password=file.readline().strip()
    else:
        print "2;Failed;set root:root ownership and 600 permissions to file /etc/mongo-monitor.conf"
        exit()

port=find_port(instance)
if not port:
    print "0;Ok;" + instance + " is not configured"
else:
    recovery_check(port, user, password)
