Ejemplo n.º 1
0
    def get_summary(self):
        res = []
        path_dir = self.mars_config.get_base_path()
        snap_times_list = os.listdir(path_dir)
        snap_times_list.sort(reverse=True)

        for snap_time in snap_times_list:
            try:
                time_stamp = int(snap_time)
                time_str = time.strftime('%Y-%m-%d %H:%M:%S',
                                         time.localtime(time_stamp))
                cur_summary = {
                    'time':
                    time_str,
                    GROUPS_NAME:
                    len(get_group(self.mars_config, snap_time)),
                    DEVICE_NAME:
                    len(get_devices(self.mars_config, snap_time)),
                    DEVICE_CONFIG_NAME:
                    len(get_devices_configs(self.mars_config, snap_time)),
                    HOSTS_NAME:
                    len(get_host(self.mars_config, snap_time)),
                    LINKS_NAME:
                    len(get_link(self.mars_config, snap_time)),
                    FLOW_NAME:
                    len(get_flow(self.mars_config, snap_time)),
                }
                res.append(cur_summary)
            except ValueError as e:
                pass

        return res
Ejemplo n.º 2
0
 def save(self, commit=True) -> models.Homework:
     data: models.Homework = super().save(commit=False)
     group = utils.get_group(self.cleaned_data.pop('subject'), self.instance.lesson.group.klass)
     if data.lesson.date != self.cleaned_data['date']:
         data.delete()
         return models.Homework.add_homework(**self.cleaned_data, group=group)
     data.group = group
     if not self.data.get("deleteFile") is None:
         data.h_file.delete()
     data.save()
     return data
Ejemplo n.º 3
0
 def init_snap_data(self, snap_time_str):
     print('Start to trace the ' +
           UseStyle(snap_time_str, fore='green', mode='underline') +
           ' snap data\n')
     snap_time = format_time_string_2_number(snap_time_str)
     self.snap_time = snap_time
     self.device_config_obj = DeviceConfigs.initialize_with(
         self.mars_config, get_devices_configs(self.mars_config, snap_time))
     self.hosts_obj = Hosts.initialize_with(
         self.mars_config, get_host(self.mars_config, snap_time))
     self.group_obj = Groups.initialize_with(
         self.mars_config, get_group(self.mars_config, snap_time))
     self.flow_obj = Flows.initialize_with(
         self.mars_config, get_flow(self.mars_config, snap_time))
     self.link_obj = Links.initialize_with(
         self.mars_config, get_link(self.mars_config, snap_time))
Ejemplo n.º 4
0
def upgrade_2_2():
    # CONFIGURATION
    upgrade_conf = True
    upgrade_db = True
    # END
    conf = config.get_config(validate=False)
    print "[Migration from v2.1 to v2.2]\n"
    backup("2.1")
    if upgrade_conf:
        print "Upgrading configuration file..."
        new = json.loads(conf["config_json"], object_pairs_hook=OrderedDict)
        # delete the linux plugin
        del new["plugins"]["linux"]
        # add the command plugin
        new["plugins"]["command"] = {}
        new["plugins"]["command"]["timeout"] = 30
        # add the system plugin
        new["plugins"]["system"] = {}
        new["plugins"]["system"]["timeout"] = 30
        # add timeout to image
        new["plugins"]["image"] = {}
        new["plugins"]["image"]["timeout"] = 30
        # add the earthquake plugin
        new["plugins"]["earthquake"] = None
        # add the rss plugin
        new["plugins"]["rss"] = None
        # add the mqtt plugin
        new["plugins"]["mqtt"] = {}
        new["plugins"]["mqtt"]["enabled"] = False
        new["plugins"]["mqtt"]["hostname"] = "localhost"
        new["plugins"]["mqtt"]["port"] = 1883
        # add the ds18b20 plugin
        new["plugins"]["ds18b20"] = None
        # add the dht plugin
        new["plugins"]["dht"] = None
        # add additional options in db
        new["db"]["database_file"] = "/var/lib/redis/dump.rdb"
        new["db"]["backup"] = {}
        new["db"]["backup"]["daily"] = True
        new["db"]["backup"]["weekly"] = True
        # add the ads1x15 plugin
        new["plugins"]["ads1x15"] = None
        print "\tINFO: please be aware the following new plugins are now available: earthquake, mqtt, ds18b20, dht, ads1x15, rss. Review the documentation for details"
        # add general
        new["general"] = {}
        new["general"]["latitude"] = 0
        new["general"]["longitude"] = 0
        new["general"]["house_name"] = "myHouse"
        print "\tWARNING: different plugins use now the new 'latitude' and 'longitude' settings in 'general', ensure they are correct"
        # add language
        new["general"]["language"] = "en"
        print "\tINFO: multiple languages are now supported. Define your language in 'general' and create your aliases for each 'display_name' variable"
        # move units and timeframe under general
        new["general"]["units"] = conf["units"]
        del new["units"]
        new["general"]["timeframes"] = conf["timeframes"]
        del new["timeframes"]
        # migrate sections
        new_sections = []
        for section in new["gui"]["sections"]:
            section_item = {}
            section_item["section_id"] = section
            section_item["display_name"] = {}
            section_item["display_name"]["en"] = section
            new_sections.append(section_item)
        new["gui"]["sections"] = new_sections
        # define the news module
        news = {
            "module_id":
            "news",
            "section_id":
            "Main",
            "display_name": {
                "en": "News"
            },
            "icon":
            "fa-newspaper-o",
            "enabled":
            True,
            "widgets": [[{
                "widget_id":
                "news_recent",
                "display_name": {
                    "en": "Recent News"
                },
                "enabled":
                True,
                "size":
                12,
                "layout": [{
                    "type": "table",
                    "sensor": "news:rss:all_news",
                    "columns": ""
                }]
            }]],
            "sensors": [{
                "module_id": "news",
                "group_id": "rss",
                "sensor_id": "all_news",
                "enabled": True,
                "plugin": {
                    "plugin_name": "rss",
                    "url": "http://rss.cnn.com/rss/edition.rss",
                    "polling_interval": 20
                },
                "format": "string",
                "retention": {
                    "realtime_count": 1
                }
            }]
        }
        # define the power module
        power = {
            "module_id":
            "power",
            "section_id":
            "System",
            "display_name": {
                "en": "Reboot/Shutdown",
            },
            "icon":
            "fa-power-off",
            "enabled":
            True,
            "widgets": [[{
                "widget_id":
                "reboot",
                "display_name": {
                    "en": "Reboot the system",
                },
                "enabled":
                True,
                "size":
                4,
                "offset":
                1,
                "layout": [{
                    "type": "button",
                    "display_name": {
                        "en": "Reboot",
                    },
                    "send": "power/command/reboot/run/save"
                }]
            }, {
                "widget_id":
                "shutdown",
                "display_name": {
                    "en": "Shutdown the system",
                },
                "enabled":
                True,
                "size":
                4,
                "offset":
                2,
                "layout": [{
                    "type": "button",
                    "display_name": {
                        "en": "Shutdown",
                    },
                    "send": "power/command/shutdown/run/save"
                }]
            }]],
            "sensors": [{
                "module_id": "power",
                "group_id": "command",
                "sensor_id": "reboot",
                "enabled": True,
                "plugin": {
                    "plugin_name": "system",
                    "measure": "reboot"
                },
                "format": "string",
                "retention": {
                    "realtime_count": 1
                }
            }, {
                "module_id": "power",
                "group_id": "command",
                "sensor_id": "shutdown",
                "enabled": True,
                "plugin": {
                    "plugin_name": "system",
                    "measure": "shutdown"
                },
                "format": "string",
                "retention": {
                    "realtime_count": 1
                }
            }]
        }
        # add retention to sensors
        new["sensors"]["retention"] = {}
        new["sensors"]["retention"]["realtime_new_only"] = False
        new["sensors"]["retention"]["realtime_count"] = 0
        new["sensors"]["retention"]["realtime_days"] = 5
        new["sensors"]["retention"]["recent_days"] = 5
        new["sensors"]["retention"]["history_days"] = 0
        # add language to weatherchannel
        new["plugins"]["weatherchannel"]["language"] = "en"
        # delete location from weatherchannel and wunderground
        del new["plugins"]["weatherchannel"]["location"]
        del new["plugins"]["wunderground"]["location"]
        print "\tWARNING: 'location' in 'plugins/wunderground' and 'plugins/weatherchannel' has been precated, use the new 'latitude' and 'longitude' in 'general' instead"
        # delete csv_file from the csv plugin
        if "csv_file" in new["plugins"]["csv"]:
            print "\tWARNING: 'csv_file' in 'plugins/csv' has been deprecated, specify the filename in each sensor"
        new["plugins"]["csv"] = None
        # warn about data_expire_days
        print "\tWARNING: data_expire_days in 'sensors' has been deprecated, use 'retention' instead"
        del new["sensors"]["data_expire_days"]
        # warn about icloud widget
        print "\tWARNING: if you have any widget displaying the position of an icloud-based sensor, please manually edit it. Set 'type' to 'map', 'group' to the group of sensors, 'tracking' to 'true' and 'timeframe' to 'realtime'"
        # add output
        new["output"] = {}
        # migrate notifications into output
        new["output"]["email"] = conf["notifications"]["email"]
        new["output"]["slack"] = conf["notifications"]["slack"]
        # add email subject
        new["output"]["email"]["subject"] = "Notification"
        del new["notifications"]
        # add sms notification
        sms = {
            "enabled": False,
            "ssl": False,
            "hostname": "www.freevoipdeal.com",
            "username": "",
            "password": "",
            "from": "",
            "to": [],
            "min_severity": "alert",
            "rate_limit": 1
        }
        new["output"]["sms"] = sms
        # add audio notification
        output_audio = {
            "enabled": False,
            "engine": "google",
            "language": "en-US"
        }
        new["output"]["audio"] = output_audio
        print "\tINFO: added the following new notification channels: sms, audio. Enable them if interested"
        # remove options from email
        del new["output"]["email"]["module_digest"]
        new["output"]["email"]["enabled"] = new["output"]["email"][
            "realtime_alerts"]
        del new["output"]["email"]["realtime_alerts"]
        print "\tWARNING: 'module_digest' in 'email' has been deprecated, if 'daily_digest' is set to 'true' in the module, the digest will be sent"
        # add input
        new["input"] = {}
        new["input"]["settings"] = {}
        new["input"]["settings"]["algorithm"] = "token_set_ratio"
        new["input"]["settings"]["score"] = 50
        # remove options from slack
        new["output"]["slack"]["enabled"] = new["output"]["slack"][
            "realtime_alerts"]
        del new["output"]["slack"]["realtime_alerts"]
        new["input"]["slack"] = {}
        new["input"]["slack"]["enabled"] = new["output"]["slack"][
            "interactive_bot"]
        del new["output"]["slack"]["interactive_bot"]
        # add skin
        new["gui"]["skin"] = "blue"
        # add pws
        pws = {
            "enabled": False,
            "username": "",
            "password": "",
            "publishing_interval": 10,
            "data": {
                "tempf": "outdoor:temperature:external",
                "humidity": "outdoor:humidity:external",
                "baromin": "outdoor:pressure:external"
            }
        }
        new["pws"] = pws
        # add audio input
        input_audio = {
            "enabled": False,
            "engine": "google",
            "language": "en-US",
            "echo_request": False,
            "recorder": {
                "max_duration": 60,
                "start_duration": 0.1,
                "start_threshold": 1,
                "end_duration": 3,
                "end_threshold": 0.1
            }
        }
        new["input"]["audio"] = input_audio
        print "\tINFO: added audio input. Enable it if interested"
        # cycle through the modules
        group_to_delete = []
        group_summary_exclude = {}
        for module in new["modules"]:
            module_id = module["module_id"]
            if "display_name" in module:
                display_name = {"en": module["display_name"]}
                module["display_name"] = display_name
            # add uptime rule
            if module_id == "system":
                uptime_rule = {
                    "rule_id": "system_reboot",
                    "display_name": "The system has been recently rebooted",
                    "enabled": True,
                    "severity": "info",
                    "run_every": "5 minutes",
                    "conditions": ["last_uptime < prev_uptime"],
                    "definitions": {
                        "last_uptime": "system:runtime:uptime,-1,-1",
                        "prev_uptime": "system:runtime:uptime,-2,-2"
                    }
                }
                module["rules"].append(uptime_rule)
                uptime_sensor = {
                    "module_id": "system",
                    "group_id": "runtime",
                    "sensor_id": "uptime",
                    "enabled": True,
                    "display_name": "uptime",
                    "plugin": {
                        "plugin_name": "system",
                        "measure": "uptime",
                        "polling_interval": 10
                    },
                    "format": "int"
                }
                module["sensors"].append(uptime_sensor)
                print "\tINFO: a rule called 'system_reboot' to notify when the system reboots has been added for your convenience"
            if "widgets" in module:
                for i in range(len(module["widgets"])):
                    for j in range(len(module["widgets"][i])):
                        widget = module["widgets"][i][j]
                        # update display_name
                        if "display_name" in widget:
                            display_name = {"en": widget["display_name"]}
                            widget["display_name"] = display_name
                        for k in range(len(widget["layout"])):
                            layout = widget["layout"][k]
                            # update display_name
                            if "display_name" in layout:
                                display_name = {"en": layout["display_name"]}
                                layout["display_name"] = display_name
                            # add tracking to map
                            if "type" in layout and layout["type"] == "map":
                                layout["tracking"] = True
                                # delete the data from the map sensors since format has changed
                                if "group" in layout:
                                    group_to_delete.append(layout["group"])
            if "rules" in module:
                for i in range(len(module["rules"])):
                    rule = module["rules"][i]
                    # update display_name
                    if "display_name" in rule:
                        display_name = {"en": rule["display_name"]}
                        rule["display_name"] = display_name
                    for a, b in rule["definitions"].iteritems():
                        # rename timestam in elapsed in rule definition
                        if not utils.is_number(b) and ",timestamp" in b:
                            rule["definitions"][a] = b.replace(
                                ",timestamp", ",elapsed")
            if "sensors" in module:
                for i in range(len(module["sensors"])):
                    sensor = module["sensors"][i]
                    # add enabled
                    sensor["enabled"] = True
                    # update display_name
                    if "display_name" in sensor:
                        display_name = {"en": sensor["display_name"]}
                        sensor["display_name"] = display_name
                    # add module_id to each sensor
                    sensor["module_id"] = module_id
                    # remove group_summary_exclude
                    if "group_summary_exclude" in sensor:
                        group_summary_exclude[
                            module_id + ":" +
                            sensor["group_id"]] = module_id + ":" + sensor[
                                "group_id"] + ":" + sensor["sensor_id"]
                        del sensor["group_summary_exclude"]
                    # convert single_instance
                    if "single_instance" in sensor:
                        sensor["retention"] = {}
                        sensor["retention"]["realtime_count"] = 1
                        del sensor["single_instance"]
                    if "plugin" in sensor:
                        # rename csv plugin settings
                        if sensor["plugin"]["plugin_name"] == "csv":
                            if "date_position" in sensor:
                                sensor["plugin"]["date_position"] = sensor[
                                    "plugin"]["date_index"]
                                del sensor["plugin"]["date_index"]
                            if "node_id" in sensor:
                                sensor["plugin"]["filter"] = sensor["plugin"][
                                    "node_id"]
                                del sensor["plugin"]["node_id"]
                            if "node_id_index" in sensor:
                                sensor["plugin"]["filter_position"] = sensor[
                                    "plugin"]["node_id_index"]
                                del sensor["plugin"]["node_id_index"]
                            if "measure" in sensor:
                                sensor["plugin"]["prefix"] = sensor["plugin"][
                                    "measure"]
                                del sensor["plugin"]["measure"]
                            if "measure_index" in sensor:
                                sensor["plugin"]["value_position"] = sensor[
                                    "plugin"]["measure_index"]
                                del sensor["plugin"]["measure_index"]
                        if sensor["plugin"]["plugin_name"] == "icloud":
                            # device name mandatory
                            sensor["plugin"]["device_name"] = ""
                            print "\tWARNING: the 'icloud' plugin requires now a single 'device_name' to be set, please review all your sensors using this plugin"
                            if "devices" in sensor["plugin"]:
                                sensor["plugin"]["device"] = sensor["plugin"][
                                    "devices"][0]
                        if sensor["plugin"]["plugin_name"] == "linux":
                            # migrate the linux plugin
                            if sensor["plugin"]["measure"] == "custom":
                                # migrate to the command plugin
                                del sensor["plugin"]["measure"]
                                sensor["plugin"]["plugin_name"] = "command"
                            else:
                                # migrate to the system plugin
                                sensor["plugin"]["plugin_name"] = "system"
        # add the power module
        new["modules"].append(power)
        print "\tINFO: a new module called 'power' has been added for rebooting/shutting down the system"
        # add the news module
        new["modules"].append(news)
        print "\tINFO: a new module called 'news' has been added for presenting the latest headlines"
        # second round
        for module in new["modules"]:
            module_id = module["module_id"]
            if "widgets" in module:
                for i in range(len(module["widgets"])):
                    for j in range(len(module["widgets"][i])):
                        widget = module["widgets"][i][j]
                        for k in range(len(widget["layout"])):
                            layout = widget["layout"][k]
                            if layout[
                                    "type"] == "sensor_group_summary" and layout[
                                        "group"] in group_summary_exclude:
                                # add exclude
                                layout["exclude"] = []
                                layout["exclude"].append(
                                    group_summary_exclude[layout["group"]])
        # delete from the db the sensors in group_to_delete
        for group in group_to_delete:
            sensors = utils.get_group(group)
            for sensor in sensors:
                print sensor["module_id"] + ":" + sensor[
                    "group_id"] + ":" + sensor["sensor_id"]
                db.delete(sensor["module_id"] + ":" + sensor["group_id"] +
                          ":" + sensor["sensor_id"])
        # save the updated configuration
        config.save(json.dumps(new, default=lambda o: o.__dict__))
    if upgrade_db:
        print "Upgrading database..."
        version_key = conf["constants"]["db_schema"]["version"]
        db.set_simple(version_key, "2.2")
