Esempio n. 1
0
def minions_status_task():
    #minion status , version data save to mysql
    status_all = sapi.runner_status('status')
    for host_name in status_all['up']:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        try:
            version = eval(salt_grains[0].grains).get('saltversion').decode('string-escape')
        except:
            version = 'NULL'
            logger.error("Don't get minion version")
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status = Minions_status()
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Up'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_all['down']:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        try:
            version = eval(salt_grains[0].grains).get('saltversion').decode('string-escape')
        except:
            version = 'NULL'
            logger.error("Don't get minion version")
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status = Minions_status()
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Down'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Down')
Esempio n. 2
0
def minions_status_scheduled_job():
    status = Minions_status()
    status_all = sapi.runner_status('status')
    for host_name in status_all['up']:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        version = eval(
            salt_grains[0].grains).get('saltversion').decode('string-escape')
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Up'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(
            minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_all['down']:
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Down'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(
            minion_id=host_name, minion_version=version, minion_status='Down')
Esempio n. 3
0
def minions_status_task():
    #minion status , version data save to mysql
    status_all = sapi.runner_status('status')
    for host_name in status_all['up']:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        try:
            version = eval(salt_grains[0].grains).get('saltversion').decode('string-escape')
        except:
            version = 'NULL'
            logger.error("Don't get minion version")
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status = Minions_status()
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Up'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_all['down']:
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status = Minions_status()
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Down'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Down')
Esempio n. 4
0
def minions_status_scheduled_job():
    #status_up = []
    #status_down = []
    group = NodeGroups()
    #sapi = SaltAPI()
    status = Minions_status()
    status_all = sapi.runner_status('status')
    for host_name in status_all['up']:
        version = sapi.remote_noarg_execution(host_name, 'grains.items')['saltversion']
        #version = "2015.5.5 (Lithium)"
        #version_dic = {'version': version}
        #group_dic = group.hosts_in_group(host_name)
        #status_dic = {'host': host_name}
        #status_dic.update(group_dic)
        #status_dic.update(version_dic)
        #status_up += [status_dic]
        #minion_id = Minions_status.objects.get(minion_id=host_name)
        #minion_id.delete()
        #status = Minions_status(minion_id=host_name)
        #update(blog=b)
        #if minion_id
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Up'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_all['down']:
        #version_dic = {'version': ""}
        #group_dic = group.hosts_in_group(host_name)
        #status_dic = {'host': host_name}
        #status_dic.update(group_dic)
        #status_dic.update(version_dic)
        #status_down += [status_dic]
        #minion_id = Minions_status.objects.get(minion_id=host_name)
        #minion_id.delete()
        try:
            minion_id = Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Down'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Down')
Esempio n. 5
0
def grains_task():
    # grains data save to mysql
    salt_grains = Salt_grains()
    minions_status = Minions_status()
    status = sapi.runner_status('status')
    status_up = status['up']
    status_down = status['down']
    for host_name in status_up:
        grains = sapi.remote_noarg_execution(host_name, 'grains.items')
        try:
            Salt_grains.objects.get(minion_id=host_name)
        except:
            salt_grains.grains = grains
            salt_grains.minion_id = host_name
            salt_grains.save()
        Salt_grains.objects.filter(minion_id=host_name).update(
            grains=grains, minion_id=host_name)

    # minion status , version data save to mysql
    for host_name in status_up:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        version = eval(
            salt_grains[0].grains).get('saltversion').decode('string-escape')
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            minions_status.minion_id = host_name
            minions_status.minion_version = version
            minions_status.minion_status = 'Up'
            minions_status.save()
        Minions_status.objects.filter(minion_id=host_name).update(
            minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_down:
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            minions_status.minion_id = host_name
            minions_status.minion_version = version
            minions_status.minion_status = 'Down'
            minions_status.save()
        Minions_status.objects.filter(minion_id=host_name).update(
            minion_id=host_name, minion_version=version, minion_status='Down')
Esempio n. 6
0
def grains_task():
    # grains data save to mysql
    salt_grains = Salt_grains()
    minions_status = Minions_status()
    status = sapi.runner_status('status')
    status_up = status['up']
    status_down = status['down']
    for host_name in status_up:
        grains = sapi.remote_noarg_execution(host_name, 'grains.items')
        try:
            Salt_grains.objects.get(minion_id=host_name)
        except:
            salt_grains.grains = grains
            salt_grains.minion_id = host_name
            salt_grains.save()
        Salt_grains.objects.filter(minion_id=host_name).update(grains=grains, minion_id=host_name)

    # minion status , version data save to mysql
    for host_name in status_up:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        version = eval(salt_grains[0].grains).get('saltversion').decode('string-escape')
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            minions_status.minion_id = host_name
            minions_status.minion_version = version
            minions_status.minion_status = 'Up'
            minions_status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version,
                                                                  minion_status='Up')
    for host_name in status_down:
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            minions_status.minion_id = host_name
            minions_status.minion_version = version
            minions_status.minion_status = 'Down'
            minions_status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version,
                                                                  minion_status='Down')
Esempio n. 7
0
def minions_status_scheduled_job():
    status = Minions_status()
    status_all = sapi.runner_status('status')
    for host_name in status_all['up']:
        salt_grains = Salt_grains.objects.filter(minion_id=host_name)
        version = eval(salt_grains[0].grains).get('saltversion').decode('string-escape')
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Up'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Up')
    for host_name in status_all['down']:
        try:
            Minions_status.objects.get(minion_id=host_name)
        except:
            status.minion_id = host_name
            status.minion_version = version
            status.minion_status = 'Down'
            status.save()
        Minions_status.objects.filter(minion_id=host_name).update(minion_id=host_name, minion_version=version, minion_status='Down')