Esempio n. 1
0
    def request_program_stats(self, request):
        '''need to make sure the request is good
           and check for an early request
        '''
        logger.debug("Entering request_program_stats")
        while True:
            try:
                this_response = requests.post(self.requesturl, data=request)

                sentryUtils.log_response(this_response)
                stats_load = json.loads(this_response.text, parse_int = int, parse_float = int)
                if stats_load.has_key('result'):
                    return stats_load['result']
                elif stats_load.has_key('code'):
                    if str(stats_load["code"]) == "-32000": #code -32000 is an early request
                        print "Made a request too fast waiting a minute"
                        logger.debug("code: {0!s}".format(stats_load["code"]))
                        logger.debug("text: {0!s}".format(stats_load["message"]))
                        sleep(STATS_SLEEP_TIME)
                    else:
                        raise Exception("Bad response from Sentry {0!s}".format(this_response.text))
                else:
                    print "error: {0!s}".format(this_response.text)
            except:
                print "Sentry did not respond. Will try again"
        logger.debug("Leaving request_program_stats")
        return stats_load
Esempio n. 2
0
    def UpdateMPEGInput(self, UpdateMPEG, BreakNumber = 20):
        '''
        Function to talk to Input.UpdateMPEGInput to set the input settings.
        arguments:
                UpdateMPEG - List of dicts containing the MPEG input settings
                BreakNumber - how many port settings to send at a time
        '''
        '''
        example Input.UpdateMPEGInput request
        {
            "jsonrpc":2.0,"method":"Input.UpdateMPEGInput","params":
            {"inputType":"json","inputSettings":[{"sentryName":"Name or IP",
            "portnum":13,"sourceIp":"*","groupAddr":"225.215.1.5","destPort":8000,
            "name":"Port 13","desc":"My port 13","monitorBackup":false,
            "backupSourceIp":"*","backupGroupAddr":"225.215.2.1","backupDestPort":8001,
            "vlanId":1069,"mode":"Multicast"}]},"id":1}
        '''
        '''
        example responses from Input.UpdateMPEGInput
        {"ver":"1.0","jsonrpc":"2.0","code":-32602,"message":"sentryName is a required parameter.","data":null,"cnt":null}
        {"ver":"1.0","jsonrpc":"2.0","id":1,"result":[{"region":"PA","location":"Danville","display_name":"sentry3",
            "ip_addr":"10.0.1.14","unit_name":"sentry3","Error":"Port 1155, 1156, 1157, 1158, 1159 are out of the range.","System ID":4}]}
        {"ver":"1.0","jsonrpc":"2.0","id":1,"result":[{"region":"PA","location":"Danville","display_name":"sentry3",
            "ip_addr":"10.0.1.14","unit_name":"sentry3","response":{"resultCode":"200","resultMsg":"Success"},"System ID":4}]}
         {"ver":"1.0","jsonrpc":"2.0","id":1,"result":[{"region":"PA","location":"Danville","display_name":"sentry2","ip_addr":"10.0.1.13","unit_name":"sentry2",
            "Error":"The Source IP for port number 9 (172.31.27.22 ) is invalid.<br>The Source IP for port number 11 (172.31.27.22 ) is invalid.
            <br>The Source IP for port number 12 (172.31.27.22 ) is invalid.<br>The Source IP for port number 14 (172.31.27.22 ) is invalid.
            <br>The Source IP for port number 15 (172.31.27.22 ) is invalid.<br>The Source IP for port number 17 (172.31.27.22 ) is invalid.
            <br>The Source IP for port number 20 (172.31.27.22 ) is invalid.<br>The Source IP for port number 21 (172.31.27.22 ) is invalid.","System ID":3}]
        '''
        logger.debug("Entering UpdateMPEGInput")
        InputSettings = ''
        for num, port in enumerate(UpdateMPEG, start=1):
            InputSettings += str(json.dumps(port))
            if num % BreakNumber == 0 or num == len(UpdateMPEG):
                request = '''{{"jsonrpc":2.0,
                    "method":"Input.UpdateMPEGInput",
                    "params":
                    {{"inputType":"json",
                    "inputSettings":
                    [{0!s}]}},"id":1}}'''.format(str(InputSettings))
                logger.debug(request)
                this_response = requests.post(self.requesturl, data=request)
                sentryUtils.log_response(this_response)
                '''if stats_load.has_key('result'):
                    return stats_load['result']
                else:
                        raise Exception("Bad response from Sentry {0!s}".format(this_response.text))
                else:
                    print "error: {0!s}".format(this_response.text)'''
                InputSettings = ''
            else:
                InputSettings += ','

        logger.debug("Leaving UpdateMPEGInput")
