Quantcast
Channel: Symantec Connect - Articles
Viewing all articles
Browse latest Browse all 1863

Python Flask Application for GUP Server Monitoring using SEPM REST API

$
0
0

Monitoring of GUP servers for availbility fro other endpoints is critical aspect in SEPM architechture. GUP server solves the problem of high bandwidth utilization for locations with high endpoint density. on the otherhand availability of GUP servers is important as all endpoints are dependent on GUP server. 

GUP servers work on behalf of endpoints to download content from SEPM server. thus, only once for first client  GUP server need to download  content from SEPM. For all subsequent similiar content download request GUP server itself serves content to endpoints. 

To know more about GUP server refer 

http://origin-symwisedownload.symantec.com/resources/sites/SYMWISE/content/live/SOLUTIONS/139000/TECH139867/en_US/GUP_Whitepaper_1.1.pdf

Purpose of this article is to develop Python / Flask web application  for monitoring of GUP server which gives details like 

  1. GUP Servers hostname 
  2. IP Addresses 
  3. Status (Online(in Green color) or Offline(in Red color) )
  4. last Heartbeat (GMT)
  5. Antivirus Signature of GUP 
  6. SEP Group GUP belong to 

You can add other fields also based on response of REST API response 
Other informtion offered by REST API response eg. (valuses of some fields are masquereded by xxxxxx )

 {'agentVersion': '14.0.3876.1100',
  'avas': '2018-04-10 rev. 009',
  'cidsDrvOnOff': '1',
  'computerDomainName': 'xxxxxxxxxxx',
  'computerName': 'xxxxxxxx',
  'cpumhz': '1600',
  'currentIPS': '2018-04-10 rev. 061',
  'diskDrive': 'C:\\',
  'freeDisk': '1000000000',
  'freeMem': '5000000000',
  'hiStatus': '1',
  'ipAddress': 'x.x.x.x.',
  'ips': '2018-04-10 rev. 061',
  'lastHeartBeat': '2018-04-11 04:01:25',
  'operationSystem': 'Windows xxxxxxxx',
  'port': 'xxxx',
  'processorType': 'Intel64 Family 6 Model 63 Stepping 2',
  'sepDomain': 'xxxx',
  'sepmgroup': 'My Company\\xxxxxx',
  'seq': '192075',
  'status': 'Online',
  'totalMem': 'xxxxxxxx'}

Application consists of 3 files 

1. Python Code

2. index.html

3. gupServerStatus.html

# Python code

__author__ = 'ashishkushwaha'
import requests, json, pprint
from flask import Flask
from flask import render_template
from flask import request

app = Flask(__name__)
pagesize = '1000'

api_url_base = "https://<SEPM Server IP>:8446/sepm/api/v1/"
authentication_url = "https://<SEPM Server IP>/sepm/api/v1/identity/authenticate"
# if output is required in JSON format
json_format = True

payload = {"username" : "<Username>", "password" : "<passwd>","domain" : "<domain>"}
headers = {"Content-Type":"application/json"}

#requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'HIGH:!DH:!aNULL' # necessary
#r = requests.Session()      # Start session in order to store the SessionID Cookie
r = requests.post(authentication_url, verify=False, headers=headers, data=json.dumps(payload))
api_token = (r.json()["token"])

headers = {'pageSize':pagesize,'Content-Type': 'application/json', 'Authorization': 'Bearer {0}'.format(api_token)}

# REST API URL to fetch information

gup_status = '{0}api/v1/gup/status'.format(api_url_base)


#Function to fetch information based on URL passed and response
def get_info(url,params):
    api_url = url
    params = params
    response = requests.get(api_url, headers=headers,verify=False, params=params)
    if response.status_code == 200:
        return json.loads(response.content.decode('utf-8'))
    else:
        return response.status_code


@app.route(("/gupServerStatus"))
def gupServerStatus():
    gup_status_url = '{0}api/v1/gup/status'.format(api_url_base)
    params={}
    response_info = get_info(gup_status_url,params)
    if response_info is not 200:
        pprint.pprint(response_info)
        gupServerStatus=response_info
        #print('Total Endpoints:',response_info['totalElements'])
        #print(response_info["totalElements"])
    else:
        print('[!] Request Failed, {0}')


    return render_template("gupServerStatus.html",gupServerStatus=gupServerStatus)


@app.route('/')
def root():
    # return app.send_static_file('index.html')
    return render_template('index.html')

if __name__ =='__main__':
    app.run(port=5002, debug=True)
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>SEP Page</title>
    <meta http-equiv="refresh" content="300">
</head>

<style>
    .thick-border {
        border: 3px solid green;
        border-collapse: collapse;}

    body            { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;}
a, h1, h2       { color: #377ba8; }
h1, h2          { margin: 0; }
h1              { border-bottom: 2px solid #eee; }
h2              { font-size: 1.2em; }

table .dataframe, .dataframe th, .dataframe td {
  border: none;
  border-bottom: 1px solid #C8C8C8;
  border-collapse: collapse;
  text-align:left;
  padding: 10px;
  margin-bottom: 40px;
  font-size: 0.9em;
}

.issuemachines th {
    background-color: #77dd77;
    color: white;
}

tr:nth-child(odd)	{ background-color:#eee; }
tr:nth-child(even)	{ background-color:#fff; }

tr:hover            { background-color: #ffff99;}

</style>

<style>
body {font-family: "Lucida Sans Unicode", sans-serif;}

.tablink {
    background-color: #555;
    color: white;
    float: left;
    border: none;
    outline: none;
    cursor: pointer;
    padding: 14px 16px;
    font-size: 17px;
    width: 20%;
}

.tablink:hover {
    background-color: #777;
}

/* Style the tab content */
.tabcontent {
    color: white;
    display: none;
    padding: 50px;
    text-align: center;
}

#Home {background-color:#5D6D7E;}
#Summary {background-color:#5D6D7E;}
#DailyDrillDown {background-color:#5D6D7E;}
#AdminLogins {background-color:#5D6D7E;}
#Search {background-color:#5D6D7E;}

    div#loading {
    width: 35px;
    height: 35px;
    display: none;
    background: url(/static/loadingimage.gif) no-repeat;
    cursor: wait;
    }
</style>

<script>
function openCity(cityName,elmnt,color) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablink");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].style.backgroundColor = "";
    }
    document.getElementById(cityName).style.display = "block";
    elmnt.style.backgroundColor = color;

}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>

<script type="text/javascript">// <![CDATA[
        function loading(){
            $("#loading").show();
            $("#content").hide();
        }
// ]]></script>

</head>


    <body>


        <div id="gupServerStatus" class="tabcontent">
          <h3>GUP Servers </h3>
          <p>GUP Servers</p>
        </div>


        <a href="/gupServerStatus"><button class="tablink" onclick="openCity('gupServerStatus', this, 'green');loading();"> GUP Servers</button></a>
 
        <br/>

        <div id="content">{% block content %}{% endblock %}</div>


    </body>
</html>
{% extends "index.html" %}

{% block content %}
<br/>

<!--{{gupServerStatus}}-->
    <!--AD Logs is Login user Local Admin -->
<div class=page>
            <table class="centered thick-border">

                        <th>Hostname </th>
                        <th>IP Address</th>
                        <th>Status</th>
                        <th>last Heart Beat(GMT)</th>
                        <th>AV Signature</th>
                        <th>Group</th>


                {% for row in gupServerStatus %}
                    <tr>
                        <!--{% for c in row %}-->
                            <!--<td>{{c}}</td>-->
                        <!--{% endfor %}-->

                        <td align="left" width="10%">{{row['computerName']}}</td>
                        <td align="center">{{row['ipAddress']}}</td>
                        <td align="center">
                            {%if row['status'] == "Offline" %} <div style ="color:red">{{row['status']}}</div>
                            {%else %} <div style ="color:green">{{row['status']}}</div>
                            {% endif %}
                        </td>
                        <td align="center">{{row['lastHeartBeat']}}</td>
                        <td align="center">{{row['avas']}}</td>
                        <td align="left">{{row['sepmgroup']}}</td>


                    </tr>
                {% endfor %}
            </table>

</div>
{% endblock %}

Viewing all articles
Browse latest Browse all 1863

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>