Regular Expressions and SQL Server Error Logs - All false results












0















Ok, I have done my searching and I have tried many things. I think it is time to put my question here:



I have been working on taking in other user's SQL Server error logs, parsing out the rows into columns, then bulk inserting the data 1000 at a time. I troubleshoot SQL Server for other people so sp_readerrorlog will only show me my local instance. Finding root cause involves 4 sets of logs (SQL Server, Application Event, System Event, and get-clusterlog outputs and matching up timestamps. A fast load into SQL Server along with the ability to pull the exact timeframe needed will shorten my time spent staring at log files.



I am currently bottlenecked in testing the rows with a regular expression, which does work if I feed it data myself:



def sqlrowmatch(row):
pattern = re.compile(r'dddd-dd-ddsdd:dd:dd.dd')

if pattern.search(row):
return True
else:
return False


given any string that matches above (1111-11-11 11:11:11.11) will return as true. The idea is if in a SQL Server Error Log, if this is matched, then it is a separate entry. this will allow memory graphs, deadlock graphs, and dumps to all be grouped in one entry as opposed to being split over several lines.



However, if I point it at one of the SQL Error Logs, there seems to be extra characters. This is giving re.match and re.show a hard time finding a match. If I load any line in this function,sqlrowmatch(), it reports back false for all rows.



ÿþ <-- this appears to be the first 2 characters at the first line. re.search just doesn't even find it anywhere in the in the different elements.



False is what is returned if I put the function in with the 'with open' as statement:



with open(file, 'r') as sqllog:
for line in sqllog:
print(sqlrowmatch(line))


the first line should always be true if sqlrowmatch() is used.




2018-10-13 22:40:09.41 Server Microsoft SQL Server 2016 (SP2-CU2-GDR) (KB4458621) - 13.0.5201.2 (X64)




So I am lost and my current project is at a halt. Perhaps some seasoned insight from this group can get me going again.



TIA










share|improve this question























  • Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

    – Kouri
    Nov 14 '18 at 16:12


















0















Ok, I have done my searching and I have tried many things. I think it is time to put my question here:



I have been working on taking in other user's SQL Server error logs, parsing out the rows into columns, then bulk inserting the data 1000 at a time. I troubleshoot SQL Server for other people so sp_readerrorlog will only show me my local instance. Finding root cause involves 4 sets of logs (SQL Server, Application Event, System Event, and get-clusterlog outputs and matching up timestamps. A fast load into SQL Server along with the ability to pull the exact timeframe needed will shorten my time spent staring at log files.



I am currently bottlenecked in testing the rows with a regular expression, which does work if I feed it data myself:



def sqlrowmatch(row):
pattern = re.compile(r'dddd-dd-ddsdd:dd:dd.dd')

if pattern.search(row):
return True
else:
return False


given any string that matches above (1111-11-11 11:11:11.11) will return as true. The idea is if in a SQL Server Error Log, if this is matched, then it is a separate entry. this will allow memory graphs, deadlock graphs, and dumps to all be grouped in one entry as opposed to being split over several lines.



However, if I point it at one of the SQL Error Logs, there seems to be extra characters. This is giving re.match and re.show a hard time finding a match. If I load any line in this function,sqlrowmatch(), it reports back false for all rows.



ÿþ <-- this appears to be the first 2 characters at the first line. re.search just doesn't even find it anywhere in the in the different elements.



False is what is returned if I put the function in with the 'with open' as statement:



with open(file, 'r') as sqllog:
for line in sqllog:
print(sqlrowmatch(line))


the first line should always be true if sqlrowmatch() is used.




2018-10-13 22:40:09.41 Server Microsoft SQL Server 2016 (SP2-CU2-GDR) (KB4458621) - 13.0.5201.2 (X64)




So I am lost and my current project is at a halt. Perhaps some seasoned insight from this group can get me going again.



TIA










share|improve this question























  • Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

    – Kouri
    Nov 14 '18 at 16:12
















0












0








0








Ok, I have done my searching and I have tried many things. I think it is time to put my question here:



I have been working on taking in other user's SQL Server error logs, parsing out the rows into columns, then bulk inserting the data 1000 at a time. I troubleshoot SQL Server for other people so sp_readerrorlog will only show me my local instance. Finding root cause involves 4 sets of logs (SQL Server, Application Event, System Event, and get-clusterlog outputs and matching up timestamps. A fast load into SQL Server along with the ability to pull the exact timeframe needed will shorten my time spent staring at log files.



I am currently bottlenecked in testing the rows with a regular expression, which does work if I feed it data myself:



