| Total Complexity | 4 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import json |
||
| 15 | class WMIQueryAction(Action): |
||
| 16 | def run(self, host, password, query, username='Administrator'): |
||
| 17 | if not WMIC_EXISTS: |
||
| 18 | msg = ('Cannot find "wmic" binary. Please make sure WMI client'
|
||
| 19 | '(wmic) for' |
||
| 20 | ' Linux is installed and available in $PATH') |
||
| 21 | raise Exception(msg) |
||
| 22 | |||
| 23 | client = self._get_client(host=host, username=username, |
||
| 24 | password=password) |
||
| 25 | |||
| 26 | # Note: This method throws on connection issue, invalid query, etc |
||
| 27 | result = client.query(query) |
||
| 28 | |||
| 29 | try: |
||
| 30 | result = json.dumps(result) |
||
| 31 | except Exception: |
||
| 32 | pass |
||
| 33 | |||
| 34 | return result |
||
| 35 | |||
| 36 | def _get_client(self, host, username, password): |
||
| 37 | client = wmi.WmiClientWrapper(username=username, |
||
| 38 | password=password, |
||
| 39 | host=host) |
||
| 40 | return client |
||
| 41 |