Example #1
0
    def update(
        self,
        title=None,
        hosts=None,
        counters=None,
        screen_id=None,
        timespan=None,
        graph_type=None,
        method=None,
        position=None,
    ):

        title = self.title if title is None else title
        hosts = self.hosts if hosts is None else hosts
        hosts = hosts and ENDPOINT_DELIMITER.join(hosts) or ""

        counters = self.counters if counters is None else counters
        counters = counters and ENDPOINT_DELIMITER.join(counters) or ""

        screen_id = screen_id or self.screen_id
        timespan = timespan or self.timespan
        graph_type = graph_type or self.graph_type
        method = method if method is not None else self.method
        position = position or self.position
        db_conn.execute(
            """update dashboard_graph set title=%s, hosts=%s, counters=%s, screen_id=%s,
                    timespan=%s, graph_type=%s, method=%s, position=%s where id=%s""",
            (title, hosts, counters, screen_id, timespan, graph_type, method, position, self.id),
        )
        db_conn.commit()
        return DashboardGraph.get(self.id)
Example #2
0
 def update_multi(cls, rows):
     for x in rows:
         id = x["id"]
         hosts = x["hosts"] or []
         counters = x["counters"] or []
         db_conn.execute('''update dashboard_graph set hosts=%s, counters=%s where id=%s''',
                 (ENDPOINT_DELIMITER.join(hosts) or "", ENDPOINT_DELIMITER.join(counters) or "", id))
     db_conn.commit()
Example #3
0
 def add(cls, title, hosts, counters, screen_id,
             timespan=3600, graph_type='h', method='', position=0):
     cursor = db_conn.execute('''insert into dashboard_graph (title, hosts, counters, screen_id,
             timespan, graph_type, method, position)
             values(%s, %s, %s, %s, %s, %s, %s, %s)''',
             (title, ENDPOINT_DELIMITER.join(hosts) or "", ENDPOINT_DELIMITER.join(counters) or "", screen_id,
                 timespan, graph_type, method, position))
     id_ = cursor.lastrowid
     db_conn.execute('''update dashboard_graph set position=%s where id=%s''', (id_, id_))
     db_conn.commit()
     cursor and cursor.close()
     return cls.get(id_)
Example #4
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %(es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute('''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE time_=%s''',
             (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     if not id_:
         cursor = db_conn.execute("select id from tmp_graph where ck='" + ck + "'")
         id_ = cursor.fetchone()[0]
     db_conn.commit()
     cursor and cursor.close()
     return id_
Example #5
0
 def gets(cls, pid=None, start=0, limit=0):
     assert limit >= 0
     if pid is not None:
         if limit > 0:
             cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where pid=%s limit %s, %s''', (pid, start, limit))
         else:
             cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where pid=%s''', (pid,))
     else:
         if limit > 0:
             cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen limit %s, %s''', (start, limit))
         else:
             cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen''')
     rows = cursor.fetchall()
     cursor.close()
     return [cls(*row) for row in rows]
Example #6
0
 def add(cls, tmp_id, type, data):
     cursor = db_conn.execute('''insert ignore into domeos_graph (tmp_id, type, data) values(%s, %s, %s) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)''',
                              (tmp_id, type, data))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor and cursor.close()
     return id_
Example #7
0
    def searchAlias(cls):
        sql = '''select id, endpoint, alias from endpoint_alias '''

        cursor = db_conn.execute(sql)
        rows = cursor.fetchall()
        cursor and cursor.close()
        return [cls(*row) for row in rows]
Example #8
0
 def check(cls,pid,name):
     cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where pid=%s and name=%s''',(pid,name))
     row = cursor.fetchone()
     cursor.close()
     if row:
         return cls(*row)
     else:
         return
Example #9
0
 def get(cls, id):
     cursor = db_conn.execute('''select id, tmp_id, type, data from domeos_graph where id=%s''', (id,))
     row = cursor.fetchone()
     cursor and cursor.close()
     if row:
         id, tmp_id, type, data = row
         return cls(id, tmp_id, type, data)
     else:
         return None
Example #10
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %(es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute('''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id),time_=%s''',
             (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor and cursor.close()
     return id_
Example #11
0
 def get(cls, id):
     cursor = db_conn.execute('''select id, endpoints, counters, time_ from tmp_graph where id=%s''', (id,))
     row = cursor.fetchone()
     cursor and cursor.close()
     if row:
         id, endpoints, counters, time_ = row
         endpoint_list = endpoints and endpoints.split(ENDPOINT_DELIMITER) or []
         counter_list = counters and counters.split(ENDPOINT_DELIMITER) or []
         return cls(id, endpoint_list, counter_list, time_)
     else:
         return None
Example #12
0
 def get(cls, id):
     cursor = db_conn.execute('''select id, title, hosts, counters, screen_id,
             timespan, graph_type, method, position
             from dashboard_graph where id=%s''', (id,))
     row = cursor.fetchone()
     cursor and cursor.close()
     if row:
         args = list(row)
         args[2] = args[2].split(ENDPOINT_DELIMITER) or []
         args[3] = args[3].split(ENDPOINT_DELIMITER) or []
         return cls(*args)
Example #13
0
 def gets_by_screen_id(cls, screen_id):
     cursor = db_conn.execute('''select id, title, hosts, counters, screen_id,
             timespan, graph_type, method, position 
             from dashboard_graph where screen_id=%s order by position''', (screen_id,))
     rows = cursor.fetchall()
     cursor and cursor.close()
     ret = []
     for row in rows:
         args = list(row)
         args[2] = args[2].split(ENDPOINT_DELIMITER) or []
         args[3] = args[3].split(ENDPOINT_DELIMITER) or []
         ret.append(cls(*args))
     return ret
Example #14
0
 def add(cls,
         title,
         hosts,
         counters,
         screen_id,
         timespan=3600,
         graph_type='h',
         method='',
         position=0):
     cursor = db_conn.execute(
         '''insert into dashboard_graph (title, hosts, counters, screen_id,
             timespan, graph_type, method, position)
             values(%s, %s, %s, %s, %s, %s, %s, %s)''',
         (title, ENDPOINT_DELIMITER.join(hosts)
          or "", ENDPOINT_DELIMITER.join(counters)
          or "", screen_id, timespan, graph_type, method, position))
     id_ = cursor.lastrowid
     db_conn.execute(
         '''update dashboard_graph set position=%s where id=%s''',
         (id_, id_))
     db_conn.commit()
     cursor and cursor.close()
     return cls.get(id_)
Example #15
0
 def gets_by_screen_id(cls, screen_id):
     cursor = db_conn.execute(
         '''select id, title, hosts, counters, screen_id,
             timespan, graph_type, method, position 
             from dashboard_graph where screen_id=%s order by position''',
         (screen_id, ))
     rows = cursor.fetchall()
     cursor and cursor.close()
     ret = []
     for row in rows:
         args = list(row)
         args[2] = args[2].split(ENDPOINT_DELIMITER) or []
         args[3] = args[3].split(ENDPOINT_DELIMITER) or []
         ret.append(cls(*args))
     return ret
Example #16
0
 def get(cls, id):
     cursor = db_conn.execute(
         '''select id, endpoints, counters, time_ from tmp_graph where id=%s''',
         (id, ))
     row = cursor.fetchone()
     cursor and cursor.close()
     if row:
         id, endpoints, counters, time_ = row
         endpoint_list = endpoints and endpoints.split(
             ENDPOINT_DELIMITER) or []
         counter_list = counters and counters.split(
             ENDPOINT_DELIMITER) or []
         return cls(id, endpoint_list, counter_list, time_)
     else:
         return None
Example #17
0
 def add(cls, pid, name):
     cursor = db_conn.execute('''insert into dashboard_screen (pid, name) values(%s, %s)''', (pid, name))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor.close()
     return cls.get(id_)
Example #18
0
 def get(cls, id):
     cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where id=%s''', (id,))
     row = cursor.fetchone()
     cursor.close()
     return row and cls(*row)
Example #19
0
 def remove(cls, id):
     db_conn.execute("""delete from dashboard_graph where id=%s""", (id,))
     db_conn.commit()
Example #20
0
 def get_by_pid(cls, id):
     cursor = db_conn.execute("""select id, pid, name, time from dashboard_screen where pid=%s""", (id,))
     rows = cursor.fetchall()
     cursor.close()
     return [cls(*row) for row in rows]
Example #21
0
 def remove(cls, id):
     db_conn.execute('''delete from dashboard_graph where id=%s''', (id, ))
     db_conn.commit()
Example #22
0
 def get_by_pid(cls, id):
     cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where pid=%s''', (id,))
     rows = cursor.fetchall()
     cursor.close()
     return [cls(*row) for row in rows]
Example #23
0
 def update(self, pid=None, name=None):
     pid = pid or self.pid
     name = name or self.name
     db_conn.execute('''update dashboard_screen set pid=%s, name=%s where id=%s''', (pid, name, self.id))
     db_conn.commit()
     return DashboardScreen.get(self.id)
Example #24
0
 def add(cls, pid, name):
     cursor = db_conn.execute('''insert into dashboard_screen (pid, name) values(%s, %s)''', (pid, name))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor.close()
     return cls.get(id_)
Example #25
0
 def remove(cls, id):
     db_conn.execute('''delete from dashboard_screen where id=%s''', (id,))
     db_conn.commit()
Example #26
0
 def update(self, pid=None, name=None):
     pid = pid or self.pid
     name = name or self.name
     db_conn.execute('''update dashboard_screen set pid=%s, name=%s where id=%s''', (pid, name, self.id))
     db_conn.commit()
     return DashboardScreen.get(self.id)
Example #27
0
 def get(cls, id):
     cursor = db_conn.execute('''select id, pid, name, time from dashboard_screen where id=%s''', (id,))
     row = cursor.fetchone()
     cursor.close()
     return row and cls(*row)