<commit_before><commit_msg>add script to add hostgroup on all external organizations<commit_after>from datetime import datetime
from notification.models import TaskHistory
from socket import gethostname
from workflow.steps.util.zabbix import AddOrganizationHostGroup

class AddHostgroupExternalOrganization(object):
    def __init__(self, infras):
        self.infras = infras
        self._task = None

    @property
    def task(self):
        if not self._task:
            self._task = self.register_task()
        return self._task

    def register_task(self):
        task_history = TaskHistory()
        task_history.task_id = datetime.now().strftime("%Y%m%d%H%M%S")
        task_history.task_name = "add_hostgroup_external_organization"
        task_history.relevance = TaskHistory.RELEVANCE_WARNING
        task_history.task_status = TaskHistory.STATUS_RUNNING
        task_history.context = {'hostname': gethostname()}
        task_history.user = 'admin'
        task_history.save()
        return task_history

    def do(self):
        self.task.add_detail("Add Hostgroup on external organizations")
        for infra in self.infras:
            for instance in infra.instances.all():
                self.task.add_detail(
                    "adding hostgroup for {}...".format(instance),
                    level=2
                )
                step = AddOrganizationHostGroup(instance)
                step.do()
        self.task.set_status_success('Hostgroups added successfully.')
{'fraction_non_alphanumeric': 0.08383233532934131, 'fraction_numerical': 0.0006653359946773121, 'mean_word_length': 2.598086124401914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087624', 'n_tokens_mistral': 410, 'n_tokens_neox': 400, 'n_words': 90}