Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell + code refactoring #71

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Powershell + code refactoring #71

wants to merge 10 commits into from

Conversation

melnemr
Copy link
Contributor

@melnemr melnemr commented Oct 22, 2020

Step 1: Link to Jira issue

Step 2: Description of changes

Step 3: Did you add / update tests for your changes in the right area?

  • Unit/Component test
  • Integration test

Step 4: I'm confident that everything is properly tested:

I got a PO / QA Approval by:

  • Name

Step 5: Can we ship this feature to production?

  • Yes, I'm proud of my work. Ship it! 🚢

scom/stackstate_checks/scom/scom.py Show resolved Hide resolved
scom/stackstate_checks/scom/scom.py Show resolved Hide resolved
scom/stackstate_checks/scom/scom.py Outdated Show resolved Hide resolved
type_response = (session.post('http://'+ scom_ip +'/OperationsManager/data/scomObjects',auth=HttpNtlmAuth(domain + '\\' + username, password),json=type_data["criteria"])).json()
self.requests_counter +=1
self.log.debug("Number of requets: "+str(self.requests_counter))
component_type = type_response.get("scopeDatas")[0].get("className").lower().replace(" ","-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type_response.get("scopeDatas")[0].get("className").lower().replace(" ","-")

This will fail if we get something unsuspected, can we add some guards around it

Copy link
Contributor Author

@melnemr melnemr Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the response is always something like
{
"scopeDatas": [
{
"id": "e4750a18-1ae2-7a66-c54a-d0ab8caa1c85",
"displayName": "Exchange Back End",
"className": "IIS 10 Web Site",
"path": "EX01.stackstate.lab",
"fullName": "Microsoft.Windows.InternetInformationServices.10.0.WebSite:EX01.stackstate.lab;W3SVC/2"
}
]
}
what i do is just some string manipulation to convert "IIS 10 Web Site" to "iis-10-web-site" and add it as the type of the component

how can we add some guards around it ? check if scopeDatas as well as className exist ?

scom/stackstate_checks/scom/scom.py Outdated Show resolved Hide resolved
properties_list = dict()
relations_list = []
for detail in properties:
properties_list.update({str(detail.get("name").encode('utf-8')):str(detail.get("value").encode('utf-8'))})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure we actually have name and value for the detail object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the response i parse:
"monitoringObjectProperties": [
{
"name": "Application Pool Name",
"value": "DefaultAppPool"
},
{
"name": "Failed Request Tracing Enabled",
"value": "False"
},
{
"name": "Failed Request Tracing Directory",
"value": "C:\inetpub\logs\FailedReqLogFiles"
},
{
"name": "Start Automatically",
"value": "True"
},
{
"name": "Connection Time-out (seconds)",
"value": "120"
},
{
"name": "Maximum Concurrent Connections",
"value": ""
},
{
"name": "Maximum Bandwidth (Bytes/second)",
"value": ""
},
{
"name": "ID",
"value": "2"
},
{
"name": "Key",
"value": "W3SVC/2"
},
{
"name": "Description",
"value": "Exchange Back End"
},
{
"name": "Server Bindings",
"value": ":81:"
},
{
"name": "Secure Bindings",
"value": "
:444:"
},
{
"name": "Folder path",
"value": "C:\Program Files\Microsoft\Exchange Server\V15\ClientAccess"
},
{
"name": "Log File Directory",
"value": "C:\inetpub\logs\LogFiles\W3SVC2"
},
{
"name": "LogfileType",
"value": "4"
},
{
"name": "BITS",
"value": ""
},
{
"name": "Log File Pattern",
"value": "u_ex??????.log"
},
{
"name": "Logging Enabled",
"value": "True"
},
{
"name": "Anonymous Username",
"value": "IUSR"
},
{
"name": "Cache ISAPI",
"value": "False"
},
{
"name": "Allow Keep Alive",
"value": "True"
},
{
"name": "URL",
"value": "http://EX01.stackstate.lab:81;https://EX01.stackstate.lab:444;"
},
{
"name": "Perf Counter Instance Name",
"value": "Exchange Back End"
},
{
"name": "Object Status",
"value": "System.ConfigItem.ObjectStatusEnum.Active"
},
{
"name": "Asset Status",
"value": ""
},
{
"name": "Notes",
"value": ""
},
{
"name": "Display Name",
"value": "Exchange Back End"
},
{
"name": "Path",
"value": "EX01.stackstate.lab"
}
]

name and value will always be there. should i add a couple of lines to always check for them ?

relations_list = []
for detail in properties:
properties_list.update({str(detail.get("name").encode('utf-8')):str(detail.get("value").encode('utf-8'))})
name = str(response["displayName"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few things here that can potentially fail, make sure that all these values are there or use some defaults if possible

scom/stackstate_checks/scom/scom.py Outdated Show resolved Hide resolved
scom/stackstate_checks/scom/scom.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants