0

I have a function who sending ack into the icinga / nagios server.

Function - sendAcknowledge

void MNetworkConnector::sendAcknowledge(QString service, QString host)
{

    QNetworkAccessManager *ackmanager;
    ackmanager = new QNetworkAccessManager();

    QString ackcommand = "http://nagioscore.demos.nagios.com/nagios/cgi-bin/cmd.cgi?cmd_typ=34&cmd_mod=2&host=#host#&service=#service#&com_author=nagiosadmin&com_data=Sent:+mMonitor&btnSubmit=Commit";
    service = service.replace(" ", "+");
    ackcommand = ackcommand.replace("#host#", host).replace("#service#", service);
    connect(ackmanager, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished2(QNetworkReply*)));

    QNetworkRequest myReq;
    QUrl myUrl(ackcommand);
    myUrl.setUserName("nagiosadmin");
    myUrl.setPassword("nagiosadmin");
    myReq.setUrl(myUrl);
    myReq.setRawHeader("Referer", "http://nagioscore.demos.nagios.com/nagios/cgi-bin/cmd.cgi");
    ackmanager->get(myReq);
}

Function - replyFinished2

void MNetworkConnector::replyFinished2(QNetworkReply *r)
{
    qDebug() << "reply output:" << r->readAll();
}

System returned several errors. If I test this source on my corporate icinga server, I have error: Not all commands could be send off successfully - Not Authorized

If I test it manualy on my corporate icinga server, I have error: Error: This appears to be a CSRF attack! The command wasn't issued via Classic-UI itself!

If I test it manualy on nagios test site, I have no error. Set service ack is Ok.

If I test this source I have error:Sorry, but you are not authorized to commit the specified command.

What's wrong? Thank you for all your ideas. At first I need solved problem in Icinga, the nagios test page I used only as alternative tests.

exo
  • 373
  • 5
  • 22

2 Answers2

0

When the website requests authentication QNetworkAccessManager will emit the authenticationRequired() signal. Try connecting the signal with a slot and then set the username and password on the QAuthenticator object passed as argument to the slot.

Connection:

connect(ackmanager, SIGNAL(authenticationRequired(QNetworkReply *, QAuthenticator *)), this, SLOT(authenticationRequired(QNetworkReply *, QAuthenticator *)));

Slot:

void MNetworkConnector::authenticationRequired(QNetworkReply *r, QAuthenticator *authenticator)
{
    authenticator->setUser("nagiosadmin");
    authenticator->setPassword("nagiosadmin");
}
felipeptcho
  • 1,377
  • 2
  • 9
  • 23
  • This was my first version of code :-). I thought that problem was there so I changed it to verified in QUrl. – exo Sep 20 '16 at 05:42
  • Uhh this is terrible. All problems is only because host name is case sensitive :-(. I transferred all hosts to BIG and then when sending ACK..... grrrrrrrr. 2 days and 2 nigths. – exo Sep 20 '16 at 12:39
  • Oh man! I would tell you I had tested the code you provided and it was working fine. I had imagined the problem was happening for some little detail you didn't notice. I was about to ask you the part of the code where you set the host and service. Hahaha. I'm glad you have fixed the problem despite the time it took. – felipeptcho Sep 20 '16 at 13:39
  • Thank you very much for your interest and effort. Server has really stupid answers. :-). Why don't reports - bad HOST name, HOST not exists or something like this? – exo Sep 20 '16 at 14:04
0

The problem was sensitive to uppercase and lowercase letters in the HOST.

exo
  • 373
  • 5
  • 22