Esempio n. 3
0
    def SetProgramMapping(self, ProgramMapping, BreakNumber=20):
        '''
        Function to talk to "Program.SetProgramMapping to set the input settings.
        arguments:
                UpdateMPEG - List of dicts containing the MPEG input settings
                BreakNumber - how many port settings to send at a time
        '''
        '''
        example "Program.SetProgramMapping request
            {
            "jsonrpc":2.0,
            "method":"Program.SetProgramMapping",
            "params":
            {"inputType":"json","inputSettings":[{"sentryName":"Name or IP","portNumber":"1","programNumber":"1","providerName":"HBO"},
            {"sentryName":"Name or IP","portNumber":"1","programNumber":"2","providerName":"5StarMAX"},
            {"sentryName":"Name or IP","portNumber":"1","programNumber":"3","providerName":"MyProvider","userAdded":true}]},
            "id":1
            }
        '''
        '''
        example responses from "Program.SetProgramMapping"

        '''
        logger.debug("Entering ProgramMapping")
        InputSettings = ''
        for num, port in enumerate(ProgramMapping, start=1):
            InputSettings += str(json.dumps(port))
            if num % BreakNumber == 0 or num == len(ProgramMapping):
                request = '''{{
                    "jsonrpc":2.0,
                    "method":"Program.SetProgramMapping",
                    "params":
                    {{"inputType":"json","inputSettings":
                    [{0!s}]}},"id":1}}'''.format(str(InputSettings))
                logger.debug(request)
                this_response = requests.post(self.requesturl, data=request)
                sentryUtils.log_response(this_response)
                '''if stats_load.has_key('result'):
                    return stats_load['result']
                else:
                        raise Exception("Bad response from Sentry {0!s}".format(this_response.text))
                else:
                    print "error: {0!s}".format(this_response.text)'''
                InputSettings = ''
            else:
                InputSettings += ','

        logger.debug("Leaving ProgramMapping")
Esempio n. 4
0
    def getMPEGInput(self):
        """
        {{
            "jsonrpc":2.0,
            "method":"Input.GetMPEGInput",
            "params":{"outputType":"json","activeOnly":true,"inputType":"ETH", "vlanIds":[1069]},
            "id":1
        }}"""

        request = """{
                    "jsonrpc":2.0,
                    "method":"Input.GetMPEGInput",
                    "params":{"outputType":"json","inputType":"ETH","activeOnly":true},
                    "id":1
                    }"""
        logger.debug(request)
        sentryUtils.log_response(requests.post(self.requesturl, data=request))
Esempio n. 5
0
 def updatePrimaryAudio(self, programMapping):
     """
         {{}
         "jsonrpc":2.0,
         "method":"Audio.UpdatePrimaryPID",
         "params":{"inputType":"json",
             "inputSettings":[
                 {{
                 "sentryName":"192.0.0.0",
                 "portNumber":"0",
                 "programNumber":"10",
                 "pidOrder":"1",
                 "codecType":"MPEG1",
                 "language":"eng"
                 }}}
             ]}},
         "id":1                
     """
     logger.debug("Entering updatePrimaryAudio")
     for program in programMapping:
         if (program['Audio_1'] != "0"):
             try:
                 int(program['Audio_1'])
                 audio_select = '"pidOrder":"{0!s}"'.format(program['Audio_1'])
             except ValueError:
                 audio_select = '"codecType":"DOLBY {0!s}"'.format(program['Audio_1'])
             request = """{{
                         "jsonrpc":2.0,
                         "method":"Audio.UpdatePrimaryPID",
                         "params":{{"inputType":"json",
                             "inputSettings":[
                                 {{
                                 "sentryName":"{0!s}",
                                 "portNumber":"{1!s}",
                                 "programNumber":"{2!s}",
                                 {3!s}
                                 }}
                             ]}},
                         "id":1
                         }}""".format(program['sentryName'],program['portNumber'],program['programNumber'],audio_select)
             logger.debug(request)
             sentryUtils.log_response(requests.post(self.requesturl, data=request))
     logger.debug("Leaving updatePrimaryAudio")
Esempio n. 6
0
    def deletePrimaryPIDSettings(self, sentryList):
        """
        {
        "jsonrpc":2.0,
        "method":"Audio.GetPrimaryPIDSettings",
        "params":{
            "outputType":"json",
            "sentryNames":"10.0.1.12,10.0.1.13,10.0.1.14"
            },
        "id":1
        }
        {
        "jsonrpc":2.0,
        "method":"Audio.DeletePrimaryPIDSettings",
        "params":{
            "inputType":"json",
            "inputSettings":[{
                "sentryName": "192.0.0.0",
                "portNumber":"1",
                "programNumber":"10"
                },
                {
                "sentryName": "192.0.0.0",
                "portNumber":"2",
                "programNumber":"10"
                }
            ]
        },
        "id":1
        }
	
        
        """
        logger.debug("Entering deletePrimaryPIDSettings")
        for sentry in sentryList:
            request = """{{
                        "jsonrpc":2.0,
                        "method":"Audio.GetPrimaryPIDSettings",
                        "params":{{
                            "outputType":"json",
                            "sentryNames":"{0!s}"
                            }},
                        "id":1
                        }}""".format(sentry.strip())
            logger.debug(request)
            this_response = requests.post(self.requesturl, data=request)
            sentryUtils.log_response(this_response)
            audioSettings = json.loads(this_response.text, parse_int = int, parse_float = int)
            if audioSettings.has_key('result'):
                for audio in audioSettings['result']:
                    if not audio.has_key('Error'):
                        request = """{{
                                "jsonrpc":2.0,
                                "method":"Audio.DeletePrimaryPIDSettings",
                                "params":{{
                                    "inputType":"json",
                                    "inputSettings":[{{
                                        "sentryName": "{0!s}",
                                        "portNumber":"{1!s}",
                                        "programNumber":"{2!s}"
                                        }}
                                ]
                                }},
                                "id":1
                                }}""".format(sentry.strip(),audio['port_number'],audio['program_number'])
                        logger.debug(request)
                        this_response = requests.post(self.requesturl, data=request)
                        sentryUtils.log_response(this_response)
        logger.debug("Leaving deletePrimaryPIDSettings")