Ejemplo n.º 1
0
def schedule_host_downtime(
    hostname='', start_time=str(unix_timestamp()),
    end_time='', fixed_trigger_id=0,
    author='', comment=''):
    if not (hostname and end_time and author and comment):
        return False

    if start_time.isdigit():
        start_time = int(start_time)
    else:
        start_time = int(webtime_to_timestamp(start_time))
    if not end_time:
        end_time = start_time + 100000;
    else:
        end_time = int(webtime_to_timestamp(end_time))
    duration = end_time - start_time

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'SCHEDULE_HOST_DOWNTIME'
    command = ';'.join(
        [command, hostname, str(start_time), str(end_time), str(0),
         str(fixed_trigger_id), str(duration), author, comment])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 2
0
def schedule_host_downtime(hostname='',
                           start_time=str(unix_timestamp()),
                           end_time='',
                           fixed_trigger_id=0,
                           author='',
                           comment=''):
    if not (hostname and end_time and author and comment):
        return False

    if start_time.isdigit():
        start_time = int(start_time)
    else:
        start_time = int(webtime_to_timestamp(start_time))
    if not end_time:
        end_time = start_time + 100000
    else:
        end_time = int(webtime_to_timestamp(end_time))
    duration = end_time - start_time

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'SCHEDULE_HOST_DOWNTIME'
    command = ';'.join([
        command, hostname,
        str(start_time),
        str(end_time),
        str(0),
        str(fixed_trigger_id),
        str(duration), author, comment
    ])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 3
0
def acknowledge_svc_problem(hostname='', service=''):
    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'ACKNOWLEDGE_SVC_PROBLEM'
    command = ';'.join(
            [command, hostname, service, '1', '1', '0', 'nodetraq', 'acknowledgeded via email'])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 4
0
def acknowledge_host_problem(hostname=''):
    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'ACKNOWLEDGE_HOST_PROBLEM'
    command = ';'.join([
        command, hostname, '1', '1', '0', 'nodetraq',
        'acknowledgeded via email'
    ])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 5
0
def remove_from_downtime(hostname):
    nr = NagiosReader()
    downtimes = nr.parse_downtimes()
    if downtimes:
        down_id = [h for h in downtimes if h["Host Name"] == hostname]
        if down_id:
            # Run removal
            command = print_loc + ' "[%s] ' % unix_timestamp()
            command += 'DEL_HOST_DOWNTIME'
            command = ';'.join([command, down_id[0]["Downtime ID"]])
            command += '\\n" > %s' % nagios_loc
            run_ssh_command(master_server, command)
        return True
    else:
        return False
Ejemplo n.º 6
0
def remove_from_downtime(hostname):
    nr = NagiosReader()
    downtimes = nr.parse_downtimes()
    if downtimes:
        down_id = [h for h in downtimes if h["Host Name"] == hostname]
        if down_id:
            # Run removal
            command = print_loc + ' "[%s] ' % unix_timestamp()
            command += 'DEL_HOST_DOWNTIME'
            command = ';'.join(
                    [command, down_id[0]["Downtime ID"]])
            command += '\\n" > %s' % nagios_loc
            run_ssh_command(master_server, command)
        return True
    else:
        return False
Ejemplo n.º 7
0
def disable_host_service_notifications(hostname):
    if not hostname:
        return None

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'DISABLE_HOST_SVC_NOTIFICATIONS'
    command = ';'.join([command, hostname])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'DISABLE_HOST_NOTIFICATIONS'
    command = ';'.join([command, hostname])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 8
0
def disable_host_service_notifications(hostname):
    if not hostname:
        return None

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'DISABLE_HOST_SVC_NOTIFICATIONS'
    command = ';'.join(
        [command, hostname])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)

    command = print_loc + ' "[%s] ' % unix_timestamp()
    command += 'DISABLE_HOST_NOTIFICATIONS'
    command = ';'.join(
        [command, hostname])
    command += '\\n" > %s' % nagios_loc

    run_ssh_command(master_server, command)
    return True
Ejemplo n.º 9
0
def remove_nagios_monitors(hostname):
    fqdn = hostname + '.yourdomain'
    rm = '/bin/rm -rf'
    auto_dir = '/etc/nagios/AUTO/'
    auto_dir += fqdn
    command = rm + " " + auto_dir

    run_ssh_command(master_server, command)
    run_ssh_command(nagios2, command)
    run_ssh_command(nagios3, command)
    return True
Ejemplo n.º 10
0
def remove_nagios_monitors(hostname):
    fqdn = hostname + '.yourdomain'
    rm = '/bin/rm -rf'
    auto_dir = '/etc/nagios/AUTO/'
    auto_dir += fqdn
    command = rm + " " + auto_dir

    run_ssh_command(master_server, command)
    run_ssh_command(nagios2, command)
    run_ssh_command(nagios3, command)
    return True
Ejemplo n.º 11
0
def grab_new_drraw(graph):
    command = 'cd /var/drraw/saved && ./grab_drraw_graph.py '
    command += ' '.join([graph.name, graph.filename])
    run_ssh_command('root@graph_server', command)
Ejemplo n.º 12
0
def generate_index():
    run_ssh_command('root@graphs',
            'cd /var/drraw/saved && ./generate_index.py')
