{
    "code_name": "nmap_services",
    "unique_prefix": "NMAPSRV",
    "enabled": true,    
    "data_source":  "pialert-db-query",
    "data_filters": [
        {
            "compare_column" : "ForeignKey",
            "compare_operator" : "==",
            "compare_field_id": "txtMacFilter",
            "compare_js_template": "'{value}.toString()'", 
            "compare_use_quotes": true 
        }
    ],
    "localized": ["display_name", "description", "icon"],
    "display_name" : [{
        "language_code":"en_us",
        "string" : "Services (NMAP)"
    }],
    "icon":[{
        "language_code":"en_us",
        "string" : "<i class=\"fa-solid fa-satellite-dish\"></i>"
    }],     
    "description": [{
        "language_code":"en_us",
        "string" : "This plugin shows all services discovered by NMAP scans."
    }],
    "params" : [],  
    "database_column_definitions":
    [          
        {
            "column": "Index",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "N/A"
                }]
        } ,
        {
            "column": "Plugin",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "N/A"
                }]
        },
        {
            "column": "Object_PrimaryID",
            "css_classes": "col-sm-2",
            "show": true,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Device name"
                }]
        },
        {
            "column": "Object_SecondaryID",
            "css_classes": "col-sm-2",
            "show": true,
            "type": "url",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Ip and Port"
                }]
        } ,
        {
            "column": "DateTimeCreated",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Created"
                }]
        },
        {
            "column": "DateTimeChanged",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Changed"
                }]
        },
        {
            "column": "Watched_Value1",
            "css_classes": "col-sm-1",
            "show": true,
            "type": "label",            
            "default_value":"",
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Service"
                }]
        },
        {
            "column": "Watched_Value2",
            "css_classes": "col-sm-1",
            "show": true,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "State"
                }]
        },
        {
            "column": "Watched_Value3",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "N/A"
                }]
        } ,
        {
            "column": "Watched_Value4",
            "css_classes": "col-sm-2",
            "show": false,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "N/A"
                }]
        } ,       
        {
            "column": "Extra",
            "css_classes": "col-sm-3",
            "show": true,
            "type": "label",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Extra"
                }]
        },       
        {
            "column": "ForeignKey",
            "css_classes": "col-sm-2",
            "show": true,
            "type": "devicemac",            
            "default_value":"",
            "options": [],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "MAC"
                }]
        },        
        {
            "column": "Status",
            "css_classes": "col-sm-1",
            "show": true,
            "type": "replace",            
            "default_value":"",
            "options": [
                {
                    "equals": "watched-not-changed",
                    "replacement": "<div style='text-align:center'><i class='fa-solid fa-square-check'></i><div></div>"
                },
                {
                    "equals": "watched-changed",
                    "replacement": "<div style='text-align:center'><i class='fa-solid fa-triangle-exclamation'></i></div>"
                },
                {
                    "equals": "new",
                    "replacement": "<div style='text-align:center'><i class='fa-solid fa-circle-plus'></i></div>"
                }
            ],
            "localized": ["name"],
            "name":[{
                "language_code":"en_us",
                "string" : "Status"
                }]
        }            
    ],
    "settings":[
        {
            "function": "RUN",            
            "type": "text.select",            
            "default_value":"disabled",
            "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
            "localized": ["name", "description"],
            "name" :[{
                "language_code":"en_us",
                "string" : "When to run"
            }],
            "description": [{
                "language_code":"en_us",
                "string" : "Specify when the SQL query is executed."
            }]
        },
        {
            "function": "CMD",
            "type": "text",
            "default_value":"SELECT  ns.MAC as Object_PrimaryID, cast('http://' || dv.dev_LastIP as VARCHAR(100)) || ':' || cast( SUBSTR(ns.Port ,0, INSTR(ns.Port , '/')) as VARCHAR(100)) as Object_SecondaryID,  datetime() as DateTime,  ns.Service as Watched_Value1, ns.State as Watched_Value2, dv.dev_Name as Watched_Value3,        'null' as Watched_Value4,        ns.Extra as Extra, ns.MAC as ForeignKey FROM (SELECT * FROM Nmap_Scan) ns left JOIN (SELECT dev_Name, dev_MAC, dev_LastIP FROM Devices) dv  ON ns.MAC = dv.dev_MAC",
            "options": [],
            "localized": ["name", "description"],
            "name" : [{
                "language_code":"en_us",
                "string" : "SQL to run"
            }],
            "description": [{
                "language_code":"en_us",
                "string" : "This SQL query is used to populate the coresponding UI tables under the Plugins section."
            }]
        },
        {
            "function": "RUN_SCHD",
            "type": "text",
            "default_value":"0 2 * * *",
            "options": [],
            "localized": ["name", "description"],
            "name" : [{
                "language_code":"en_us",
                "string" : "Schedule"
            }],
            "description": [{
                "language_code":"en_us",
                "string" : "Only enabled if you select <code>schedule</code> in the <a href=\"#NMAPSRV_RUN\"><code>NMAPSRV_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
            }]
        },
        {
            "function": "WATCH",
            "type": "text.multiselect",
            "default_value":["Watched_Value1"],
            "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
            "localized": ["name", "description"],
            "name" :[{
                "language_code":"en_us",
                "string" : "Watched"
            }] ,
            "description":[{
                "language_code":"en_us",
                "string" : "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is service type (e.g.: http, ssh)</li><li><code>Watched_Value2</code> is Status (open or closed)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
            }] 
        },
        {
            "function": "REPORT_ON",
            "type": "text.multiselect",
            "default_value":["new","watched-changed"],
            "options": ["new","watched-changed","watched-not-changed"],
            "localized": ["name", "description"],
            "name" :[{
                "language_code":"en_us",
                "string" : "Report on"
            }] ,
            "description":[{
                "language_code":"en_us",
                "string" : "Send a notification only on these statuses. <code>new</code> means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. <code>watched-changed</code> means that selected <code>Watched_ValueN</code> columns changed."
            }] 
        }
    ]
}