Ejemplo n.º 5
0
    def __init__(self, handle):
        activity.Activity.__init__(self, handle, True)

        # ToolbarBox:

        toolbarbox = ToolbarBox()
        activitybutton = ActivityButton(self)
        toolbarbox.toolbar.insert(activitybutton, 0)

        separator = gtk.SeparatorToolItem()
        toolbarbox.toolbar.insert(separator, -1)

        explorer_btn = RadioToolButton()
        explorer_btn.set_tooltip('Explorador')
        explorer_btn.props.icon_name = 'activity-explorer'
        toolbarbox.toolbar.insert(explorer_btn, -1)

        self._goup = ToolButton('to-subjects')
        self._goup.connect('clicked', self._go_up_clicked)
        self._goup.set_tooltip('Ver Materias')
        self._goup.set_accelerator("<Shift><M>")
        self._goup.set_sensitive(False)
        toolbarbox.toolbar.insert(self._goup, -1)

        self._select_all = ToolButton('select-all')
        self._select_all.set_tooltip('Seleccionar todo')
        self._select_all.connect("clicked", self._select_all_clicked)
        self._select_all.set_sensitive(False)
        toolbarbox.toolbar.insert(self._select_all, -1)

        self._download = ToolButton('download')
        self._download.set_tooltip('Descargar')
        self._download.set_sensitive(False)
        toolbarbox.toolbar.insert(self._download, -1)

        separator = gtk.SeparatorToolItem()
        toolbarbox.toolbar.insert(separator, -1)

        homework_btn = RadioToolButton()
        homework_btn.set_tooltip('Tareas Domiciliarias')
        homework_btn.props.icon_name = 'homework'
        homework_btn.props.group = explorer_btn

        toolbarbox.toolbar.insert(homework_btn, -1)

        open_btn = ToolButton()
        open_btn.set_tooltip('Seleccionar tarea')
        open_btn.props.icon_name = 'open-from-journal'
        open_btn.set_sensitive(False)
        open_btn.connect("clicked", self._select_hw_from_journal)
        toolbarbox.toolbar.insert(open_btn, -1)

        self._send = ToolButton()
        self._send.set_tooltip('Enviar tarea')
        self._send.connect('clicked', self._send_hw_to_server)
        self._send.props.icon_name = 'document-send'
        self._send.set_sensitive(False)
        toolbarbox.toolbar.insert(self._send, -1)

        homework_btn.connect('clicked', self.homework_btn_cb, open_btn)
        explorer_btn.connect('clicked', self.explorer_btn_cb, open_btn)

        separator = gtk.SeparatorToolItem()
        separator.set_expand(True)
        separator.set_draw(False)
        toolbarbox.toolbar.insert(separator, -1)

        stopbtn = StopButton(self)
        toolbarbox.toolbar.insert(stopbtn, -1)

        self.set_toolbar_box(toolbarbox)
        self._one_alert = None

        # Canvas
        self._canvas = gtk.EventBox()
        self._name = ''
        self._last_name = ''
        self._hw_title = ''
        self._hw_description = ''
        self._hw_path = ''
        self._hw_mimetype = ''

        self.set_canvas(self._canvas)
        self.show_all()
        if not utils.get_group():
            self.choose_group()
        else:
            self._do_canvas()
Ejemplo n.º 6
0
def group_view(request):
    data = {}
    data["public"] = utils.get_public(request)
    data["group"] = utils.get_group()
    return render(request, 'data_mgr/group.html', {"data": data})
Ejemplo n.º 7
0
def get_group_view(request):
    id = request.GET.get("id")
    ret = utils.get_group(id)
    return public.success_result_http(ret)
Ejemplo n.º 8
0
def group_view(request):
    data = {}
    data["public"] = utils.get_public(request)
    data["group"] = utils.get_group()
    return render(request, 'data_mgr/group.html', {"data":data})
Ejemplo n.º 9
0
def get_group_view(request):
    id = request.GET.get("id")
    ret = utils.get_group(id)
    return  public.success_result_http(ret)
Ejemplo n.º 10
0
 def add_homework(self, klass: models.Klasses) -> models.Homework:
     subject = self.cleaned_data.pop('subject')
     group = utils.get_group(subject, klass)
     return models.Homework.add_homework(group=group, **self.cleaned_data)