Ejemplo n.º 13
0
    def create(self, username, full_name, email, shell='/bin/bash',
               title='', manager='',
               departmentNumber='', roomNumber='',
               deploycode = 'false', orgchartmanager = 'false',
               utilityaccount = 'false'):
        username = str(username)
        full_name = str(full_name)
        email = str(email)
        shell = str(shell)
        title = str(title)
        manager = str(manager)
        departmentNumber = str(departmentNumber)
        roomNumber = str(roomNumber)
        deploycode = str(deploycode)
        orgchartmanager = str(orgchartmanager)
        utilityaccount = str(utilityaccount)

        attrs = {}
        attrs['objectClass'] = [
            'top', 'posixAccount',
            'person', 'organizationalPerson',
            'inetOrgPerson', 'yourdomain', 'extensibleobject']
        attrs['uid'] = username
        attrs['cn'] = full_name
        namesplit = full_name.split()
        if len(namesplit) == 2:
            attrs['givenName'] = namesplit[0]
            attrs['sn'] = namesplit[1]
        elif len(namesplit) == 1:
            attrs['givenName'] = namesplit[0]
            attrs['sn'] = ''
        else:
            attrs['givenName'] = ''
            attrs['sn'] = ''
        attrs['mail'] = email
        attrs['homeDirectory'] = '/home/%s' % username
        attrs['loginShell'] = shell
        attrs['gidNumber'] = '1008'
        attrs['uidNumber'] = str(int(self.last_uid) + 1)
        attrs['nsAccountLock'] = 'false'

        # YourDomain object
        attrs['title'] = title
        attrs['manager'] = manager
        attrs['departmentNumber'] = departmentNumber
        attrs['roomNumber'] = roomNumber
        attrs['deploycode'] = deploycode
        attrs['orgchartmanager'] = orgchartmanager
        attrs['utilityaccount'] = utilityaccount

        ldif = modlist.addModlist(attrs)
        self.connection.add_s('uid=%s' % username+','+_baseDN, ldif)

        c.new_account = True
        c.full_name = full_name
        c.username = username
        c.password = GeneratePassword(10)

        # Create the vpn-client for that user
        if utilityaccount == 'false':
            run_ssh_command('vpn_machine',
                './vpn-client.sh %s' % username)

        # Send Welcome Email
        self.update_attribute(
            'uid=%s' % username+','+_baseDN,
            'userPassword', c.password)
        if attrs['mail']:
            try:
                send_email(render('email/ldap_account.mako'),
                'Welcome to Yourdomain!', email_to=attrs['mail'])
            except Exception as e:
                print e
Ejemplo n.º 14
0
    def create(self,
               username,
               full_name,
               email,
               shell='/bin/bash',
               title='',
               manager='',
               departmentNumber='',
               roomNumber='',
               deploycode='false',
               orgchartmanager='false',
               utilityaccount='false'):
        username = str(username)
        full_name = str(full_name)
        email = str(email)
        shell = str(shell)
        title = str(title)
        manager = str(manager)
        departmentNumber = str(departmentNumber)
        roomNumber = str(roomNumber)
        deploycode = str(deploycode)
        orgchartmanager = str(orgchartmanager)
        utilityaccount = str(utilityaccount)

        attrs = {}
        attrs['objectClass'] = [
            'top', 'posixAccount', 'person', 'organizationalPerson',
            'inetOrgPerson', 'yourdomain', 'extensibleobject'
        ]
        attrs['uid'] = username
        attrs['cn'] = full_name
        namesplit = full_name.split()
        if len(namesplit) == 2:
            attrs['givenName'] = namesplit[0]
            attrs['sn'] = namesplit[1]
        elif len(namesplit) == 1:
            attrs['givenName'] = namesplit[0]
            attrs['sn'] = ''
        else:
            attrs['givenName'] = ''
            attrs['sn'] = ''
        attrs['mail'] = email
        attrs['homeDirectory'] = '/home/%s' % username
        attrs['loginShell'] = shell
        attrs['gidNumber'] = '1008'
        attrs['uidNumber'] = str(int(self.last_uid) + 1)
        attrs['nsAccountLock'] = 'false'

        # YourDomain object
        attrs['title'] = title
        attrs['manager'] = manager
        attrs['departmentNumber'] = departmentNumber
        attrs['roomNumber'] = roomNumber
        attrs['deploycode'] = deploycode
        attrs['orgchartmanager'] = orgchartmanager
        attrs['utilityaccount'] = utilityaccount

        ldif = modlist.addModlist(attrs)
        self.connection.add_s('uid=%s' % username + ',' + _baseDN, ldif)

        c.new_account = True
        c.full_name = full_name
        c.username = username
        c.password = GeneratePassword(10)

        # Create the vpn-client for that user
        if utilityaccount == 'false':
            run_ssh_command('vpn_machine', './vpn-client.sh %s' % username)

        # Send Welcome Email
        self.update_attribute('uid=%s' % username + ',' + _baseDN,
                              'userPassword', c.password)
        if attrs['mail']:
            try:
                send_email(render('email/ldap_account.mako'),
                           'Welcome to Yourdomain!',
                           email_to=attrs['mail'])
            except Exception as e:
                print e