コード例 #1
0
class AlarmClass(db.Model):

    """告警类型表"""

    __tablename__ = 'alarm_classes'

    id = db.Column(db.Integer, primary_key=True)
    category_id = db.Column(db.Integer, db.ForeignKey('categories.id'))
    name = db.Column(db.String(60))
    alias = db.Column(db.String(60))
    severity = db.Column(db.Integer)
    probable_cause = db.Column(db.String(200))
    specific_problem = db.Column(db.String(200))
    additional_info = db.Column(db.String(200))
    remark = db.Column(db.String(100))
    created_at = db.Column(db.DateTime)
    updated_at  = db.Column(db.DateTime)

    category    = db.relation('Category')


    def __repr__(self):
        return '<AlarmClass %r>' % self.name

    def __unicode__(self):
        return u'<告警类型 %s>'% self.alias
コード例 #2
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class Area(db.Model):
    """
    Area Table
    """
    __tablename__ = 'areas'
    id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer, db.ForeignKey('areas.id'))
    dn = db.Column(db.String(100))
    name = db.Column(db.String(50))
    alias = db.Column(db.String(100))
    area_type = db.Column(db.Integer)
    longitude = db.Column(db.Float)
    latitude = db.Column(db.Float)
    address = db.Column(db.String(100))
    order_seq = db.Column(db.Integer)
    managed_status = db.Column(db.Integer)
    entrance_type = db.Column(db.Integer)
    sub_type = db.Column(db.Integer)
    entrance_level = db.Column(db.Integer)
    check_state = db.Column(db.Integer)
    entrance = db.Column(db.Integer)
    entrance_name = db.Column(db.String(50))
    branch = db.Column(db.Integer)
    branch_name = db.Column(db.String(50))
    town = db.Column(db.Integer)
    town_name = db.Column(db.String(50))
    cityid = db.Column(db.Integer)
    city_name = db.Column(db.String(50))
    remark = db.Column(db.String(50))
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime, default=datetime.now)

    children = db.relation(
        'Area',
        backref=backref("parent", remote_side=id),
    )

    @hybrid_property
    def full_name(self):
        name_list = [
            self.city_name, self.town_name, self.branch_name,
            self.entrance_name
        ]
        fname = ' / '.join([name for name in name_list if name])
        return self.name if fname == '' else fname

    def __unicode__(self):
        return u'<区域 %r>' % self.alias
コード例 #3
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class SysOid(db.Model):
    """设备系统OID"""

    __tablename__ = 'sysoids'

    id = db.Column(db.Integer, primary_key=True)
    sysoid = db.Column(db.String(100))
    model_id = db.Column(db.Integer, db.ForeignKey('models.id'))
    disco = db.Column(db.String(20))  # 发现模块
    mib = db.Column(db.String(20))  # mib文件, 从 miboids.mib 中选
    remark = db.Column(db.String(100))

    model = db.relation('Model')

    def __unicode__(self):
        return u'<SysOid %s>' % self.sysoid
コード例 #4
0
class AlarmKnowledge(db.Model):

    __tablename__ = 'alarm_knowledges'

    id              = db.Column(db.Integer, primary_key=True)
    class_id        = db.Column(db.Integer, db.ForeignKey("alarm_classes.id"))
    probable_cause  = db.Column(db.String(200))
    resolvent       = db.Column(db.String(200))
    probability     = db.Column(db.Integer)
    apply_count     = db.Column(db.Integer)
    created_at      = db.Column(db.DateTime)
    updated_at      = db.Column(db.DateTime)

    alarm_class     = db.relation('AlarmClass')

    def __unicode__(self):
        return u'<告警知识库 %s>'% self.alarm_alias
コード例 #5
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class Monitor(db.Model):
    """监控器表"""

    __tablename__ = 'monitors'

    id = db.Column(db.Integer, primary_key=True)
    category = db.Column(db.String(20))  # 分类, 不关联
    vendor = db.Column(db.String(20))  # 厂商,
    sysoid = db.Column(db.String(100))  # 不关联
    match = db.Column(db.String(100))  # 匹配规则
    modid = db.Column(db.Integer, db.ForeignKey('modules.id'))
    mib = db.Column(db.String(20))
    remark = db.Column(db.String(100))

    module = db.relation('Module')

    def __unicode__(self):
        return u'<监控器>'
コード例 #6
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class Role(db.Model):

    """角色表"""

    __tablename__ = 'roles'

    id          = db.Column(db.Integer, primary_key=True)
    name        = db.Column(db.String(50), unique=True)
    description = db.Column(db.String(100))
    created_at  = db.Column(db.DateTime, default=datetime.now)
    updated_at  = db.Column(db.DateTime, default=datetime.now)

    permissions = db.relation('Permission', backref="roles", secondary=roles_permissions)

    def __repr__(self):
        return '<Role%r>' % self.name

    def __unicode__(self):
        return u'<角色 %s>' % self.name
コード例 #7
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class Model(db.Model):
    """设备型号"""
    __tablename__ = 'models'
    id = db.Column(db.Integer, primary_key=True)
    cityid = db.Column(db.Integer)
    category_id = db.Column(db.Integer, db.ForeignKey("categories.id"))
    object = db.Column(db.String(100))  # 不要
    name = db.Column(db.String(100))
    alias = db.Column(db.String(100))
    sysoid = db.Column(db.String(100))
    vendor_id = db.Column(db.Integer, db.ForeignKey("vendors.id"))
    fttx = db.Column(db.Integer)  # 不要
    control_slot_num = db.Column(db.Integer)  # 不要
    business_slot_num = db.Column(db.Integer)  # 不要
    is_valid = db.Column(db.Integer)
    remark = db.Column(db.String(100))

    category = db.relation('Category')

    def __unicode__(self):
        return u'<型号 %s>' % self.alias
コード例 #8
0
class Alarm(db.Model):
    
    """告警表"""

    __tablename__ = 'alarms'

    id                      = db.Column(db.Integer, primary_key=True)
    alarm_key               = db.Column(db.String(200))
    class_id                = db.Column(db.Integer, db.ForeignKey('alarm_classes.id'))
    alarm_name              = db.Column(db.String(60))
    alarm_alias             = db.Column(db.String(200))
    alarm_state             = db.Column(db.Integer)
    manager                 = db.Column(db.String(60))   
    agent                   = db.Column(db.String(60))  
    node_id                 = db.Column(db.Integer, db.ForeignKey('nodes.id')) 
    #node_class              = db.Column(db.Integer) 
    #node_alias              = db.Column(db.String(200))  
    #node_addr               = db.Column(db.String(100))  
    #node_managed_state      = db.Column(db.Integer) 
    #node_prod_state         = db.Column(db.Integer) 
    source                  = db.Column(db.String(60))
    source_class            = db.Column(db.String(60))  
    severity                = db.Column(db.Integer) 
    summary                 = db.Column(db.String(200))
    state_change            = db.Column(db.DateTime)
    first_occurrence        = db.Column(db.DateTime)
    last_occurrence         = db.Column(db.DateTime)
    occur_count             = db.Column(db.Integer) 
    priority                = db.Column(db.Integer)
    graded                  = db.Column(db.Integer) 
    location                = db.Column(db.String(100))  
    service                 = db.Column(db.String(100))  
    customer                = db.Column(db.String(100))  
    sequence_no             = db.Column(db.Integer) 
    x733_type               = db.Column(db.Integer) 
    probable_cause          = db.Column(db.String(200))  
    specific_problem        = db.Column(db.String(200)) 
    additional_information  = db.Column(db.String(200))
    proposed_repaire_action = db.Column(db.String(200))  
    acked                   = db.Column(db.Integer) 
    acked_user              = db.Column(db.String(60))   
    acked_time              = db.Column(db.DateTime) 
    acked_note              = db.Column(db.String(60))   
    cleared                 = db.Column(db.Integer) 
    cleared_user            = db.Column(db.String(60))   
    cleared_time            = db.Column(db.DateTime) 
    cleared_note            = db.Column(db.String(100)) 
    order_state             = db.Column(db.Integer) 
    root_cause              = db.Column(db.Integer) 
    cause_type              = db.Column(db.Integer) 
    extended_attrs          = db.Column(db.Text)
    created_at              = db.Column(db.DateTime) 
    updated_at              = db.Column(db.DateTime) 

    alarm_class             = db.relation('AlarmClass')
    node                    = db.relation('Node', backref=db.backref("alarms"))

    def __repr__(self):
        return '<Alarm%r>' % self.alarm_alias

    def __unicode__(self):
        return u'<当前告警 %s>'% self.alarm_alias
コード例 #9
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
 def node(cls):
     return db.relation('Node')
コード例 #10
0
ファイル: models.py プロジェクト: chinnurtb/xiaoli
 def node(cls):
     return db.relation('Node')
コード例 #11
0
ファイル: models.py プロジェクト: yordanomp/xiaoli
class User(db.Model, UserMixin):

    """用户表"""

    __tablename__ = 'users'

    id         = db.Column(db.Integer, primary_key=True)
    username   = db.Column(db.String(40), unique=True)
    name       = db.Column(db.String(40))
    email      = db.Column(db.String(60), unique=True)
    _password  = db.Column('password', db.String(60))
    signup_on  = db.Column(db.DateTime)
    role_id    = db.Column(db.Integer, db.ForeignKey('roles.id'))
    domain_id  = db.Column(db.Integer, db.ForeignKey('domains.id'))
    group_id   = db.Column(db.Integer, db.ForeignKey('user_groups.id'))
    department = db.Column(db.String(100))
    telephone  = db.Column(db.String(20))
    mobile     = db.Column(db.String(20))
    memo       = db.Column(db.String(1024))
    status     = db.Column(db.String(40))
    created_at = db.Column(db.DateTime, default=datetime.now)
    updated_at = db.Column(db.DateTime, default=datetime.now)
    expired_at = db.Column(db.DateTime, default=datetime.now)

    role   = db.relation('Role', order_by='Role.name')
    domain = db.relation('Domain')
    # group  = db.relation('UserGroup')

    def __unicode__(self):
        return u'<用户 %s>' % self.username

    def __init__(self):
        pass

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, value):
        self._password = User.create_passwd(value)

    @property
    def is_province_user(self):
        if self.domain.province_list:
            return True
        else:
            return False
        
    def gravatar_url(self, size=80):
        """Return the gravatar image for the given email address."""
        return 'http://www.gravatar.com/avatar/%s?d=identicon&s=%d' % \
            (md5(self.email.strip().lower().encode('utf-8')).hexdigest(), size)

    def __repr__(self):
        return '<User %r>' % self.username

    @staticmethod
    def create_passwd(raw):
        return md5(raw).hexdigest()        
        
    def check_passwd(self, passwd):
        if not self.password:
            return False
        # return self.password == passwd
        return self.password == User.create_passwd(passwd)

    @classmethod
    def authenticate(clazz, login, passwd):
        user = clazz.query.filter(db.or_(User.username == login, 
                                    User.email == login)).first()
        if user:
            authenticated = user.check_passwd(passwd)
        else:
            authenticated = False

        return user, authenticated