Getting Dict Value from same source at different times and comparing them












0















I am working on a ceph mgr plugin. I have a dict that I get from self.get('health'). The keys and values in the dict changes depending on the health of the system.



What I want to achieve is to write a function in python that gets the value of self.get('health') every 1 minute and compare it with the previous value i.e. oldDictValue compared to newDictValue where newDictValue is the dict value gotten after 1 minute.



oldDictValue and newDictValue are variables holding values from self.get('health') at different times.










share|improve this question

























  • I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

    – Ha Bom
    Dec 29 '18 at 9:01













  • @HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

    – Kate Longchi
    Dec 29 '18 at 9:13











  • Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

    – Ha Bom
    Dec 29 '18 at 9:23











  • Can you put it in the question for easier understanding?

    – Ha Bom
    Dec 29 '18 at 9:25
















0















I am working on a ceph mgr plugin. I have a dict that I get from self.get('health'). The keys and values in the dict changes depending on the health of the system.



What I want to achieve is to write a function in python that gets the value of self.get('health') every 1 minute and compare it with the previous value i.e. oldDictValue compared to newDictValue where newDictValue is the dict value gotten after 1 minute.



oldDictValue and newDictValue are variables holding values from self.get('health') at different times.










share|improve this question

























  • I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

    – Ha Bom
    Dec 29 '18 at 9:01













  • @HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

    – Kate Longchi
    Dec 29 '18 at 9:13











  • Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

    – Ha Bom
    Dec 29 '18 at 9:23











  • Can you put it in the question for easier understanding?

    – Ha Bom
    Dec 29 '18 at 9:25














0












0








0








I am working on a ceph mgr plugin. I have a dict that I get from self.get('health'). The keys and values in the dict changes depending on the health of the system.



What I want to achieve is to write a function in python that gets the value of self.get('health') every 1 minute and compare it with the previous value i.e. oldDictValue compared to newDictValue where newDictValue is the dict value gotten after 1 minute.



oldDictValue and newDictValue are variables holding values from self.get('health') at different times.










share|improve this question
















I am working on a ceph mgr plugin. I have a dict that I get from self.get('health'). The keys and values in the dict changes depending on the health of the system.



What I want to achieve is to write a function in python that gets the value of self.get('health') every 1 minute and compare it with the previous value i.e. oldDictValue compared to newDictValue where newDictValue is the dict value gotten after 1 minute.



oldDictValue and newDictValue are variables holding values from self.get('health') at different times.







python dictionary ceph






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 29 '18 at 12:47









Unhandled Exception

1,045159




1,045159










asked Dec 29 '18 at 8:54









Kate LongchiKate Longchi

11




11













  • I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

    – Ha Bom
    Dec 29 '18 at 9:01













  • @HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

    – Kate Longchi
    Dec 29 '18 at 9:13











  • Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

    – Ha Bom
    Dec 29 '18 at 9:23











  • Can you put it in the question for easier understanding?

    – Ha Bom
    Dec 29 '18 at 9:25



















  • I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

    – Ha Bom
    Dec 29 '18 at 9:01













  • @HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

    – Kate Longchi
    Dec 29 '18 at 9:13











  • Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

    – Ha Bom
    Dec 29 '18 at 9:23











  • Can you put it in the question for easier understanding?

    – Ha Bom
    Dec 29 '18 at 9:25

















I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

– Ha Bom
Dec 29 '18 at 9:01







I think you can combine those two posts to solve your problem: interval timer and comparing 2 dictionaries

– Ha Bom
Dec 29 '18 at 9:01















@HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

– Kate Longchi
Dec 29 '18 at 9:13





@HaBom this [stackoverflow.com/questions/4527942/… will not quite work because the dict lenght will be different if there's a change in status

– Kate Longchi
Dec 29 '18 at 9:13













Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

– Ha Bom
Dec 29 '18 at 9:23





Yeah, there are so many ways to compare 2 dictionaries in that post, but they're just the ideas. Can you provide a sample of dictionaries?

– Ha Bom
Dec 29 '18 at 9:23













Can you put it in the question for easier understanding?

– Ha Bom
Dec 29 '18 at 9:25





Can you put it in the question for easier understanding?

– Ha Bom
Dec 29 '18 at 9:25












1 Answer
1






active

oldest

votes


















0














Here is a proposed pseudo code for what I wish to achieve. I am finding it difficult to covert this to a working solution



```  
fun diff_health(old_health, new_health):
old = {}
new = {}
updated = {}
for code, item in new_health['checks'].iteritems():
if code not in old_health['checks']:
# it's a new alert
new[code] = item
else:
old_item = old_health['checks'][code]
if item['severity'] != old_item['severity'] or item['summary']['message'] != old_item['usmmary']['message']:
# changed
updated[code] = item
for code, item in old_health['checks'].iteritems():
if code not in new_health['checks']:
# health alert has resolved
...
return old, new, updated
```


new_health and old_health are values from self.get('heatth') at diffrent times






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968124%2fgetting-dict-value-from-same-source-at-different-times-and-comparing-them%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Here is a proposed pseudo code for what I wish to achieve. I am finding it difficult to covert this to a working solution



    ```  
    fun diff_health(old_health, new_health):
    old = {}
    new = {}
    updated = {}
    for code, item in new_health['checks'].iteritems():
    if code not in old_health['checks']:
    # it's a new alert
    new[code] = item
    else:
    old_item = old_health['checks'][code]
    if item['severity'] != old_item['severity'] or item['summary']['message'] != old_item['usmmary']['message']:
    # changed
    updated[code] = item
    for code, item in old_health['checks'].iteritems():
    if code not in new_health['checks']:
    # health alert has resolved
    ...
    return old, new, updated
    ```


    new_health and old_health are values from self.get('heatth') at diffrent times






    share|improve this answer






























      0














      Here is a proposed pseudo code for what I wish to achieve. I am finding it difficult to covert this to a working solution



      ```  
      fun diff_health(old_health, new_health):
      old = {}
      new = {}
      updated = {}
      for code, item in new_health['checks'].iteritems():
      if code not in old_health['checks']:
      # it's a new alert
      new[code] = item
      else:
      old_item = old_health['checks'][code]
      if item['severity'] != old_item['severity'] or item['summary']['message'] != old_item['usmmary']['message']:
      # changed
      updated[code] = item
      for code, item in old_health['checks'].iteritems():
      if code not in new_health['checks']:
      # health alert has resolved
      ...
      return old, new, updated
      ```


      new_health and old_health are values from self.get('heatth') at diffrent times






      share|improve this answer




























        0












        0








        0







        Here is a proposed pseudo code for what I wish to achieve. I am finding it difficult to covert this to a working solution



        ```  
        fun diff_health(old_health, new_health):
        old = {}
        new = {}
        updated = {}
        for code, item in new_health['checks'].iteritems():
        if code not in old_health['checks']:
        # it's a new alert
        new[code] = item
        else:
        old_item = old_health['checks'][code]
        if item['severity'] != old_item['severity'] or item['summary']['message'] != old_item['usmmary']['message']:
        # changed
        updated[code] = item
        for code, item in old_health['checks'].iteritems():
        if code not in new_health['checks']:
        # health alert has resolved
        ...
        return old, new, updated
        ```


        new_health and old_health are values from self.get('heatth') at diffrent times






        share|improve this answer















        Here is a proposed pseudo code for what I wish to achieve. I am finding it difficult to covert this to a working solution



        ```  
        fun diff_health(old_health, new_health):
        old = {}
        new = {}
        updated = {}
        for code, item in new_health['checks'].iteritems():
        if code not in old_health['checks']:
        # it's a new alert
        new[code] = item
        else:
        old_item = old_health['checks'][code]
        if item['severity'] != old_item['severity'] or item['summary']['message'] != old_item['usmmary']['message']:
        # changed
        updated[code] = item
        for code, item in old_health['checks'].iteritems():
        if code not in new_health['checks']:
        # health alert has resolved
        ...
        return old, new, updated
        ```


        new_health and old_health are values from self.get('heatth') at diffrent times







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 29 '18 at 9:40

























        answered Dec 29 '18 at 9:34









        Kate LongchiKate Longchi

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968124%2fgetting-dict-value-from-same-source-at-different-times-and-comparing-them%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas