Exemple #1
0
    def save(self):
        cmds = []
        cmds.append("services sp auto-config interface rules add \"%s\"" % self.name)
        cmds.append("services sp auto-config interface rules edit \"%s\" description set \"%s\"" % (self.name, self.description))
        cmds.append("services sp auto-config interface rules edit \"%s\" precedence set %s" % (self.name, self.precedence))

        if self.action_type:
            cmds.append("services sp auto-config interface rules edit \"%s\" action type enable" % self.name)
            cmds.append("services sp auto-config interface rules edit \"%s\" type set %s" % (self.name, self.action_set_type))
        else:
            cmds.append("services sp auto-config interface rules edit \"%s\" action type disable" % self.name)

        if self.action_asns:
            cmds.append("services sp auto-config interface rules edit \"%s\" action asns enable" % self.name)
            cmds.append("services sp auto-config interface rules edit \"%s\" peers set %s" % (self.name, self.action_set_asn))
        else:
            cmds.append("services sp auto-config interface rules edit \"%s\" action asns disable" % self.name)

        if self.action_set_mo:
            cmds.append("services sp auto-config interface rules edit \"%s\" action managed_objects enable" % self.name)
            cmds.append("services sp auto-config interface rules edit \"%s\" managed_objects type set %s" % (self.name, self.action_set_mo_type))
            for mo in self.action_set_mos:
                cmds.append("services sp auto-config interface rules edit \"%s\" managed_objects add \"%s\"" % (self.name, mo))
        else:
            cmds.append("services sp auto-config interface rules edit \"%s\" managed_objects clear" % self.name)

        cmds.append("services sp auto-config interface rules edit \"%s\" regexp set \"%s\"" % (self.name, self.match_intf_desc_regex))

        pf = PeakflowSOAP(self.co)
        for cmd in cmds:
            res = pf.cliRun(cmd)
        return res
Exemple #2
0
 def from_peakflow(cls, co):
     """
     """
     pf = PeakflowSOAP(co)
     config = pf.cliRun("config show")
     mos = cls.from_conf(config['results'])
     for mo in mos:
         mo.co = co
     return mos
Exemple #3
0
    def save(self):
        # TODO: implement support for parents..
        cmds = []
        cmds.append("services sp managed_objects add \"%s\"" % self.name)
        for tag in self.tags:
            cmds.append(
                "services sp managed_objects edit \"%s\" tags add \"%s\"" %
                (self.name, tag))
        cmds.append(
            "services sp managed_objects edit \"%s\" description set \"%s\"" %
            (self.name, self.description))
        cmds.append(
            "services sp managed_objects edit \"%s\" family set \"%s\"" %
            (self.name, self.family))
        cmds.append("services sp managed_objects edit \"%s\" match set %s" %
                    (self.name, self.match.get_conf()))

        pf = PeakflowSOAP(self.co)
        for cmd in cmds:
            res = pf.cliRun(cmd)
        return res
Exemple #4
0
    def from_id(cls, co, alert_id):
        a = Alert()

        pf = PeakflowSOAP(co)

        # get XML from peakflow
        res = pf.getDosAlertSummariesXML(alert_id)
        # XML to python
        root = objectify.fromstring(res.encode('utf-8'))

        # extract values
        a.direction = root.alert.direction
        a.type = root.alert.get('type')
        a.destination = root.alert.resource.ip
        try:
            a.attack_start = datetime.fromtimestamp(
                int(root.alert.duration.get('start')))
        except:
            pass
        try:
            a.attack_stop = datetime.fromtimestamp(
                int(root.alert.duration.get('stop')))
        except:
            pass
        a.ongoing = bool(root.alert.duration.get('ongoing'))
        a.duration = int(root.alert.duration.get('length'))
        a.target_mo = root.alert.resource.managed_object.get('name')
        a.target_mo_id = root.alert.resource.managed_object.get('gid')
        try:
            a.protocol = root.alert.protocol
        except:
            pass
        try:
            a.impact_bps = root.alert.impact.get('bps')
        except:
            pass
        try:
            a.impact_pps = root.alert.impact.get('pps')
        except:
            pass
        a.threshold = root.alert.severity.get('threshold')
        a.threshold_unit = root.alert.severity.get('unit')

        try:
            for annotation in root.alert['annotation-list'].iterchildren():
                m = re.match("TMS mitigation '([^']+)' (started|stopped)",
                             str(annotation.content))
                if m is not None:
                    a.mitigation_name = m.group(1)
                    if m.group(2) == 'started':
                        a.mitigation_start = datetime.fromtimestamp(
                            int(annotation.added))
                    if m.group(2) == 'stopped':
                        a.mitigation_stop = datetime.fromtimestamp(
                            int(annotation.added))
        except:
            pass

        res = client.service.getDosAlertDetailsXML(alert_id)
        root = objectify.fromstring(res.encode('utf-8'))
        for item in root['sample-list']:
            if item.get('name') is None:
                continue

            for prefix in item.prefixes.find('prefix'):
                if prefix.get('is_dst') == "0":
                    a.sources.append(prefix.get('cidr'))

        return a
Exemple #5
0
 def __init__(self):
     self.pf = PeakflowSOAP()
Exemple #6
0
                      "--password",
                      help="password for SOAP API connection")
    parser.add_option("--customer-id",
                      metavar="ID",
                      help="get a graph for customer with id ID")
    parser.add_option("--output-file",
                      metavar="FILE",
                      help="write output to FILE")
    parser.add_option("--mo-type", help="MO type")
    parser.add_option("--mo-id", help="MO id")
    parser.add_option("--filter", help="Filter by [nexthop]")
    parser.add_option("--graph-title", help="title of the graph")
    parser.add_option("--graph", help="fetch data and write a graph")
    parser.add_option("--table", help="fetch data and print in tabular form")
    (options, args) = parser.parse_args()

    pf = PeakflowSOAP(options.host, options.username, options.password)

    if options.graph and not options.output_file:
        print >> sys.stderr, "Please provide an output file to write the graph to with --output-file"
        sys.exit(1)

    f = Report()
    if options.graph:
        f.get_graph(options.output_file, options.mo_type, options.mo_id,
                    options.graph_title, options.filter, 1)

    if options.table:
        print f.get_table(options.output_file, options.mo_type, options.mo_id,
                          options.graph_title, options.filter, 1)