def sqlrowmatch(row):
pattern = re.compile(r'dddd-dd-ddsdd:dd:dd.dd')

if pattern.search(row):
return True
else:
return False


given any string that matches above (1111-11-11 11:11:11.11) will return as true. The idea is if in a SQL Server Error Log, if this is matched, then it is a separate entry. this will allow memory graphs, deadlock graphs, and dumps to all be grouped in one entry as opposed to being split over several lines.



However, if I point it at one of the SQL Error Logs, there seems to be extra characters. This is giving re.match and re.show a hard time finding a match. If I load any line in this function,sqlrowmatch(), it reports back false for all rows.



ÿþ <-- this appears to be the first 2 characters at the first line. re.search just doesn't even find it anywhere in the in the different elements.



False is what is returned if I put the function in with the 'with open' as statement:



with open(file, 'r') as sqllog:
for line in sqllog:
print(sqlrowmatch(line))


the first line should always be true if sqlrowmatch() is used.




2018-10-13 22:40:09.41 Server Microsoft SQL Server 2016 (SP2-CU2-GDR) (KB4458621) - 13.0.5201.2 (X64)




So I am lost and my current project is at a halt. Perhaps some seasoned insight from this group can get me going again.



TIA










share|improve this question














Ok, I have done my searching and I have tried many things. I think it is time to put my question here:



I have been working on taking in other user's SQL Server error logs, parsing out the rows into columns, then bulk inserting the data 1000 at a time. I troubleshoot SQL Server for other people so sp_readerrorlog will only show me my local instance. Finding root cause involves 4 sets of logs (SQL Server, Application Event, System Event, and get-clusterlog outputs and matching up timestamps. A fast load into SQL Server along with the ability to pull the exact timeframe needed will shorten my time spent staring at log files.



I am currently bottlenecked in testing the rows with a regular expression, which does work if I feed it data myself:



def sqlrowmatch(row):
pattern = re.compile(r'dddd-dd-ddsdd:dd:dd.dd')

if pattern.search(row):
return True
else:
return False


given any string that matches above (1111-11-11 11:11:11.11) will return as true. The idea is if in a SQL Server Error Log, if this is matched, then it is a separate entry. this will allow memory graphs, deadlock graphs, and dumps to all be grouped in one entry as opposed to being split over several lines.



However, if I point it at one of the SQL Error Logs, there seems to be extra characters. This is giving re.match and re.show a hard time finding a match. If I load any line in this function,sqlrowmatch(), it reports back false for all rows.



ÿþ <-- this appears to be the first 2 characters at the first line. re.search just doesn't even find it anywhere in the in the different elements.



False is what is returned if I put the function in with the 'with open' as statement:



with open(file, 'r') as sqllog:
for line in sqllog:
print(sqlrowmatch(line))


the first line should always be true if sqlrowmatch() is used.




2018-10-13 22:40:09.41 Server Microsoft SQL Server 2016 (SP2-CU2-GDR) (KB4458621) - 13.0.5201.2 (X64)




So I am lost and my current project is at a halt. Perhaps some seasoned insight from this group can get me going again.



TIA







python-3.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 16:00









KouriKouri

13




13













  • Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

    – Kouri
    Nov 14 '18 at 16:12





















  • Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

    – Kouri
    Nov 14 '18 at 16:12



















Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

– Kouri
Nov 14 '18 at 16:12







Interesting enough, I found my answer here: stackoverflow.com/questions/18176475/… open should be done with encoding='utf-16'

– Kouri
Nov 14 '18 at 16:12














1 Answer
1






active

oldest

votes


















0














Interesting enough, I found my answer here: Opening huge text file, unicode issue



open should be done with encoding='utf-16'



It now matches appropriately






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%2f53304236%2fregular-expressions-and-sql-server-error-logs-all-false-results%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














    Interesting enough, I found my answer here: Opening huge text file, unicode issue



    open should be done with encoding='utf-16'



    It now matches appropriately






    share|improve this answer




























      0














      Interesting enough, I found my answer here: Opening huge text file, unicode issue



      open should be done with encoding='utf-16'



      It now matches appropriately






      share|improve this answer


























        0












        0








        0







        Interesting enough, I found my answer here: Opening huge text file, unicode issue



        open should be done with encoding='utf-16'



        It now matches appropriately






        share|improve this answer













        Interesting enough, I found my answer here: Opening huge text file, unicode issue



        open should be done with encoding='utf-16'



        It now matches appropriately







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 16:13









        KouriKouri

        13




        13
































            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%2f53304236%2fregular-expressions-and-sql-server-error-logs-all-false-results%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

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python