Add possibility to get all issues
This commit is contained in:
		
							parent
							
								
									f950b3719f
								
							
						
					
					
						commit
						ba63276df3
					
				
					 5 changed files with 89 additions and 3 deletions
				
			
		|  | @ -123,6 +123,8 @@ if __name__ == "__main__": | |||
|                 schedule.every(server.request_total_run_seconds).seconds.do(threaded, OMBI.get_all_requests) | ||||
|             if server.request_issues_counts: | ||||
|                 schedule.every(server.request_issues_type_run_seconds).seconds.do(threaded, OMBI.get_issues_counts) | ||||
|             if server.issues_total_counts: | ||||
|                 schedule.every(server.issues_total_run_seconds).seconds.do(threaded, OMBI.get_all_issues) | ||||
| 
 | ||||
|     if CONFIG.sickchill_enabled: | ||||
|         for server in CONFIG.sickchill_servers: | ||||
|  |  | |||
|  | @ -85,7 +85,8 @@ get_request_total_counts = true | |||
| request_total_run_seconds = 300 | ||||
| get_request_issues_counts = true | ||||
| request_type_issues_run_seconds = 300 | ||||
| 
 | ||||
| get_issues_total_counts = true | ||||
| issues_total_run_seconds = 300 | ||||
| 
 | ||||
| [sickchill-1] | ||||
| url = sickchill.domain.tld:8081 | ||||
|  |  | |||
|  | @ -183,9 +183,15 @@ class INIParser(object): | |||
| 
 | ||||
|                             request_issues_type_run_seconds = self.config.getint(section, 'request_type_issues_run_seconds') | ||||
| 
 | ||||
|                             issues_total_counts = self.config.getboolean(section, 'get_issues_total_counts') | ||||
| 
 | ||||
|                             issues_total_run_seconds = self.config.getint(section, 'issues_total_run_seconds') | ||||
| 
 | ||||
|                             server = OmbiServer(server_id, scheme + url, apikey, verify_ssl, request_type_counts, | ||||
|                                                 request_type_run_seconds, request_total_counts, | ||||
|                                                 request_total_run_seconds, request_issues_counts, request_issues_type_run_seconds) | ||||
|                                                 request_total_run_seconds, request_issues_counts,  | ||||
|                                                 request_issues_type_run_seconds, issues_total_counts,  | ||||
|                                                 issues_total_run_seconds) | ||||
| 
 | ||||
|                         if service == 'sickchill': | ||||
|                             get_missing = self.config.getboolean(section, 'get_missing') | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ from requests import Session, Request | |||
| from datetime import datetime, timezone | ||||
| 
 | ||||
| from varken.helpers import connection_handler, hashit | ||||
| from varken.structures import OmbiRequestCounts, OmbiIssuesCounts, OmbiMovieRequest, OmbiTVRequest | ||||
| from varken.structures import OmbiRequestCounts, OmbiIssuesCounts, OmbiIssue, OmbiMovieRequest, OmbiTVRequest | ||||
| 
 | ||||
| 
 | ||||
| class OmbiAPI(object): | ||||
|  | @ -193,3 +193,62 @@ class OmbiAPI(object): | |||
|         ] | ||||
| 
 | ||||
|         self.dbmanager.write_points(influx_payload) | ||||
| 
 | ||||
|     def get_all_issues(self): | ||||
|         now = datetime.now(timezone.utc).astimezone().isoformat() | ||||
|         endpoint = '/api/v1/Issues/' | ||||
| 
 | ||||
|         req = self.session.prepare_request(Request('GET', self.server.url + endpoint)) | ||||
|         get_issues = connection_handler(self.session, req, self.server.verify_ssl) | ||||
|          | ||||
| 
 | ||||
|         if not any([get_issues]): | ||||
|             self.logger.error('No json replies. Discarding job') | ||||
|             return | ||||
| 
 | ||||
|         issues_count = len(get_issues) | ||||
| 
 | ||||
|         try: | ||||
|             issue_list = [OmbiIssue(**issue) for issue in get_issues] | ||||
|         except TypeError as e: | ||||
|             self.logger.error('TypeError has occurred : %s while creating OmbiIssue structure', e) | ||||
|             return | ||||
| 
 | ||||
|         influx_payload = [ | ||||
|             { | ||||
|                 "measurement": "Ombi", | ||||
|                 "tags": { | ||||
|                     "type": "Issues_Total", | ||||
|                     "server": self.server.id | ||||
|                 }, | ||||
|                 "time": now, | ||||
|                 "fields": { | ||||
|                     "total": issues_count | ||||
|                 } | ||||
|             } | ||||
|         ] | ||||
|         # Request Type: Movie = 1, TV Show = 0 | ||||
|         # Status: 0 = Pending, 1 = In Progress, 2 = Resolved | ||||
|         for issue in issue_list: | ||||
|             hash_id = hashit(f'{issue.id}{issue.requestId}{issue.title}') | ||||
| 
 | ||||
|             influx_payload.append( | ||||
|                 { | ||||
|                     "measurement": "Ombi", | ||||
|                     "tags": { | ||||
|                         "type": "Issues", | ||||
|                         "server": self.server.id, | ||||
|                         "request_type": issue.requestType, | ||||
|                         "status": issue.status, | ||||
|                         "title": issue.title, | ||||
|                         "subject": issue.subject, | ||||
|                         "description": issue.description | ||||
|                     }, | ||||
|                     "time": now, | ||||
|                     "fields": { | ||||
|                         "hash": hash_id | ||||
|                     } | ||||
|                 } | ||||
|             ) | ||||
| 
 | ||||
|         self.dbmanager.write_points(influx_payload) | ||||
|  | @ -63,6 +63,8 @@ class OmbiServer(NamedTuple): | |||
|     request_total_run_seconds: int = 30 | ||||
|     request_issues_counts: bool = False | ||||
|     request_issues_type_run_seconds: int = 30 | ||||
|     issues_total_counts: bool = False | ||||
|     issues_total_run_seconds: int = 30 | ||||
| 
 | ||||
| 
 | ||||
| class TautulliServer(NamedTuple): | ||||
|  | @ -402,6 +404,22 @@ class OmbiMovieRequest(NamedTuple): | |||
|     canApprove: bool = None | ||||
|     id: int = None | ||||
| 
 | ||||
| class OmbiIssue(NamedTuple): | ||||
|     title: str = None | ||||
|     requestType:  int = None | ||||
|     providerId: int = None | ||||
|     requestId: int = None | ||||
|     subject: str = None | ||||
|     description: str = None | ||||
|     issueCategoryId: int = None | ||||
|     issueCategory: dict = None | ||||
|     status: int = None | ||||
|     resovledDate: None = None | ||||
|     userReportedId: str = None | ||||
|     userReported: str = None | ||||
|     comments: str = None | ||||
|     id: int = None | ||||
| 
 | ||||
| 
 | ||||
| class OmbiTVRequest(NamedTuple): | ||||
|     tvDbId: int = None | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue