class PoolForm(BaseForm): template = "pool" form_type = HiddenField(default="pool") id = HiddenField() name = StringField("Name", [InputRequired()]) description = StringField("Description") longitude = StringField("Longitude", default=0.0) latitude = StringField("Latitude", default=0.0) operator = SelectField( "Type of match", choices=( ("all", "Match if all properties match"), ("any", "Match if any property matches"), ), ) manually_defined = BooleanField( "Manually defined (won't be automatically updated)")
class SegmentForm(FlaskForm): segment_type = SelectField("Next Node Type", choices=( ("address ipv4", "Specify hop address"), ("mpls label", "MPLS configuration"), ), default="address") value = StringField()
class RestCallForm(ServiceForm): form_type = HiddenField(default="rest_call_service") call_type = SelectField(choices=( ("GET", "GET"), ("POST", "POST"), ("PUT", "PUT"), ("DELETE", "DELETE"), ("PATCH", "PATCH"), )) rest_url = StringField(substitution=True) payload = DictField(json_only=True, substitution=True) params = DictField(substitution=True) headers = DictField(substitution=True) verify_ssl_certificate = BooleanField("Verify SSL Certificate") timeout = IntegerField(default=15) username = StringField() password = PasswordField()
class ResultLogDeletionForm(BaseForm): action = "eNMS.administration.resultLogDeletion" form_type = HiddenField(default="result_log_deletion") deletion_types = SelectMultipleField( "Instances do delete", choices=[("run", "result"), ("changelog", "changelog")], ) date_time = StringField(type="date", label="Delete Records before")
class WorkflowLabelForm(BaseForm): form_type = HiddenField(default="workflow_label") action = "eNMS.workflow.createLabel" text = StringField(widget=TextArea(), render_kw={"rows": 15}) alignment = SelectField( "Text Alignment", choices=(("left", "Left"), ("center", "Center"), ("right", "Right")), )
class UnixShellScriptForm(NetmikoForm): form_type = HiddenField(default="unix_shell_script_service") enable_mode = BooleanField("Run as root using sudo") config_mode = BooleanField("Config mode") source_code = StringField( widget=TextArea(), render_kw={"rows": 15}, default=("#!/bin/bash\n" "# The following example shell script returns" " 0 for success; non-zero for failure\n" "directory_contents=`ls -al /root` # Needs privileged mode\n" "return_code=$?\n" "if [ $return_code -ne 0 ]; then\n" " exit $return_code # Indicating Failure\n" "else\n" ' echo -e "$directory_contents"\n' " exit 0 # Indicating Success\n" "fi\n"), ) driver = SelectField(choices=app.NETMIKO_DRIVERS, default="linux") use_device_driver = BooleanField(default=True) fast_cli = BooleanField() timeout = IntegerField(default=10) delay_factor = FloatField(default=1.0) global_delay_factor = FloatField(default=1.0) expect_string = StringField(substitution=True) auto_find_prompt = BooleanField(default=True) strip_prompt = BooleanField(default=True) strip_command = BooleanField(default=True) groups = { "Main Parameters": { "commands": ["source_code"], "default": "expanded" }, "Advanced Netmiko Parameters": { "commands": [ "expect_string", "auto_find_prompt", "strip_prompt", "strip_command", ], "default": "hidden", }, **NetmikoForm.groups, }
class PingForm(ServiceForm): form_type = HiddenField(default="ping_service") protocol = SelectField(choices=(("ICMP", "ICMP Ping"), ("TCP", "TCP Ping"))) ports = StringField() count = IntegerField(default=5) timeout = IntegerField(default=2) ttl = IntegerField(default=60) packet_size = IntegerField(default=56)
class NetmikoPromptsForm(NetmikoForm): form_type = HiddenField(default="netmiko_prompts_service") command = StringField(substitution=True) confirmation1 = StringField(substitution=True) response1 = StringField(substitution=True) confirmation2 = StringField(substitution=True) response2 = StringField(substitution=True) confirmation3 = StringField(substitution=True) response3 = StringField(substitution=True) groups = { "Main Parameters": { "commands": [ "command", "confirmation1", "response1", "confirmation2", "response2", "confirmation3", "response3", ], "default": "expanded", }, **NetmikoForm.groups, }
class MailNotificationForm(ServiceForm): form_type = HiddenField(default="mail_notification_service") title = StringField(substitution=True) sender = StringField() recipients = StringField() body = StringField(widget=TextArea(), render_kw={"rows": 5}, substitution=True) def validate(self): valid_form = super().validate() for field in ("title", "sender", "recipients", "body"): if not getattr(self, field).data: getattr( self, field).errors.append(f"{field.capitalize()} is missing.") valid_form = False return valid_form
class VlanConfigurationForm(NapalmForm): form_type = HiddenField(default="vlan_configuration_service") action = SelectField( choices=( ("load_merge_candidate", "Load merge"), ("load_replace_candidate", "Load replace"), ) ) interface_name = StringField(validators=[InputRequired()]) vlan_id = IntegerField(validators=[NumberRange(min=10, max=4000)]) description = StringField() vrf = StringField() qos = StringField() ipv4s = FieldList(FormField(Ipv4Form), min_entries=5) ipv6s = FieldList(FormField(Ipv6Form), min_entries=5) shutdown = SelectField( choices=( ("yes", "yes"), ("no", "no"), ), default="no" ) groups = { "Main Parameters": { "commands": [ "action", "interface_name", "vlan_id", "description", "vrf", "qos", "shutdown" ], "default": "expanded" }, "IPv4 address Parameters": { "commands": ["ipv4s"], "default": "expanded", }, "IPv6 address Parameters": { "commands": ["ipv6s"], "default": "expanded", }, **NapalmForm.groups, }
class PayloadExtractionForm(ServiceForm): form_type = HiddenField(default="payload_extraction_service") variable1 = StringField("Variable Name") query1 = StringField("Python Extraction Query", python=True) match_type1 = SelectField("Post Processing", choices=match_choices) match1 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation1 = SelectField("Operation", choices=operation_choices) variable2 = StringField("Variable Name") query2 = StringField("Python Extraction Query", python=True) match_type2 = SelectField("Post Processing", choices=match_choices) match2 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation2 = SelectField("Operation", choices=operation_choices) variable3 = StringField("Variable Name") query3 = StringField("Python Extraction Query", python=True) match_type3 = SelectField("Post Processing", choices=match_choices) match3 = StringField( "Regular Expression / TextFSM Template Text", widget=TextArea(), render_kw={"rows": 5}, ) operation3 = SelectField("Operation", choices=operation_choices) groups = { "Extraction 1": { "commands": ["variable1", "query1", "match_type1", "match1", "operation1"], "default": "expanded", }, "Extraction 2": { "commands": ["variable2", "query2", "match_type2", "match2", "operation2"], "default": "expanded", }, "Extraction 3": { "commands": ["variable3", "query3", "match_type3", "match3", "operation3"], "default": "expanded", }, }
class AnsiblePlaybookForm(ServiceForm): form_type = HiddenField(default="ansible_playbook_service") playbook_path = SelectField("Playbook Path", choices=(), validation=False) arguments = StringField("Arguments (Ansible command line options)", substitution=True) pass_device_properties = BooleanField( "Pass Device Inventory Properties (to be used " "in the playbook as {{name}} or {{ip_address}})") options = DictField("Options (passed to ansible as -e extra args)", substitution=True)
class AddServiceForm(BaseForm): form_type = HiddenField(default="add_services") template = "add_services" mode = SelectField( "Mode", choices=( ("deep", "Deep Copy (creates a duplicate from the service)"), ("shallow", "Shallow Copy (creates a reference to the service)"), ), ) search = StringField()
class DeviceConnectionForm(BaseForm): template = "device_connection" form_type = HiddenField(default="device_connection") address_choices = [("ip_address", "IP address"), ("name", "Name")] + [ (property, values["pretty_name"]) for property, values in app.properties["custom"]["device"].items() if values.get("is_address", False) ] address = SelectField(choices=address_choices) username = StringField("Username") password = PasswordField("Password")
class TaskForm(BaseForm): template = "object" form_type = HiddenField(default="task") id = HiddenField() scheduling_mode = SelectField( "Scheduling Mode", choices=(("cron", "Crontab Scheduling"), ("standard", "Standard Scheduling")), ) name = StringField("Name", [InputRequired()]) description = StringField("Description") start_date = StringField("Start Date", type="date") end_date = StringField("End Date", type="date") frequency = IntegerField("Frequency", default=0) frequency_unit = SelectField( "Frequency Unit", choices=( ("seconds", "Seconds"), ("minutes", "Minutes"), ("hours", "Hours"), ("days", "Days"), ), ) crontab_expression = StringField("Crontab Expression") initial_payload = DictField("Payload") def validate(self): valid_form = super().validate() no_date = self.scheduling_mode.data == "standard" and not self.start_date.data if no_date: self.start_date.errors.append("A start date must be set.") no_cron_expression = (self.scheduling_mode.data == "cron" and not self.crontab_expression.data) if no_cron_expression: self.crontab_expression.errors.append( "A crontab expression must be set.") no_service = not self.service.data if no_service: self.service.errors.append("No service set.") return valid_form and not any( [no_date, no_cron_expression, no_service])
class PoolForm(BaseForm): template = "pool" form_type = HiddenField(default="pool") id = HiddenField() name = StringField("Name", [InputRequired()]) admin_only = BooleanField("Pool visible to admin users only") access_groups = StringField("Groups") description = StringField("Description") operator = SelectField( "Type of match", choices=( ("all", "Match if all properties match"), ("any", "Match if any property matches"), ), ) manually_defined = BooleanField( "Manually defined (won't be automatically updated)") @classmethod def form_init(cls): cls.models = ("device", "link", "service", "user") for model in cls.models: setattr(cls, f"{model}_properties", app.properties["filtering"][model]) for property in app.properties["filtering"][model]: setattr(cls, f"{model}_{property}", StringField(property)) setattr(cls, f"{model}_{property}_invert", BooleanField(property)) form_properties["pool"][f"{model}_{property}_invert"] = { "type": "bool" } setattr( cls, f"{model}_{property}_match", SelectField(choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), )), )
class DeviceForm(ObjectForm): template = "object" form_type = HiddenField(default="device") id = HiddenField() icon = SelectField( "Icon", choices=( ("antenna", "Antenna"), ("firewall", "Firewall"), ("host", "Host"), ("optical_switch", "Optical switch"), ("regenerator", "Regenerator"), ("router", "Router"), ("server", "Server"), ("switch", "Switch"), ), ) ip_address = StringField("IP address") port = IntegerField("Port", default=22) operating_system = StringField("Operating System") os_version = StringField("OS Version") longitude = StringField("Longitude", default=0.0) latitude = StringField("Latitude", default=0.0) username = StringField("Username") password = PasswordField("Password") enable_password = PasswordField("'Enable' Password") napalm_driver = SelectField("NAPALM Driver", choices=app.NAPALM_DRIVERS, default="ios") netmiko_driver = SelectField("Netmiko Driver", choices=app.NETMIKO_DRIVERS, default="cisco_ios") scrapli_driver = SelectField("Scrapli Driver", choices=choices(app.SCRAPLI_DRIVERS), default="cisco_iosxe")
class TopologyImportForm(ServiceForm): form_type = HiddenField(default="topology_import_service") import_type = SelectField(choices=( ("librenms", "LibreNMS"), ("netbox", "Netbox"), ("opennms", "OpenNMS"), )) netbox_address = StringField(default="http://0.0.0.0:8000") netbox_token = PasswordField() opennms_address = StringField() opennms_devices = StringField() opennms_login = StringField() opennms_password = PasswordField() librenms_address = StringField(default="http://librenms.example.com") librenms_token = PasswordField() groups = { "Type of Import": { "commands": ["import_type"], "default": "expanded" }, "Netbox": { "commands": ["netbox_address", "netbox_token"], "default": "expanded", }, "OpenNMS": { "commands": [ "opennms_address", "opennms_devices", "opennms_login", "opennms_password", ], "default": "expanded", }, "LibreNMS": { "commands": ["librenms_address", "librenms_token"], "default": "expanded", }, }
class EventForm(BaseForm): template = "event" form_type = HiddenField(default="event") id = HiddenField() name = StringField("Name", [InputRequired()]) @classmethod def form_init(cls): cls.configure_relationships("service") cls.properties = ("log_source", "log_content") for property in ("log_source", "log_content"): setattr(cls, property, StringField(property)) setattr(cls, property + "_regex", BooleanField("Regex"))
class NapalmConfigurationForm(NapalmForm): form_type = HiddenField(default="napalm_configuration_service") action = SelectField( choices=( ("load_merge_candidate", "Load merge"), ("load_replace_candidate", "Load replace"), ) ) content = StringField(widget=TextArea(), render_kw={"rows": 5}, substitution=True) groups = { "Main Parameters": {"commands": ["action", "content"], "default": "expanded"}, **NapalmForm.groups, }
class NetmikoValidationForm(NetmikoForm): form_type = HiddenField(default="netmiko_validation_service") command = StringField(substitution=True) expect_string = StringField(substitution=True, help="netmiko/expect_string") auto_find_prompt = BooleanField(default=True, help="netmiko/auto_find_prompt") strip_prompt = BooleanField(default=True, help="netmiko/strip_prompt") strip_command = BooleanField(default=True, help="netmiko/strip_command") use_genie = BooleanField(default=False) groups = { "Main Parameters": {"commands": ["command"], "default": "expanded"}, **NetmikoForm.groups, "Advanced Netmiko Parameters": { "commands": [ "expect_string", "auto_find_prompt", "strip_prompt", "strip_command", "use_genie", ], "default": "hidden", }, }
class ObjectForm(BaseForm): form_type = HiddenField(default="object") name = StringField("Name", [InputRequired()]) description = StringField("Description") subtype = StringField("Subtype") location = StringField("Location") vendor = StringField("Vendor") model = StringField("Model")
class ObjectForm(BaseForm): action = "eNMS.base.processData" form_type = HiddenField(default="object") get_request_allowed = False id = HiddenField() name = StringField("Name", [InputRequired()]) access_groups = StringField("Groups") description = StringField("Description") subtype = StringField("Subtype") location = StringField("Location") vendor = StringField("Vendor") model = StringField("Model")
class ConfigureBgpForm(NapalmForm): form_type = HiddenField(default="configure_bgp_service") local_as = IntegerField("Local AS", default=0) loopback = StringField("Loopback", default="Lo42") loopback_ip = StringField("Loopback IP") neighbor_ip = StringField("Neighbor IP") remote_as = IntegerField("Remote AS") vrf_name = StringField("VRF Name") groups = { "Main Parameters": { "commands": [ "local_as", "loopback", "loopback_ip", "neighbor_ip", "remote_as", "vrf_name", ], "default": "expanded", }, **NapalmForm.groups, }
class CredentialForm(BaseForm): action = "eNMS.base.processData" form_type = HiddenField(default="credential") id = HiddenField() name = StringField("Name", [InputRequired()]) description = StringField(widget=TextArea(), render_kw={"rows": 13}) role = SelectField( "Role", choices=( ("read-write", "Read Write"), ("read-only", "Read Only"), ), ) subtype = SelectField("Type", choices=(("password", "Username / Password"), ("key", "SSH Key"))) device_pools = MultipleInstanceField("Devices", model="pool") user_pools = MultipleInstanceField("Users", model="pool") priority = IntegerField("Priority", default=1) username = StringField("Username") enable_password = PasswordField("'Enable' Password") password = PasswordField("Password") private_key = StringField(widget=TextArea(), render_kw={"rows": 10})
class GenericFileTransferForm(ServiceForm): form_type = HiddenField(default="generic_file_transfer_service") direction = SelectField(choices=(("get", "Get"), ("put", "Put"))) protocol = SelectField(choices=(("scp", "SCP"), ("sftp", "SFTP"))) source_file = StringField(validators=[InputRequired()], substitution=True) destination_file = StringField(validators=[InputRequired()], substitution=True) missing_host_key_policy = BooleanField() load_known_host_keys = BooleanField() look_for_keys = BooleanField() source_file_includes_globbing = BooleanField( "Source file includes glob pattern") max_transfer_size = IntegerField(default=2**30) window_size = IntegerField(default=2**30) timeout = FloatField(default=10.0) def validate(self): valid_form = super().validate() invalid_direction = (self.source_file_includes_globbing.data and self.direction.data == "get") if invalid_direction: self.direction.errors.append( "Globbing only works with the 'PUT' direction") return valid_form and not invalid_direction
class ChangelogForm(BaseForm): template = "object" form_type = HiddenField(default="changelog") id = HiddenField() severity = SelectField( "Severity", choices=( ("debug", "Debug"), ("info", "Info"), ("warning", "Warning"), ("error", "Error"), ("critical", "Critical"), ), ) content = StringField(widget=TextArea(), render_kw={"rows": 10})
class UserForm(RbacForm): form_type = HiddenField(default="user") groups = StringField("Groups") theme = SelectField( "Theme", choices=[(theme, values["name"]) for theme, values in themes["themes"].items()], ) authentication = SelectField( "Authentication", choices=[(method, values["display_name"]) for method, values in settings["authentication"]["methods"].items()], ) password = PasswordField("Password") is_admin = BooleanField(default=False)
def filtering_form_generator(): for form_type in models: properties, relations = app.properties["filtering"].get(form_type, []), {} for model, relation in relationships[form_type].items(): if model in ("edges", "results"): continue relations[model] = MultipleInstanceField(model) relationships[f"{form_type}_filtering"][model] = relation relationships[f"{form_type}_relation_filtering"][model] = relation relation_form = { "template": "filtering", "properties": sorted(relations), "object_type": form_type, "form_type": HiddenField(default=f"{form_type}_relation_filtering"), **{ **relations, **{ f"{relation}_filter": SelectField(choices=( ("any", "Any"), ("all", "All"), ("not_any", "Unrelated"), ("none", "None"), )) for relation in relations }, }, } type(f"{form_type}RelationshipFilteringForm", (BaseForm, ), relation_form) form = deepcopy(relation_form) form.update({ "form_type": HiddenField(default=f"{form_type}_filtering"), "properties": sorted(properties) + sorted(relations), **{property: StringField() for property in properties}, **{ f"{property}_filter": SelectField(choices=( ("inclusion", "Inclusion"), ("equality", "Equality"), ("regex", "Regular Expression"), )) for property in properties }, }) type(f"{form_type}FilteringForm", (BaseForm, ), form)
class PythonSnippetForm(ServiceForm): form_type = HiddenField(default="python_snippet_service") source_code = StringField( type="code", python=True, widget=TextArea(), render_kw={ "rows": 15, "help": "python_snippet/source_code" }, default=""" # Click on "i" to right of "Source Code" for examples. result = {} results["success"] = True results["result"] = result""", )